Test Data Generation
#
OverviewSometimes you want to generate random data that seems realistic. For this we bundle the highly capable open-source Faker library Faker.js which makes it simple to add rich, unique, on-the-fly test data to your scripts. The Faker library allows us to generate a wide variety of syntax-correct data such as random names, numbers, strings and emails.
To start using Faker within your Flood Element script you will need to import the part of the Faker library you'd like to make us of.
For example, for basic random data we would use import random
at the top of the script:
#
Generating Random NumbersThe simplest way to generate a random number using Faker is to import the random
Faker object at the top of your Flood Element script and then use it as follows:
This example generates a 5 digit random number between 0 and 99999.
#
Generating Person NamesGenerating random first and surnames is just as easy, using the name
object:
#
Generating Email Addresses and other Web DataTo generate email addresses and other web related test data, use internet
:
#
Using fake data in testsThe easiest way to use Faker data in your test is to generate and use it inline in each step. This works well for simple tests, or when you don't need to access the same values in multiple steps.
Flood Element's TestData facility makes it simple to use Faker data across multiple steps. You can also generate a large number of fake records to use when running multiple iterations of a test script. This works the same as loading a pre-populated CSV or JSON file, but with the power of randomised values.
This example generates 5 random users with realistic data, and makes them available in the test steps. One UserData
record will be provided to the steps per test iteration.
#
Further readingFor more information about what Faker can do for you, please consult the Faker API Documentation
If you have static test data available as CSV or JSON files, consider using Flood Element's TestData facility.