By storing data extracted from your test environment in variables, you can use the values in subsequent test steps to make your test more flexible and robust. The mabl Trainer supports generating variables from the following sources:
Other ways to create variables in the Trainer include:
- API steps: extracting the response into a variable.
- Custom find steps: using CSS or XPath
- Test data-driven variables: creating placeholders for data-driven variables
Creating variables from a string template
Use a string template to create a variable from constant values, other variables, random values, or mathematical expressions. For more information on supported expressions, see the article on valid expressions.
- Click on {x} > Create variable
- Set the variable source to "String template."
- Enter the string template pattern.
- Give the variable a name.
- Click OK.
Creating variables from an element property
If you want to extract a value from the page and store it in a variable, create a variable from element property:
- Click on {x} > Create variable
- Set the variable source to "Element property."
- Click on the mouse icon to select an element on the page
- Select the element on the page. If the element is covered by a different overlapping element, hold the shift key and press the up or down arrow to scroll through overlapping elements.
- Select the Property that you want to store in the variable, such as "InnerText" or "Value"
- Assign the variable a name.
- Click OK.
If you need to modify the value extracted from the page, create a new variable using JavaScript snippet. To see an example of how to modify a string using a JavaScript snippet, click here.
Creating a variable from a JavaScript snippet
To create a variable from the output of a JavaScript snippet, take the following steps:
- Click on {x} > Create a variable.
- Set the variable source to "JavaScript"
- Create a new snippet or use an existing snippet.
- Click Run to check the output.
- Assign the variable a name.
- Click OK.
If you're new to writing snippets, see our article on the Snippet Editor for an overview.
Creating a mabl Mailbox address
For email testing scenarios that can be completed in a single test, create a temporary mabl Mailbox address:
- Click on {x} > Create a variable.
- Set the variable source to "mabl Mailbox address"
- Assign the variable a name.
- Click OK.
For more information on mabl Mailbox, see our documentation on email testing.
Creating a variable from a cookie value
In browser tests, you can store the value of a cookie in a variable:
- Click on {x} > Create a variable.
- Set the variable source to "Cookie value."
- Select the cookie.
- Assign the variable a name.
- Click OK.
The list of selectable cookies can include HTTP only cookies, which are commonly used for authentication. HTTP Only cookies are not accessible via JavaScript snippets and can only be accessed in the variable creation menu. For more information on working with cookies, click here.