You are on page 1of 8

BlazeMeter Synthetic Test Data Examples

The following advanced examples are taken from other various domains and do not use the
DigitalBank demo application. Readers without scripting experience can copy the shown
functions into data parameters to use them. Readers with scripting experience are encouraged
to learn from these examples and create their own complex functions.

Make your own lists


You can even create custom, one-off lists, for use in List Functions:

• To create a text list, enclose each text item in quotation marks, and enclose the whole
list in square brackets:
["jelly","1 bread","456","peanut butter"]
• Similarly, you also enclose purely numeric lists in square brackets:
[1,44 ,-5]
• You can use custom lists together with Random List Functions such as:
randFromList([1,44,-5]).

Text Concatenation

Function Usage Description Example Result


randFromSeedlist("firstnames") + "." + Generate a Sigmund.Byrnes@acme.com
randFromSeedlist("lastnames") + "@" +
randFromList(["acme.com","example.com"]) formatted
email address Peter.Parks@example.com
with a variety
of names and
domains.
lower(randText(4,5)) + "-" +
Generate a ojdt-00355786/1131-KDNN
randrange(999,99999999,8) +"/"+
randDigits(3,4) + "-" + custom
upper(randText(2,4))
product pxaaq-00092640/934-LB
identifier
lower(${first}) + "." + lower(${last})
A username joe.smith
in lowercase
with dot
upper(${first}) + "_" + upper(${last})
A user name JOE_SMITH
in all caps
with
underscore
wordcap(${first}) + " " +
A user name Joe Smith
wordcap(${last})
with word
capitalization
with space
“Random” Text
Function Usage Description Example Result
randText(1,25) A random “24rCAKxZzwFRY61nlW8”
alphanumeric text
within the given
minimum and
maximum length.
randInt(1,255) A random number 136
within the range.
randChars(3,3,"abc") + "/" Three random letters bca/851
+ randInt(100,999)
followed by a slash
and three random
numbers.
randRange(0,99999999,8) A random number 00038451
within the given
range, padded with
zeros (in this
example, padded up
to 8 digits).
randCreditCard("VISA") A random number 4211913369761524
with a VISA card
check digit.
randFromList(["/","\","*","ř"], 0) One of the listed "\"
characters.
randFromList(["/","\","*","ř"], One of the list items ""
50)
or nothing, with
50% chance
randFromCSV("address.csv","city") A random value "Ottawa"
from the named
column
randFromCSV("address.csv", A single value from "Madrid"
randInt(1,3))
a random column

randomIndex=randInt(1,100) Two matching "Tokyo"


values from the
valueFromCSV("address.csv", "Japan"
"country", same row of their
${randomIndex}) column.

valueFromCSV("address.csv",
"city",
${randomIndex})
regExp("[a-z]{5,10}-[0-9]{5}", Five to ten letters "sXMdM-77029"
"i")
from a to z in mixed
case, then a hyphen,
then five numbers
Matching Multi-Column Seedlists
Each row in a multi-column seedlist contains consistent data, such as a postal code that
matches the state and city. Don't use the randFromSeedlist() function with multi-
column seed lists, randomizing the rows would defeat the purpose of the rows being
consistent. To get data from multi-colun lists, use the function

valueFromSeedlist(listname,rowindex,column)

How to get matching columns:

1. Define your own row counter, ${addressRow}.


2. Replace the argument listname by "usaddress-multicol", a multi-column
seed list that contains US addresses.
3. Replace the argument rowindex by your row counter, ${addressRow}.
4. Replace column by a number from 1 to 4:
o column 1 contains US street addresses
o column 2 contains US cities
o column 3 contains US States
o column 4 contains US postal codes

Function Usage Description Output


Example
${addressRow}=randInt(1,1000) The randInt() function generates 1234
a fresh counter
value ${addressRow} for each
address. Using the same counter
value for one address ensures we
consistently look up values from
the same row of the seed list.
valueFromSeedlist("usaddress- Column 1 contains US street 3220
multicol",${addressRow},1) addresses Little
River Dr
valueFromSeedlist("usaddress- Column 2 contains a matching Dallas
multicol",${addressRow},2) US city

valueFromSeedlist("usaddress- Column 3 contains a matching TX


multicol",${addressRow},3) US state

valueFromSeedlist("usaddress- Column 4 contains a matching 75241


multicol",${addressRow},4) US postal code

If the requested row index ${addressRow} exceeds the number of rows, the function rolls
over to the beginning of the list and still returns a valid value.
Dates and Times
Synthetic data is also extremely powerful in scenarios that require valid relative dates, or
when time calculations are required.

For example, in a support ticket system, a support ticket's color depends on whether the ticket
was submitted today, yesterday, last week, or last month. In order to test the ticket color
coding, we need to create tickets with valid dates in the past, relative to the day when the test
runs.

The following table provides examples how to get time and date stamps:

Function Usage Description Output Example

time(now()) Get the current time "12:30:00.000"

now() Get the current date and time in the "2020-09-08


default time zone. 12:30:00.000"
now("Europe/Prague") Get the current date and time in the "2020-09-08
given city. 12:30:00.000"
now(“EST") Get the current date and time in the "2020-09-08
given time zone. 12:30:00.000"
now("-01:00") Get a "one hour old" timestamp "2020-09-08
11:30:00.000"
addDays(now(),-1) Get yesterday's timestamp by "2020-09-07
"adding negative one days" 12:30:00.000"
lastDay(now()) Get the last day of the current "2020-09-30"
month

Tip:
If you find yourself referring to the same relative date or time often, create a
parameter for it. For example, create a parameter yesterday and set it to
addDays(now(),-1). It's easier to remember to use ${yesterday} than
remembering the function.
The following table provides examples how to quickly convert dates:

Function Usage Description Output Example

datetime( Convert the date from the "18/05/2018


"2018-05-18 09:23:22", default ISO 8601 format to 09-23-22"
"DD/MM/YYYY HH-mm-ss") "DD/MM/YYYY HH-mm-ss".
parseDate( Parse the date as "2018-05-18
"18/05/2018 09-23-22", "DD/MM/YYYY HH-mm-ss" 09:23:22.000"
"DD/MM/YYYY HH-mm-ss") format, and convert it to the
default ISO 8601 format.

The following table provides examples how to quickly calculate time periods:

Function Usage Description Output


Example
daysAfter( How many days have passed 4
"2000-01-01","2000-01-05") between two dates?
daysAfter( How many days have passed 278
"2020-01-01",now()) between a date and now?

The following table provides examples how to generate random dates within a range:

Function Usage Description Output Example

randDate("2009-01-20", Generate a random date and time 2009-08-25


"2010-01-22") between two given dates. 06:01:16.589
addRandDays( Generate a random date within a 2020-01-07
"2020-01-01", 3, 10) certain range (here, 3 to 10 days)
after a date.
randTime("00:00:00", Generate a random time within a 10:01:13
"23:59:59") time range.
Use Parameters as Arguments of Functions
Picture a scenario where we are testing a form validation feature which detects the issuer of a
credit card number. Based on the properties of the card number, the web interface indicates
either "AMEX", "MAESTRO", or "VISA" next to the input field.

The challenges with testing this feature are:

• A random 16 digit number won't validate as a credit card number, so we need to use
the randCreditCard(issuer) function.
• Using a single issuer such as randCreditCard("AMEX")in the argument only
generates one credit card type, but we want three.

Instead of a fixed value, functions also accept parameters as arguments. This means, even the
argument of a function can be test data loaded from a CSV file.

1. Open the test, click Test Data.


2. Create a CSV file (Data Table) in the data entity.
3. Create a column named issuer. As column content, enter credit card issuers from the
list of supported arguments.

4. Pass the ${issuer} parameter as an argument into the function:


randCreditCard( ${issuer} )
5. Add an Assert Text action which matches the expected ${issuer} parameter with
the detected issuer from the web interface.

Tip: Notice each of the issuers in the data set is surrounded by quotes. We do this because
these values will be read by a function which requires its arguments to be in quotes.
Generate Complex Custom Data in One Test Step
Even a function can serve as an argument for another function. A common scenario is that the
function generates dates in its default format YYYY-MM-DD, but your test needs a different
format to pass validation, such as MMDDYYYY.

• The advantage of using a function as an argument inside another function is that it


allows for complex data generation and manipulation to occur in a single test step.

• The disadvantage is that you need to be careful to not write difficult functions that are
no longer human- readable, which makes them more difficult to maintain later.

Example 1: Change the Data Format in one step

In this scenario, a test requires a birth date of a person between 25 and 100 years old, and it
must be in the MMDDYYYY format.

To accomplish this, we use two functions together:

• dateOfBirth(min,max,date) generates a birthdate such as 1993-07-12.


• datetime(date,format) converts 1993-07-12 to 12071993.

To generate the birth date of a person that is between 25 and 100 years old now, we pass the
following arguments to the dateOfBirth(min,max,date) function:

dateOfBirth(25,100,now())

This gives us a date in the YYYY-MM-DD format.

To convert this date to our target format, we pass the whole dateOfBirth(…) function as
argument into the datetime(date,format) function, along with the target formatting
definition "MMDDYYYY":

datetime( dateOfBirth(25,100,now()), "MMDDYYYY" )

BlazeMeter evaluates functions from the inside out. The inner function generates the date of
birth in YYYY-MM-DD format. Next, the outer function converts the resulting date to the
MMDDYYYY format. This means, 1993-07-12 is converted to 12071993.
Example 2: Create a Custom Address Format in one step

Let's assume your test requires a street number followed by a street name in all upper case
letters. However, the street names in the seed lists are in title case – we need to convert them.

To accomplish a text conversion, let's again combine functions:

1. Generate a street name using randFromSeedlist("streetnames")


This gives you, for example, Concert Street.
2. Use upper() to convert this street name to all uppercase letters:
upper(randFromSeedlist("streetnames"))
For example, now we have CONCERT STREET.

3. We also generate a street number, using randDigits(3,3)


This gives you, for example, 306.

4. Concatenate the street number and the street name with a white space using:
randDigits(3,3) +" "+ upper(randFromSeedlist("streetnames"))
This results in, for example, 306 CONCERT STREET.

Tips
• When working with complex test data, start with small pieces like the house number
or a date. Always preview the output of the function to validate that the function is
generating data as expected.
• Keep copies of useful complex functions and arguments for quick reference.

For a full list of functions, search for Test Data Generation Functions in the BlazeMeter
documentation. These examples are provided to inspire you when you amend your tests
with synthetic data.

You might also like