Using variables

Variables help address testing scenarios that require dynamic values. They also help with passing values to, from and in-between test so you can keep your user journey tests shorter and easier to troubleshoot and maintain.

Use cases

  • Generating random values, including email address email testing with mabl Mailbox
  • Extracting values from element properties of the app under test
  • Securely managing user credentials that are passed to a test via variables
  • Calculating dates and deriving other values using custom JavaScript code
  • Performing data-driven testing to easily validate different scenarios
  • Sharing variable values between tests, which are called journeys in mabl
  • Managing values at an environment level (API keys, endpoints) and using them across journeys

Variables overview

When working with variables in mabl, you can think about them in three different categories:

  • Environment variables - include system-reserved variables (e.g. app.url and app.username) and derive their values either from the plan configuration or the defined environment variables.
  • Journey-generated variables - the value is generated during a journey run, as for example extracting it from an element property like innerText.
  • Data-driven variables - the value is derived from a data source such as a mabl DataTable or shared variable from a previous journey run.

Adding variables

  1. Start a new trained journey and open the mabl Trainer.
  2. Look for and hover over the "{x}" button at the bottom, and click to "Create" a variable.
  1. You will be brought to a new screen where you can assign a dynamic value source to the variable and give it a name. At present, you can generate variables from random string patterns, element properties, custom JavaScript code or a data source.

Adding variables with random values

Creating variables from a string template allows for the ability to use random macros to generate a pseudo-random string. A pattern can contain multiple random macros into which random strings will be substituted. Macros are delimited by double curly braces, e.g. {{macro}}. Currently 5 random string alphabets are supported: alpha (uppercase and lowercase letters), alphaLower (a-z), alphaUpper (A-Z), digit (0-9), and alnum (alphanumeric, i.e. alpha + digit). Along with the alphabet, a length for the generated string must be specified. Here are some examples of patterns and random strings produced by each pattern:

{{digit:2}} inch monitor
87 inch monitor

{{alnum:8}}
G7Wz8pU1

Each time the test runs a new random value will be generated for each generated variable.

To create a variable with random values:

  1. Enter a name for your variable in the "Variable name" field.
  2. For the "Set value from" field choose "String Template" selector.
  3. Add a desired pattern, using the info located above.
  4. Examine the lower shaded box and ensure it matches your desired output.
  5. Press the "OK" button to save your variable.

Adding custom JavaScript variables

Custom JavaScript snippets can be used to generate a variable value. The result will be displayed in the shaded output box. To learn more about this process checkout the "Using JavaScript to Define a Variable" section of the Using JavaScript steps in the Trainer help doc.

Adding element property variables

Property variables are variables whose values are set by finding an element on the page and extracting a property from it. Currently the only property that is supported is the inner text of an element.

To use a property variable, follow the steps below:

  1. Select "Element property" from the "Set value from" 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. e.g. innerText, class, tagName...
  5. Click the "Save" button to store your Element property variable.

Use existing variables to define a new variable

You can now compose a new variable using existing variables, in addition to randomly generated alpha-numeric strings. In the example below, we extracted the text of an element and stored it in a variable named "email". Then we created another variable "url" with the "email" variable embedded, for testing the email verification endpoint.

Using variables

  1. Once at least one variable has been defined, you will be able to use that variable by clicking on the "(x)" button and then clicking on "Use" in the menu that pops up.
  1. Select whether you'd like to use the variable as an input value or URL to visit. Clicking the latter will automatically add a step.
  1. If you'd like to use the variable as an input value, click the "Input value" button.
  2. Select a text element (an input field or textarea) on the page into which the variable's value should be inserted. Then you will be asked to select a variable to insert.
  1. After clicking "Use variable" the variable's value will be inserted into the selected element on the page.

Using variables within variables

Sometimes it's important to create multiple variables all based on one original variable, whether it be URLs, email addresses, or similar. The ability to add variables within variables make that functionality easy.

  1. Follow the steps above to create your first variable, the process is the same.
  2. Create another variable and assign a new name to it.
  3. Ensure that you select the "Generated" radio button under the "Value" heading.
  4. Type in the basics for the variable you'd like to create.
  5. Following the standard pattern, type {{@theFirstVariable}} in the spot where you want to add your first variable. For example, a variable called email would be written as {{@email}}.
  6. The box below will update with the variable preview, as shown below.

Using credentials as variables

When adding a plan, if you provide a set of credentials, mabl will exercise the auto-login feature; that is, mabl will try to figure out how to log into the app on her own. But if you want to train her instead, the app credentials are now accessible in the trainer as variables, and you can apply them to login fields.

Your credentials are stored separately from the journey script. They are encrypted at rest and in transit. You can even configure multiple plans that supply different credentials to the journey at runtime.

Credential variables are examples of a new class of variables that are configuration related and automatically defined. You cannot edit the values of these variables, but you can use them like any other variables, including in a generated variable pattern (e.g. "{{@app.url}}") or in a custom JavaScript.

Currently the following variables are supported:

"app.url" - URL of the app under test
"app.username" - App login username specified in a plan
"app.password" - App login password specified in a plan
If you want to use these variables in a custom JS step, you may reference them as:

"mablInputs.variables.web.defaults.url"
"mablInputs.variables.web.defaults.credentials.username"
"mablInputs.variables.web.defaults.credentials.password"

Using variables


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.