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.

How to create an environment variable

  1. Go to Configuration > Applications
  2. Hover over the name of the environment that you'd like to add the environment variable to. A pencil icon will appear next to the environment.

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

  1. Click on the pencil icon. The "Edit environment" page will appear.
  2. Click on the "Add environment variable" button.
  3. Enter the variable name and value. If you are using a variable across different environments, make sure that the name matches exactly. (Variable names are case sensitive.)

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


Use all caps for environment variable names

By using the conventional "screaming snake case," you can quickly distinguish environment variables from the other variables in a test.

Using environment variables

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


Using an environment variable as part of API request


Valid expressions in environment variables

The following valid expressions are supported for environment variables:

  • Macros
  • Random data
  • Math expressions

Keep in mind that these expressions will evaluate to a new value in every training instance and test run.

Environment variables cannot contain references to another variable, such as {{@another_variable}}.

Related resources