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
- Real Phone Number
- Timestamp
- Extract Value from Element
- Extract Value from Element with OCR
- Extract Value from JS Variable
- Extract Value from Alert
- Extract CSS Selector from Focused Element
- Extract Result from SQL Query
- Extract Latest SMS
The following Variable Types
are available for Mobile Tests:
- Set Value
- Set Password
- Random Number
- Random String
- Random Email
- Real Phone Number
- Timestamp
- Extract Value from Element
- Extract Value from Element with OCR
- Extract Coordinates from Focused Element
- Extract Result from SQL Query
- Extract Latest SMS
- Extract WebView Context Name
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
.
The
Real Phone Number
andExtract Latest SMS
options require your account to be associated with real phone numbers.We provide real phone numbers for our users. You don't have to use any external service.
If there are no real phone numbers associated with your account, please contact our Support Team.
More information is available in the Read SMS chapter.
You can also declare variables directly in the Endtest API request for starting a test execution, more details are available in the Endtest API chapter.
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
- Desktop or Mobile$systemPlatform
- Windows, Mac, Android or iOS$systemBrowser
- Chrome, Firefox, Internet Explorer 11, Edge or Safari$systemGeolocation
- The selected Geolocation$systemResolution
- The selected Screen Resolution$systemResolutionWidth
- The width of the selected Screen Resolution$systemResolutionHeight
- The height of the selected Screen Resolution$systemYear
- The current year$systemMonth
- The current month (e.g. 1, 2, 3)$systemDate
- The current date (e.g. 1, 2, 3)$systemDay
- The current day (e.g. Monday, Tuesday, Wednesday)$systemCurrentLoopIteration
- The current loop for an Import Test Case Multiple Times step$systemLatestScreenshotLink
- The URL for the latest screenshot$systemErrorCounter
- The current number of Errors$systemPassedCounter
- The current number of Passed Assertions$systemFailedCounter
- The current number of Failed Assertions
System variables automatically generated for each Mobile Test:
$systemPlatform
- Android or iOS$systemDevice
- The name of the device$systemYear
- The current year$systemMonth
- The current month (e.g. 1, 2, 3)$systemDate
- The current date (e.g. 1, 2, 3)$systemDay
- The current day (e.g. Monday, Tuesday, Wednesday)$systemCurrentLoopIteration
- The current loop for an Import Test Case Multiple Times step$systemLatestScreenshotLink
- The URL for the latest screenshot$systemErrorCounter
- The current number of Errors$systemPassedCounter
- The current number of Passed Assertions$systemFailedCounter
- The current number of Failed Assertions
Transfer variables to JavaScript
You can even transfer a variable to JavaScript, by using the Transfer to JavaScript
action.
After that, you can perform different operations with that variable in JavaScript with an Execute JavaScript
step.
If you want to transfer a variable from JavaScript, you need to use the Extract value from JS Variable
option from the Set Variable
action.
You can find more details about the
Execute JavaScript
action in the Execute JavaScript chapter.