When building a browser or mobile test in the Trainer, variables are essential for creating dynamic test steps. This article provides an overview of using variables in the Trainer, including how to…
How to reference variables in test steps
Many actions in the Trainer can reference variables. To use a variable in an assertion or a visit URL step, select the variable you want to reference from a dropdown.
For other actions, including JavaScript snippets, flow parameters, Configure Find, custom find steps, API steps, and echo steps, use mabl variable syntax to reference the variable.
Mabl variable syntax
To reference a variable in a test step, prepend the variable name with an @
symbol and wrap it in double curly braces {{ }}
. For example, if you want to reference a variable called product_id
, you can write {{@product_id}}
Using mabl variable syntax in Configure Find
Variable interpolation
You can also combine mabl variable syntax with other text or static text. For example, this assertion references the variable new_user
, which has a current value of user789
. In the preview, {{@new_user}}@email.com
appears as user789@email.com
.
Variable interpolation is not supported in data-driven variables or environment variables. This means that their values cannot contain references to another variable, such as {{@anotherVar}}
.
How to input variables in text fields
To input a variable value for an input field or text area, take the following steps:
- Click on the {x} button.
- Select "Use a variable."
- Click on Input value.
- Select an element on the page - input or textarea - where you want to insert the variable's value.
- In the Trainer window, select the variable from the dropdown.
- Click OK.
The Trainer inserts the variable's value into the selected input field on the page.