Reuse data in tests with variables
TL;DR
Variables are created in the variable menu or in javascript steps, and can be called in any field using the {{var}}
syntax. You can also call inline javascript using that syntax, including in variable declaration. It's frequent to use faker to generate random data.
Declare a variable
You can declare a variable in the variable menu. A variable needs a unique name and a definition. The definition can be a value, or a javascript code snippet between {{}}
.
You can also declare variables from javascript steps using the Heal.variables.set("varName","value")
object.
Inline javascript
You can use inline javascript as variable definition. Inline javascript can be called by putting it inside brackets {{}}
. Inline javascript is limited to a single line of code and is ran in isolation. It can access the following libraries:
Variables can call other variables, but make sure to avoid circular dependencies as they will result in errors.
Examples:
- Type text
{{faker.internet.email()}}
onthe email field
- Type text
{{faker.person.firstName()}}
onthe first name input
- Click on the
{{faker.helpers.arrayElement(['Pr.', 'Dr.', 'Mr.'])}} button in the title section
- Type text
a variable: {{var1}} and another variable: {{var2}}
onthe input field
Calling a variable from a step
Variables can be called in any step using the {{var}}
syntax. The following fields support variables:
- The target of left click, type text, hover, select, go to URL
- The value of type text and select
- Assertions
System variables
The following variables are system variables and cannot be overriden:
runId
: the id of the current runattempt
: the current attempt count. Heal retries runs up to 3 attempts in case of crashemail
: the catchall email of the current run. This email can be used for receiving emails.