Professional Documents
Culture Documents
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.
• 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
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)
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:
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:
The following table provides examples how to quickly calculate time periods:
The following table provides examples how to generate random dates within a range:
• 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.
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 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.
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 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())
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":
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.
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.