Variables

Introduction

A variable is essentially a placeholder for a dynamic value that you might pass in your request. Storing a frequently used value as a variable and referring to it in your test cases makes it easier when you have to change its value, because you need not change it in each test case you have used it in. You can just edit the configured variable.

You can configure different types of variables in Automation Testing that are used for different purposes.

One way of using variables is defining and storing values for fixed parameters in the Variables section, that you can easily refer to in your requests. This involves the following two types of variables:

  • Global Variables: The global variables is a single set of variables that you can define and store to be used in any of your test cases. These variables have a global scope, and can therefore be applied to all test cases.
  • Environment Variables: Environment variables help you categorize and configure values of the same keys for different environments. When you configure a test plan or perform an instant run of a test case, you can choose the environment that must be used for the execution. The variables defined in that environment will be applied. These variables can also be used globally in all test cases.

Another way of using variables in Automation Testing is extracting values received from the responses of individual requests in test cases, and assigning them to variables to pass them as parameters in the next requests in a chained set up. The scope of such variables defined within a request is only limited to that test case, and they cannot be referred outside of that test case. This method is discussed in detail with an example in the Chain Requests section.

An Example for Global and Environment Variables:

You can store different values of one variable in each single environment. For example, the value of ZAID in Catalyst is different for the Development and Production environments. In that case, you can first create two environments named “Development” and “Production”. You can then create a variable with the name “zaid” in both of these environments, and define its respective value in both separately.

While configuring a test plan, if you choose Development, the value defined for zaid in the development environment will be applied, wherever you have used the variable zaid in your requests.

You can also define the same variable as a global variable, as well as in each environment separately.

For example, you can create a variable baseURL as a global variable and define its value as “https://globaltest.com”. You can then create the same baseURL variable in the Development and Production environments with the values “https://developmenttest.com” and “https://productiontest.com” respectively.

Now, assume you refer to baseURL as the request URL while configuring the request of a test case. If you choose Development as the environment variables to use while performing an instant run, the value https://developmenttest.com will be used as the request URL. If you choose Production, the value “https://productiontest.com” will be used. If you don’t select any environment for the instant run, the global value “https://globaltest.com” will be used by default.

Important points to remember:

  • Creating the same variable as a global variable and as different environment variables is assigning multiple values to the same key.
  • You can create a global variable, and have corresponding environment variables. If you create a new variable only in a specific environment, it will still be listed in the global variables section with the same value.
  • Global variables are used by default in a test plan or an instant run, when no environment is chosen. Only when you select an environment, the environment’s values will override the global values of the variable.
  • The local variables you create inside a specific request can be declared directly by their names, and they must be passed as parameter values in other requests in the {{<variable >}} format.
  • You must pass the Global and Environment variables in the {{$<variable >}} format inside a request.

Create Global Variables

You can create global variables in the following manner:

  1. Click the Variables tab in Automation Testing, then click Create Variable.
    catalyst_pilot_create_variable_1
  2. Enter the names and values for the variables, then click Save.
    catalyst_pilot_create_variable_2
Note: Variable names must not include spaces or start with a number. Variable names are also case-sensitive.
You can also add multiple variables in bulk by clicking Bulk Add on the top-right corner. Define the variables in the key:value format in the pop-up window, then click Save.catalyst_pilot_variable_bulk_add
All these variables will be added and listed.
catalyst_pilot_variable_bulk_added

Create Environment Variables

Before you create environment variables, you must create an environment.

  1. Click Environment Variables from the Variables section.

  2. Enter a name for the environment in the pop-up window, then click Create.
    catalyst_pilot_env_variable_1

  3. You can now create variables in that environment in the same way you created Global variables. Enter the names and values of the variables, then click Save.catalyst_pilot_env_variable_2
    In an environment’s section, all your global variables will be listed when you click the Name text box. You can select one of them to assign a different value for that variable for this environment, or you can type in the text box to create a completely new variable. This variable will also be listed in the global section.

You can also add multiple environment variables in bulk by clicking Bulk Add on the top right corner, in the same as adding global variables in bulk.

Manage Global and Environment Variables

You can choose to open the global variables or a specific environment’s variables, by clicking the drop-down on top. Select the necessary option.

catalyst_pilot_variable_dropdown

  • Edit an Environment’s name: Click the edit icon next to the environment’s name. Make the changes in the pop-up window and click Update.
    catalyst_pilot_env_edit
  • Delete an Environment: Click the delete icon next to the environment’s name. Click Yes in the pop-up window.
    catalyst_pilot_env_delete
Note: If you delete an environment or a Global or Environment variable, it might affect your configured test cases and result in data loss. Make sure that you proceed with caution.
  • Delete a Variable: You can delete a Global or an Environment variable by clicking the edit icon that appears when you hover over its name.
    catalyst_pilot_variable_delete_1

Click Yes in the confirmation pop-up window.
catalyst_pilot_variable_delete_2

Last Updated 2023-05-09 17:03:08 +0530 +0530