You are developing test automation script for your application and need test data or your application has been deployed and the product owner or the business owner comes around the corner. The registration screen loads up but you realise there’s no data in the system. And you can’t think of any creative customer names besides from “John Smith” and “Jane Doe.”
So you need to use Java Faker library
The idea behind the library is very simple. It generates fake data. The library actually came out of a software project developed by my company DiUS Computing. We used it to generate data for demos or testing.
The following steps will show how to use this library with Java and Maven Project:
For example you need to test Registration form such as this one
1- In your Maven Project add the following dependency in the POM.xml file
<dependency> <groupId>com.github.javafaker</groupId><artifactId>javafaker</artifactId><version>0.5</version> </dependency>
* check the latest version from maven repository
2- Create an instance of the Faker
Faker fakeData = new Faker();
3- Add Fake data to fill this form with Faker like this snippet
String userName = fakeData.name().username(); String email = fakeData.internet().emailAddress(); // username with max 6 digits String password = fakeData.number().digits(6).toString(); String firtName = fakeData.name().firstName(); String lastName = fakeData.name().lastName();
Done you can now use these fake data in your test and every time will be new data .
for more information you can take a look at the javadocs for examples of what fake data can be generated.
Good Luck and Happy Testing 🙂
Get ready to become an Automation Guru!