Variables
Introduction
It's considered a best practice to use variables in your tests.
This helps you avoid situations where you need to update the same value in multiple places.
Declaring variables
You can use the Set Variable
action to declare a new variable.
The options from the Set Variable
action allow you to enter, extract or even generate values.
All variable names must start with the $
character.
Once declared, a variable can be used across the entire test suite.
If you want to use it in other test suites, you have to import the test case in which the variable was declared.
The following Variable Types
are available for Web Tests:
- Set Value
- Set Password
- Random Number
- Random String
- Random Email
- Timestamp
- Extract value from Element
- Extract value from JS Variable
- Extract CSS Selector from Focused Element
- Extract Result from SQL Query
The following Variable Types
are available for Mobile Tests:
- Set Value
- Set Password
- Random Number
- Random String
- Random Email
- Timestamp
- Extract Value from Element
- Extract Coordinates from Focused Element
The Variable Types which involve randomness have mandatory inputs for rules which control that randomness.
For example, the
Randomn Number
option requires users to declare a value for theLength of Number
.And the
Random Email
option requires users to declare a value for theEmail Domain
.
You can also declare variables directly in the Endtest API request for starting a new test execution.
Using variables
After you set a variable, you can use it in other steps or cases by simply entering its name in any input.
Simply typing $
inside an input will display a dropdown with the available variables.
You can concatenate variables with strings or with other variables by placing the variable name between double curly brackets:
My name is {{$username}} and my email is {{$email}}
You can also print the variables in the Results by using the Variable
or All Variables
options from the Print in Results
action.
System variables
System variables automatically generated for each Web Test:
- $systemType
- $systemPlatform
- $systemBrowser
- $systemGeolocation
- $systemResolution
- $systemYear
- $systemMonth
- $systemDate
- $systemDay
- $systemCurrentLoopIteration
System variables automatically generated for each Mobile Test:
- $systemPlatform
- $systemDevice
- $systemYear
- $systemMonth
- $systemDate
- $systemDay
- $systemCurrentLoopIteration
Transfer variables to JavaScript
You can even transfer a variable to JavaScript, by using the Transfer to JavaScript
action.