Environment variables

In mabl, you can define variables at an environment level and use them across multiple tests. Those same tests can then run across multiple environments, such as dev and production, as long as each environment defines the same variables.

A common use case for this feature is to define variables for environment-specific URLs, API endpoints, API keys, etc. so that you can easily run the same tests across multiple environments such as staging and production.

To create environment variables go to Configuration > Applications and then click the name of an environment to edit it.

The configuration screen showing to click the title of the environment.

The configuration screen showing to click the title of the environment.

View of the Edit Environment screen showing an Environment variable made titled API_URL

View of the Edit Environment screen showing an Environment variable made titled API_URL

Once created, you can use environment variables in your tests in the same way as you would use other variables created in the test, using the mabl Trainer. For example, you can input an environment variable into a text field, use it to visit a URL or reference as part of an API request as shown on the screenshot below.

Using an environment variable as part of API request

Using an environment variable as part of API request

Random environment variables

By default, when you define an environment variable, its value is treated as a static string. Nevertheless, you can generate random values using string templates with environment variables in the following way:

  1. Create an environment variable using a string template for its value
  2. In the mabl Trainer, create a variable from a string template that is being generated by the environment variable
  3. Run the test from the mabl app to validate everything works as expected

Limitations

This functionality works as described below but you will not be able to see the actual generated random value in the test run results, unless you review the screenshots.

To create an environment variable that generates a random user email, for example, you can define it with the following string template: user+{{alnum:5}}@example.com (as shown in the screenshot below).

Creating environment variable with a random string template as its value

Creating environment variable with a random string template as its value

Next, we need to go to our test and, using the mabl Trainer, create another variable, userEmail, that uses the existing environment variable as its string template as shown below.

Creating a variable based on an existing environment variable

Creating a variable based on an existing environment variable

If things are working correctly, you should see the string template assigned to the environment variable in the Preview field.

You can then use this second variable, userEmail, as part of your test. The value of the userEmail variable will not be randomly generated until you run the test in the cloud. When the test runs in the cloud, mabl will assign a random value to the userEmail variable based on the string template coming from the respective environment variable.

In the end, to verify that everything works, just trigger a test run in the cloud and review the results to ensure you see the expected random values as shown in the screenshot below.

Journey run results

Journey run results

Updated 23 days ago


Environment variables


Suggested Edits are limited on API Reference Pages

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