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, and API keys so that you can 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 appears next to the environment name.

Editing an environment

  1. Click on the pencil icon to open the Edit Environment page.
  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.


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.


Adding a new environment variable



When you save environment variables, they are serialized to JSON and encrypted using an encryption key specific to your workspace. The total size of serialized environment variables for a given environment cannot exceed 64kb.

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