In mabl, you can define variables at the environment level and use them across multiple tests. Environment variables are great for defining environment-specific URLs, API endpoints, and API keys so that you can run the same tests across multiple environments such as staging and production.
This article explains how to add environment variables in the mabl app.
You can also manage environment variables programmatically from the mabl CLI and mabl API. These options are great for making updates in bulk.
Add environment variables in the app
- Go to Configuration > Application
- 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.
- Click on the pencil icon to open the edit environment page.
- Click on the Add environment variable button. Alternatively, if you are importing environment variables from Postman, click on Import Postman variables.
- 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. Examples: "API_URL", "ADMIN_USERNAME"
Import environment variables from Postman
To import a pre-existing Postman environment into mabl, click the Import Postman variables button and upload the JSON of your Postman environment. Choose which variables to import, including editing their names and values. When you save the Import Postman variables form, the variables are added to the environment.
Importing Postman environment variables
A warning icon indicates a conflict with an existing variable in the environment. Saving the conflicting variable overwrites the existing value in your environment.
Limitations
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.
Environment variables cannot contain references to another variable, such as {{@another_variable}}
.