Using mabl, you can share variables between tests within the same plan.
- creating test data with randomly generated variables such as user IDs or emails that you would like to delete in a different test at the end of the plan
- generating variables in one test that you would like to then validate in a different test in the same plan such as creating a user and then assigning it to different roles
To share variables between tests, you would typically take the following steps:
- Create the test that generates the variables you would like to share
- Configure the test to share variables
- Create other tests that will make use of the shared variables
- Add all those tests to the same plan
You can share all variables that generated their value during a test run from the following sources:
- string templates
- element properties
- mabl mailbox
- API steps
Creating a variable from a random string template
We refer to those variables as test-generated and to configure the test to share them, do the following:
Go to the test details and click to edit the test.
Edit test details
Then, enable the variable sharing as shown below.
Enable sharing variables
Next step is to create the test that we will be passing the shared variables onto. Since a test does not know what variables it will receive upon execution, we need to create and use data-driven variables with default values as placeholders. The variable names must match the names of the variables that are being passed onto the test. Names are case sensitive.
Creating a data-driven variable named "userId"
During the test run, mabl will overwrite the default values with values from the variables passed onto the test, as long as the variable names are an exact match.
Variable name conflict resolution
If multiple test runs generate and share the same variables, but with different values, then the last test run that completed would override the variable values set by prior test runs. This is also true if the plan has multiple browsers, run multipliers and/or the test has a DataTable with multiple scenarios associated with it.
If multiple values are passed to a test for the same variable, the following order takes precedence: environment < test share < DataTable. The value coming from the DataTable scenario will overwrite all other values.
To run the created tests and share variables between them, you need to also add them to the same plan.
In order to pass variables from one test run to another test run, you need to ensure that the test run passing the variables succeeds prior to tests expecting those variables starting.
One way to achieve this is to place all tests in a sequential stage that will run the tests in the given order. Another way to setup the plan is to have all tests sharing variables in one stage and place tests expecting those variables in follow on stages.
Sharing variables between tests in a plan works best when the plan runs in a single browser on a single environment and without a run multiplier to ensure that the tests sharing variables will run just once within the plan.
Updated 7 months ago