Data PopulationΒΆ

When developing, especially when working with form we need to prepopulate the form with sample data to ease up our development.

The faker is meant to take care of this for us.

Lets populate our basic form form from earlier with sample data.

form // the basicform from earlier example

// create a populator object
DummyDataPopulator populator = new DummyDataPopulator();

// format how the data should look
// this will generate data with the format a mobile number of we use here in kenya
// +254 722 472 447
populator.setFieldPopulator("phone_number", new Telephone().setFormat("(+###) ### ### ###"));


// tell populator to populate the form.
// it will use the provider we set above for the phone number instead of the default one which
// would be a random set of numbers
populator.populate(form);

// you could also populate single field on its own
populator.populate(form.getField("gender"));

The kind of data that is generated depends on the type of view and the name of the field. e.g. if a view is edittext of with inputype of number then the populator will generated numbers for that particular view.