Data-driven variables are the building blocks of data-driven testing. A data-driven variable is a named variable whose value is supplied to the test at runtime from a different source, such as a DataTable scenario or the test's environment.
This guide describes the different types of data-driven variables in mabl.
A test that is associated with a DataTable generates one run for each scenario, or row, of the DataTable. Each DataTable scenario contains a set of variables that is passed to the test. The value of those variables is determined by the scenario.
A DataTable with the values for the "English" scenario highlighted
Shared variables are values exported from a test that is configured to share variables to another test in the same plan.
If a value is not supplied from any of the previously mentioned sources, mabl tries to use a default value from an environment variable stored with the test.
Test data-driven variables
You can store data-driven variables at the test level. See test data-driven variables for more information on this source.
Flow data-driven variables
If a flow uses a variable that was created outside of the flow, this variable is known as a flow data-driven variable. The value of a flow data-driven variable may be set from a prior test step, an environment variable, or a DataTable scenario.
Order of precedence for data-driven variables
If multiple values are passed to a test for the same variable, the following order takes precedence:
- DataTable scenario
- Shared variables
- Values stored with the environment
- Test data-driven variables (default values)
- Flow data-driven variables (default values).
The value coming from the DataTable scenario will overwrite other values.
In data-driven testing, you typically want to test deterministic scenarios that verify the application under test always produces the same output given a specific set of inputs. Nevertheless, it is possible to use random values.
The following valid expressions may be used for data-driven variables that run in browser tests:
- Faker data
- Mathematical expressions
API tests do not support these valid expressions, but they do support Postman dynamic variables.