Automation Testing

Dynamic Test Automation Data Using a Faker

By Test Guild
  • Share:
Join the Guild for FREE

Have you ever had to automate an application that required unique data for every test run?

It can be a pain.

I use to have to automate a hospital application that required that I register a new patient in every test before the rest of the workflow could proceed.

The only issue was that each username and social security number had to be unique.

Hardcoded data would not work in this scenario and seeding the database with users beforehand than cleaning up after was messy and time-consuming.

What to do? Faker to the rescue.

k6 Performance Test Tool

What is a Data Faker?

A faker allows you to dynamically create real looking data like names, phone numbers, addresses, SSN — all kinds of stuff.

Lots of times you don't care about what these values like name or address are so long as you know that your web application will save them correctly.

Using a faker allows you to model this data and create fresh dynamic values for these fields ever test run.

This approach has been recommended a few times on my test automation podcast TestTalks. For example, check out my interview with Paul Merrill on Data Strategies in Testing

Also, Titus Fortner showed an example in his Automation Guild 2018 session on using a Faker in his Crafting a Test Framework session.

Selenium Data Faker Example

Say for example I’m testing an application as if I was a user in Italy. Using faker and passing it a locale of it_IT(Italian) it will generate Italian names and address. Here is an example using Selenium with Python with a Faker

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from faker import Faker

fake = Faker('it_IT')
full_name = (fake.name())

print(full_name)
print(fake.address())

first,last = full_name.split()

driver = webdriver.Chrome('C://Download/chromedriver.exe')
driver.get("https://testguild.com/SeleniumTestPage.html")
assert "WebDriver" in driver.title
first_name = driver.find_element_by_name("fname")
last_name = driver.find_element_by_name("lname")
first_name.clear()
first_name.send_keys(first)
last_name.send_keys(last)
first_name.send_keys(Keys.RETURN)

driver.close()

This simple code generates a dynamic name which I parse into first and last names. I then use those values as inputs in my test applications first and last name fields.

It’s as simple as that.

Of course, you can get as crazy as you want, but as you can see this is powerful even in a simple scenario.

Test Management Machine Learning Robot

When You Might Want to Use a Faker in Your Test Automation

As we have seen using a faker for values that need to be unique like SSN is a prime user case for utilizing a faker.

  • If you are demoing a product to a customer having realistic looking data can help improve the experience. Faker can seed your application with realistic looking data.
  • Faster and less maintenance than using hardcoded values
  • Since you are using dynamic data, it might uncover an unanticipated bug.
  • Test that requires a broad set of test data with a bulk activity.

How to Find a Faker for Your Automation Testing Language

If you're using an automation tool that allows you to import libraries, you are in luck since there are a bunch of fakers available in most languages. Don’t waste your time creating your custom code to do what an exiting open source library can already do.

There are Faker libraries in many languages, check them out: (Let me know if I missed one of your favorites and I will add it to the list)

Don't over Fake it

Like anything sometimes going overboard can cause more issue than its worth.

Use your judgment when using a Faker and don’t over complicate your test script with unnecessary dynamic values if you don’t have to.

 

A bearded man with blue glasses and a black-and-white jacket smiles at a microphone in a studio setting.

About Joe Colantonio

Joe Colantonio is the founder of TestGuild, an industry-leading platform for automation testing and software testing tools. With over 25 years of hands-on experience, he has worked with top enterprise companies, helped develop early test automation tools and frameworks, and runs the largest online automation testing conference, Automation Guild.

Joe is also the author of Automation Awesomeness: 260 Actionable Affirmations To Improve Your QA & Automation Testing Skills and the host of the TestGuild podcast, which he has released weekly since 2014, making it the longest-running podcast dedicated to automation testing. Over the years, he has interviewed top thought leaders in DevOps, AI-driven test automation, and software quality, shaping the conversation in the industry.

With a reach of over 400,000 across his YouTube channel, LinkedIn, email list, and other social channels, Joe’s insights impact thousands of testers and engineers worldwide.

He has worked with some of the top companies in software testing and automation, including Tricentis, Keysight, Applitools, and BrowserStack, as sponsors and partners, helping them connect with the right audience in the automation testing space.

Follow him on LinkedIn or check out more at TestGuild.com.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

30 AI Terms Every Tester Should Know

Posted on 04/24/2025

Why This AI/ML List Matters to You (and Your Testing Career) AI and ...

5 Top Model Context Protocol Automation Tools (MCP Guide 2025)

Posted on 04/09/2025

What is Model Context Protocol (MCP) Model Context Protocol (MCP) is an open ...

What is TDD (Test Driven Development)

Posted on 04/05/2025

What is Test-Driven Development (TDD)? Test-Driven Development is a software development approach that ...