Sharing variables between tests

Using mabl, you can share variables between tests within the same plan.

Use cases

  • 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 set up a plan that shares variables between tests share [variables], you can take the following steps:

  1. Create the test that generates the variables you would like to share.
  2. Configure that test to share variables.
  3. Create other tests that will make use of the shared variables.
  4. Add all those tests to the same plan.

Sharing variables

You can share all variables that generated their value during a test run. We refer to those variables as test-generated, and they can be from the following sources:

  • string templates
  • element properties
  • mabl mailbox
  • JavaScript steps
  • API steps
Creating a variable from a random string templateCreating a variable from a random string template

Creating a variable from a random string template

We refer to those variables as test-generated.

Configuring a test to share variables

  1. Go to the test details
  2. Click on the edit icon.
Edit test detailsEdit test details

Edit test details

  1. Enable variable sharing as shown below.
Enable sharing variablesEnable sharing variables

Enable sharing variables

The 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"Creating a data-driven variable named "userId"

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.


Variable size limit

The combined size of test-generated variables shared from a test must not exceed 1MB.

To run the created tests and share variables between them, you need to also add them to the same plan.

Plan stages

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.


Important considerations

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.

Did this page help you?