Adding and using variables

It is now possible to define and use dynamic variables during a training session to bolster your tests.

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, "Create Variable" will display.
  1. You will be brought to a new screen that allows you to assign a name to the variables, as well as choose between a generated, property, or custom javascript variable.

Adding generated variables

Generated variables use a pattern 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


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

About Variables with URLs

Adding variables to existing URLs in your browser's navigation is currently not supported.

To add a generated variable, follow the steps below:

  1. Choose a name for your variable from the first dropdown titled "Variable name"
  2. Make sure the "Generated" option is selected from the "Value" radio button.
  3. Add a desired pattern, using the info located above.
  4. Examine the shaded "Preview" box, ensuring it matches your desired output.
  5. Press the "OK" button to store your generated 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.

Adding 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 the Property radio button.
  2. Select the mouse icon.
  3. Select an element on the page.
  4. Examine the trainer, the preview will be populated to confirm that the correct element was selected.
  5. Click the "Save" button to store your 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 variable" 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:


Adding and 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.