Configure input values to be dynamically generated or define static values that can be overridden for use in data-driven testing scenarios.
Variables allow you to define input values which can either change on every test run based on your specifications, or be set to a static value that you can override when you run a test. Here’s a few examples of when a variable comes in handy:
Testing Your Registration Flow: Being able to register a user is often one of the most important end-to-end tests you can create. However there’s one big challenge with creating automated tests for this flow: once you’ve registered an email address/username in your system, you can’t register it again. By associating a variable to the username / email address in your test, and assigning it a dynamically generated value, you can ensure that your test registers a new user every time it runs.
Data-Driven Testing: Setting an input value to a variable with a static value allows you to override that value in future test runs. This enables data-driven testing scenarios where you pass in different input values on every test run.
Variables can be defined on both inputs (e.g. entering a value into an input box) and outputs (e.g. extracting text from somewhere on the app to assert against or use elsewhere). To assign a variable to an input, create a recording or view an existing recording and select the Input step that you’d like to associate with a variable. After selecting the Input step, you’ll see a Use Variable button in the Detail view:
Clicking on this button will open a modal which lists all of the variables you’ve previously created, along with a form that lets you add a new variable:
Either select an existing variable or add a new variable and then select it, then click the Select Variable button to associate it with your Input step.
To assign a variable to output, select any test step that includes an Expected Text block, switch the toggle from ‘Static’ to ‘Dynamic’, and select the subset of text that you’d like to assign to a variable. Once selected, the text can be assigned to either an existing variable (if you’d like to assert that it matches a pre-defined value) or assigned to a new variable (if you’d like to assign it to a variable for use elsewhere in the test).
To generate a dynamic value for a given variable,
you can use one of several supported functions in your variable definition.
Support for generating random letters and digits comes from the following functions:
Each of these functions takes a value that specifies how many random characters to generate.
range(min,max) function generates a random number between
Support for generating timestamps and dates comes from the following functions:
time(offsetMs) - returns an epoch timestamp after adding
offsetMs milliseconds to the timestamp,
datetime(offsetMs) - returns a date time string of the form
“Wed Oct 07 11:19:04 EDT 2020” after adding
offsetMs milliseconds to the date,
date(format,offsetDays) - returns a formatted date string
offsetDays days to the date.
The supported formats include only the characters:
dDmMyY /, and are parsed using
||Call me, 0149783430|
||Today: Wed Oct 07 11:19:04 EDT 2020|
Reflect automatically extracts text from the elements you interact with. In some cases this text will be static, such as the text on a Sign In button. But in other cases the text could change over time, or potentially on every test run. To assert against dynamic values, click on the test step containing the text you want to assert, and under Expected Text switch from Static to Dynamic validation.
After switching to a Dynamic validation, highlight any text that will be dynamic and assign it to either a new or existing Variable.
If the Variable you’ve assigned it to is used elsewhere, Reflect will automatically assert that the Variable values match. An example is a sign-up test where you enter in a random email address in an input field when signing up, and then later assert that that email address appears somewhere later on in the sign-up workflow.