Environment variables

In mabl, you can define variables at an environment level and use them across multiple journeys. Those same journeys 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 journeys across multiple environments such as staging and production.

To create environment variables go to Configuration > Environments, select an environment, and click to edit the environment. For example, the following screenshot shows creating two environment variables - apiHost and apiKey.

Creating environment-level variables

Creating environment-level variables

Once created, you can use environment variables in your journeys in the same way as you would use other variables created in the journey, 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 journey 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 journey 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 journey 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 journey in the cloud. When the journey 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 journey 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


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.