Repeatable Tests - Data Generator
abstract
We can create unique data for repeated execution using Data Generators.
goal
Make a test repeatable by generating unique data every time.
If we run the user registration path we just created, we will find that it fails. It fails because the email id has already been registered (when we recorded it).
For the path to run again and again, we need to generate a new email id every time.
info
Automation Tip: Applications need an email id in registration forms so that registration confirmation information, password reset etc. can be sent to the user.
You need access to the email inbox to test those features. So the email id needs to be real. However, automation requires that you need to register multiple times.
It may not be possible to generate a new email id for each registration. So how do we solve this?
We can use email subaddressing. Many email providers allow adding extra information by adding a +.
Eg.,
We can utilize this in automation by adding a timestamp after the + to generate unique email ids. Eg.
Most applications allow the + during registration, and consider these emails to be unique.
If your application does not allow this, consider allowing it during testing and turn it off in production.
You can read about
https://en.wikipedia.org/wiki/Email_address#Sub-addressing
https://datatracker.ietf.org/doc/html/rfc5233
You need access to the email inbox to test those features. So the email id needs to be real. However, automation requires that you need to register multiple times.
It may not be possible to generate a new email id for each registration. So how do we solve this?
We can use email subaddressing. Many email providers allow adding extra information by adding a +.
Eg.,
mahi@example.com
and mahi+yellow7@example.com
both will be delivered to mahi@example.com
We can utilize this in automation by adding a timestamp after the + to generate unique email ids. Eg.
mahi+17134925239561@example.com
Most applications allow the + during registration, and consider these emails to be unique.
If your application does not allow this, consider allowing it during testing and turn it off in production.
You can read about
email subaddressing
here:
https://en.wikipedia.org/wiki/Email_address#Sub-addressing
https://datatracker.ietf.org/doc/html/rfc5233
steps
Email Data Generator
Let us add a data generator for the user's email field.- Click on any node of the flowchart > click on
Automate
> Go toEntities
tab. - Select
$user
entity on the left pane. - Select
email
attribute on the left pane. - Select the sub tab
Data Generator
Notice that Flowcharts has detected the value as an email and separated it into meaningful tokens like name, domain etc.
You can add more names and domains to generate more emails. -
Of particular interest for us is the add-timestamp field. Let us set it to true.
This will add a timestamp to the email and make it unique for each run. - Check the sample values by using the
Refresh Preview
button . - Click on
Save Entity
.
Text Data Generator
Similarly, let us add a Text Data Generator to the user's firstname.- Select the attribute name:
firstname
- Set the parameters as shown here :
- Check the sample values by using the
Refresh Preview
button . - Click on Save Entity button.
Other Data Generators
info
There are various types of Data Generators. We can choose the Data Generator type which best suits the attribute. Each Data Generator type has its own parameters.
- From/To: Minimum and Maximum dates can be selected from the calendar icon.
- Relative maximum and minimum dates can be set.
- Example: To generate dates for next one year
- From= today
- To= tomorrow+365 Similarly, 'yesterday' and 'minus' symbol can also be used.
- format: Date format can be set such as
dd-mm-yyyy
. - Number: To generate number based data/series with or without extra characters.
- prefix: Any alphabet, number or special character to put in the starting of the number
- min-value/max-value: Range of the number
- decimals: Number of decimal digits
- separator: Character to use as a unit separator
- decimal-separator: Character to use instead of dot for decimal numbers
- suffix: Characters to add at the end of the number
- Boolean: To generate a value among
true
andfalse
.- default-value: Value can be chosen from the three options available in the list-
random, false or true
.
- default-value: Value can be chosen from the three options available in the list-
- Phone: To generate phone number with desired country or area code in given format.
- formats: Type the phone number format along with the country/area code.
- The symbol
x
can be used to generate random digit.
- Simple-text: To generate any text based data with an option to mask it.
- text: Provide a set of alphanumeric characters. The value gets hardcoded.
- is-password: Set preference to mask the text on UI.
- Once the
is-password
is set to [/icode]true[/icode], the value in text field gets masked and can not be unmasked. If the [is-password[/icode] is changed back tofalse
, the text field gets reset.
- List: To generate a list based on a given set. The list is generated based on the hierarchy of the other lists to which it is referring to.
It can be understood with the help of an
address
entity. This entity consists of three attributes: country, state and city.- Select
country
attribute and selectData Generator Type
-list
.- Type a few country names in
values
field.
- Type a few country names in
- Select
state
attribute and selectData Generator Type
-list
.- Set the fields as follows:
- sync-with: Select
country
- sync-items: Select a country name from the list.
- values: Type few state names.
- Enter few state names for each country.
- sync-with: Select
- Select
city
attribute and selectData Generator Type
-list
.- Set the fields as follows:
- sync-with: Select
state
- sync-items: Select a state name from the list. Select the state name from the next list.
- values: Type a few city names.
- Enter a few city names for each state under each country.
Now, the data generator will generate a complete address where - sync-with: Select
city
,state
andcountry
are in sync. - Select
- Date: To generate date between the given range and in the desired format.
outcome
By associating Data Generators, we generate unique data for each run, so that tests can run repeatedly.
concepts
- Entity
- Attribute
- Data Generator
- Quick Extract
next
Positive Validations