Global Variables and Execution Profile

Execution Profile

Execution Profile helps cover multiple and different environments to execute your automation test scripts with ease. You can configure the testing environment in terms of data and behaviors through Global variables.

Create a profile

Like other test artifacts, you can CRUD the Execution Profile in the Tests Explorer.

You need to define a profile's content by adding Global variables. Do as follows:

  1. Select a profile > click Add.

  2. In the New Variable dialog, specify details for the variable > click OK.

  3. The variable is added to the profile accordingly.

View a profile

Execution profile is provided with Manual view and Script view. In the Script view, an XML editor is available for adding variables via script. Depending on the project needs, you can create as many profiles as you want to.

In the Script view, profiles are in sync once a similar list of Global Variables is required for testing different environment types. To conduct, copy and paste the variables list from one profile to another.

Set default profile at project level

Introduced in v7.4.2, you can set a default profile at the project level.

A default profile is considered as a place to comprise commonly used global variables. Other profiles can either inherit or override the global variables stored in the default one. Read more about Profile Inheritance.

You may have multiple profiles for executing your tests, for instance, staging and production profiles. It would be convenient to set a profile as your default one in every execution of a project.

Right-click on your desired execution profile and select Set as default Execution Profile.

This profile becomes a default execution option for Test Case, Test Suite, and Test Suite Collection.

It's also applied for the Command Generator's Executive Platform in case you use Katalon Runtime Engine.

Profile Inheritance

Profile Inheritance reduces your effort spent on modification and recreation of the same global variables in derived profiles. Suppose Katalon Studio does not find variables used in the test within the designated profile (any profiles but default). In that case, it will look into the default profile and use its variables to execute the test.

How to utilize Profile Inheritance

Commonly used global variables should be stored in the default profile and should store other sets of global variables in the derived (custom) profiles to avoid duplicated code and for better management.

Running the examples

The following examples illustrate how the Profile Inheritance feature works.

  • Given the following test case:

  • Execute default profile with the given test case:

    The result is shown as below:

  • Execute stagging and production profile with the given test case:

    When executing the stagging and production profiles, the name, serveURL, and credential variables are overridden (highlighted in red), while the usage and reference variables are inherited (highlighted in blue) from the global variables in the default profile.

    • Stagging profile:

      The result is shown as below:

    • Production profile:

      The result is shown as below:

Use a profile

By default, Katalon Studio uses the default profile for executing tests, as indicated on the screen's top right corner. You can select any available execution profiles in the drop-down menu.

The following section shows you a usage example. There are three profiles based on testing environments: local, staging, and production.

  • For test cases or test suites: Select your desired profile on the top right > all Global Variables within your current project automatically uses these values.

  • For Test Suite Collection: Select your desired profile to be executed with your Test Suite on the Profile column.

  • For Console Mode execution: Select your desired profile on the Profile field.

    The Generated Command has executionProfile parameter so that you can change it manually. For example:

    katalonc -noSplash  -runMode=console -consoleLog -projectPath="C:\Users\Admin\Katalon Studio\yourProject.prj" -retry=0 -testSuitePath="Test Suites/TS_RegressionTest" -executionProfile="local" -browserType="Chrome (headless)

Global Variables

A global variable is a variable defined in the execution profile and can be used in a test case, test object, web service object, and email configuration in a project.

Scope of Global Variables

Global variables are Test Suite scoped. If any Global Variable value is changed during runtime, this change will not be shared among Test Suites. This infers that you can modify Global Variables when executing a particular Test Suite without affecting other Test Suites' Global Variables in the Test Suite Collection.

You can find "Test Suites/New Test Suite (1)" is listed twice in the following screenshot. The first one uses "default," and the second one has "stagging". This association proves that a Profile is Test Suite scoped. Otherwise, the association can not be logically valid.

Use a Global Variable

Any test cases across a project can use global variables - for example, input data for keywords in Manual View (highlighted in blue) or params when binding Data for Test Execution (highlighted in red).

Parameterize a Global Variable

You can directly parameterize Global Variables in WebUI, Mobile, Windows, and API Test Objects. To parameterize a global variable, enter the syntax ${} in each type's supported locations.

For example:

  • in HTTP Body of an API Test Object:

  • in Selected Locator of a WebUI Test Object:

  • in Requested URL of a Web Service Request:

Use escaping, special characters

To use a special character like $ or \ as a regular one in any place that calls parameterized global variables, prepend it with a backslash: \ (the so-called escape character).

   "productName": ${GlobalVariable.productName},
   "unit": "\\bottle\",
   "quantity": 50,
   "discount": ${ if (productName == "wine") { return 30 } else { return 0}}
   "note": "Currency unit of ${GlobalVariable.productName} is \$."

  • Without \: note: Currency unit of ${GlobalVariable.productName} is $.
  • With \: note: Currency unit of wine is $.

Create Global Variables during runtime

Here is an approach provided by Sergii Tyshchenko.

  1. Define an environment variable (with a path to an external configuration or a properties file) in the session used to execute Katalon Studio.
  2. In the TestListener, read the variable's value (a path to the file), load that file, and override the project settings or Global variables. Use the following metaprogramming:
 void addGlobalVariable(String name, def value) {
  GroovyShell shell1 = new GroovyShell()
  MetaClass mc = shell1.evaluate("internal.GlobalVariable").metaClass
  String getterName = "get" + name.capitalize()
  mc.'static'."$getterName" = { -> return value }
  mc.'static'."$name" = value

It is possible to add getter and/or setter as new methods to the GlobalVariable class or add a new field. Then in the script, you can use GlobalVariable.VarName where the VarName is your new variable.

CustomKeywords.'helper.addGlobalVariable'('localURL', '')
println GlobalVariable.localURL

Go to the original discussion.

Update Global Variables during runtime

To change a global variable's value during runtime, use the following command syntax -g_XXX (Learn more).

See Also: