Sometimes 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:
The 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 random first and surnames is just as easy, using the
To generate email addresses and other web related test data, use
The 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.
For 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.