loading...

Generate Stub Test Data Using JFairy in Selenium

tyaga001 profile image Ankur Tyagi Updated on ・2 min read

Test Data Challenge in Test Automation

One of the biggest hurdles in automation testing is to produce test data which somewhere close to real data.

we sometime overlook the importance of test data in our test script so, I would suggest you to use test data generation library to produce data which looks like real data.

Lets look at a Java library – JFairy – which could generate test data for our selenium test automation scripts.

JFairy:

It's a library to produce stub test data which looks like real data.πŸ‘‡

Include below maven dependency in your pom file.

    <groupId>io.codearte.jfairy</groupId>
    <artifactId>jfairy</artifactId>
    <version>0.5.9</version>

More infoπŸ‘‰ jfairy-Github

Let's see one example:πŸ‘‡

To generate random person objects which could give us name, address, telephone number, age, DOB, email, passport number etc

Fairy fairy = Fairy.create();
Person person = fairy.person();
person.getFullName();
person.getAddress();
person.getAge();
person.getEmail();
person.getDateOfBirth();
person.getPassportNumber();
person.getCompanyEmail();
person.getNationalIdentityCardNumber();

When you tried to run the above code in a loop 2 times, It produces unique data every time which looks like real data.

Mark Twin
60 Glenlake Lane
Flint, MI 48504
67
twin@yahoo.com
1723-06-20T23:52:14.933-05:00
wFNmlgnox
mark.twin@furbainc.biz
677-29-1188
------------------------------------------------------
Chris Barnett
90 SW. Leeton Ridge Court
Bay City, MI 48706
58
barnett@ymail.com
1820-10-13T13:20:39.103-05:00
1tIaHKoze
chris.barnett@nonos.eu
779-13-1881
------------------------------------------------------

Same as Person object, Fairy can also create below objects & produce random test data.

1- Date 
2- Text    
3- Credit Card 
4- Company 

Summary:

It's a simple stub data library, this will be very effective to produce test data for your test automation scripts on a daily test run in CI/CD pipeline

Happy Testing!!!

Follow me on Twitter

Join us on WETESTERR Community

Subscribe to our YouTube for Tech podcast

If you like this article chances are you will like my other article as well πŸ‘‡
πŸš€https://dev.to/tyaga001/my-tech-journey-in-software-testing-5fol
πŸš€https://dev.to/tyaga001/chropath-is-no-more-a-xpath-finder-tool-it-has-evolved-a-lot-now-13fd
πŸš€https://dev.to/tyaga001/all-about-cypress-episode-1-0-12jl
πŸš€https://dev.to/tyaga001/how-to-stay-positive-in-this-isolation-time-jca

Posted on by:

tyaga001 profile

Ankur Tyagi

@tyaga001

Founder of WETSTERR My goal is to help fellow folks with my advice from what I learn from my experience to date & grow together.

Discussion

pic
Editor guide