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
- Go to Configuration > Applications
- 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
- Click on the pencil icon to open the edit environment page.
- Click on the Add environment variable button.
- 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.
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"
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.
Importing 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.
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
The following valid expressions are supported for environment variables:
- 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