title |
---|
Examples - Test Data Generation |
With the help of the incredible open-source Faker library Faker.js - we can generate test data for use in Flood Chrome test very easily and on-the-fly. The Faker library allows us to generate a wide variety of syntax-correct data such as randome names, numbers, strings, emails etc.
To start using Faker within your Flood Chrome script you will need to import the specific Faker library -for example for basic random data - we would use the following 'random' library:
import { random } from 'faker'
The simplest way to generate a random number using Faker is to declare the 'random' Faker object at the top of your Flood Chrome script and then use the following in your Flood Chrome script step to generate a 5 digit random number between 0 and 99999:
//Generate a random phone number
var randNumber = random.number(99999).toString()
You are able to generate random first and surnames very easily:
//put this import statement at the top of your script
import { name } from 'faker'
//Generate different types of names and related data
var randFirstname = name.firstName()
var randSurname = name.lastName()
var randJobTitle = name.jobTitle()
var randPrefix = name.prefix()
You are able to generate email addresses and other web related test data using the following:
//put this import statement at the top of your script
import { internet } from 'faker'
//Generate different types of names and related data
var randEmail = internet.email() ////returns "[email protected]"
var randEmailProvider = internet.email("joe","smith","protonmail.com") //returns "[email protected]"