Creating variables in the mabl Trainer

To add a variable in a browser test, open the mabl Trainer and take the following steps:

  1. Click on the "{x}" button at the bottom of the Trainer window.
  2. Select "Create a new variable" from the menu. A new screen will appear where you can select a variable source and assign a name.
  3. Choose a variable source. At present, you can generate variabltes from the following sources:
  4. Assign a name
  5. Click OK.

After clicking OK, a new step will appear in the Trainer window. An exception is made for data source variables. Data-driven variables do not create a new test step.

📘

Other ways to create variables

There are two other ways to create variables in the Trainer:

  • API steps: extracting the response into a variable.
  • {x} > Manage the variables in this test > Add variable: This method is equivalent to the "data source" option and creates a data-driven variable. Adding a variable in this manner does not create a new test step. To learn more about this type of variable, click here.

String template

The mabl string template can be used to create strings from constant values, other variables, random values, and/or mathematical expressions. For more information on supported expressions, check out the Valid expressions guide.

300300

Element property

Element property variables can be used to extract a property from an element on the page and store it in a variable. To create an element property variable, follow the steps below:

  1. Select Element property from the "Set value using" selector.
  2. Click the mouse icon.
  3. Select an element on the page.
  4. From the Property selector, choose what element property you would like to set the variable to, such as innerText, class, or tagName.
  5. Assign the variable a name.
  6. Click the OK button to store your Element property variable.
590590

Custom JavaScript variables

Custom JavaScript snippets can be used to generate a variable value. For more details on writing JavaScript snippets, check out this guide. The output of the snippet will be displayed in the shaded Results box.

584584

Mabl mailbox address

By setting the source to "mabl mailbox address", you can generate an email address that can be used for further email testing. See our guide on Email testing and validation for more information.

Data source

Selecting "data source" creates a test data-driven variable. For more information on this variable source and how to use it, check out our guide on test data-driven variables.

Converting test-generated variables into data-driven variables

If you decide to use shared variables or a DataTable, and you want to convert existing variables into data-driven variables, you can do so in four steps:

  1. Click on the pencil icon of the create-variable step(s) that you would like to convert.
  2. Change the source to "data source."
  3. Enter a default value.
  4. Click OK.

Two things will happen when you do convert the variable:

  1. The create-variable step will be removed from the test steps in the Trainer window.
  2. The variable will appear with its current value in the list of data-driven variables shown in the Manage Data-Driven Variables tab.

Did this page help you?