Environment Variables

    Environment Variables


    Article summary

    In this article we'll cover creating environment variables, and being able to dynamically switch values on execution of tests. This is particularly useful when you have values you would like to reference from a single source, and also when you would like to be able to execute your tests across multiple environments (SUT, Dev, Prod, etc).  In this guide, we will delve into setting up environment variables and harnessing their power to dynamically execute tests across diverse environments.

    Environment Variables

    In this section we'll cover creating environment variables which act as a central store for variables and values, shared across the project.

    In this example, we'll cover adding an environment variable for a URL and add it to an existing API request. 

    Firstly, we'll create a New Environment Variable using the New Item button from the Models menu. An environment variable is space for users to have a global variable they can share across different objects. 

    Upon selecting to creating a new Environment Variable the user will be asked to provide a name, and any associated tags.

    A new Environment Variable Store will be created. Open this, and then select the 'Add Variable' button to add a new variable controlled by the environment.

    A popup will appear where a name and value can be entered. This corresponds to the variable you wish to expose, along with a value for it.

    If you now navigate to an API Request, in the demo we do this by opening the JSONPraceholder module in the Model view, hitting the Edit Action tab and opening the API Request tab.

    This is where you can utilise global variables. Simply add the variable name surrounded by square brackets. In our example, we replace the current API URL with [URL]. From here you can either run the example, or hit save, regenerate the API request. What you will see now is the URL is replaced by the new Environment Variable. This is possible to do for all of the parameters within the API request dialog.

    Execution Environment Values

    Execution environment variables allow users to quickly switch out any values and replace them at run-time from a published test suite. The most common use case for this functionality is to replace URLs for executing tests between different test environments.

    To use this feature, open an existing published test suite. Below we'll focus on the 'Regression' test suite.

    Select the advanced settings button. This will open the settings dialog.

    Once the settings dialog is open, navigate to the Execution tab. Here you can add new replacement values. 

    We'll add a new rule for the URL. Here we specify to replace the URL 'google.com' with 'dev.google.com'. This will be triggered and replaced throughout our tests when executed in the test plan.