Skip to main content

Quality Assurance

Introduction to Global Variables and Execution Profiles in Katalon Studio

Man looking at tablet with coworker

Introduction

In Katalon Studio, global variables and execution profiles are powerful features that allow you to manage testing environments, data, and behaviors across your entire project. Global variables provide a way to define reusable values that can be accessed throughout your test cases, test objects, web service objects, and email configurations. Execution profiles, on the other hand, enable you to configure these global variables for specific testing scenarios or environments. We’ll dive deep into how to leverage global variables and execution profiles in Katalon Studio, with a focus on practical examples tailored for Salesforce testing.

 

Understanding Global Variables

Global variables are pre-defined values that can be accessed across your entire Katalon Studio project. They are particularly useful for:

  • Inputting data for keywords in Manual view
  • Binding data for test execution
  • Configuring testing environments

To create a global variable in Katalon Studio:

  • Right-click on the “Profiles” node in the Tests Explorer tab and select “New” > “Execution Profile”
    Picture1
  • Enter a name for the profile and click “OK”
  • In the profile’s Manual view, click “Add” to define a new global variable
  • Specify details for the variable, such as its name and value, in the “New Variable” dialog
    Picture2

 

You can view your execution profile in both Manual View and Script View:

Manual View:

Picture3

Script View:

Picture4

Global variables can be used in various parts of your test scripts, such as:

  • In the HTTP Body of an API test object
  • In the Selected Locator of a WebUI test object

Utilizing Global Variables in Test Execution

When you select an execution profile, you can establish global variables for running test cases, test suites, and test suite collections in various scenarios. By default, Katalon Studio utilizes the default profile, which is displayed on the main toolbar.

 

In Test Cases and Test Suites

To implement global variables in your test cases and test suites, choose your preferred profile from the main toolbar. This selection will apply to all test cases and test suites within your project. Within a test suite, you can only choose one specific profile that will be applied to all test cases in that suite. For instance, you can run three test cases simultaneously using the default profile in this test suite.

 

Global Variables in Test Suite Collections

In a test suite collection, you have the option to designate which profile to use for each test suite in the Profile column. This capability allows you to tailor the execution of each test suite according to the specific needs of your testing scenarios.

 

Working with Execution Profiles

Execution profiles in Katalon Studio allow you to define global variables for specific testing scenarios or environments. This is particularly useful when executing test cases, or test suite collections in different contexts. To select an execution profile for test execution:

  1. Choose the desired profile from the main toolbar in Katalon Studio
  2. In a test suite collection, you can specify which profile to use for each individual test suite

Global variables defined in execution profiles have a test suite scope. This means that modifying the value of a global variable in one test suite will not impact the values in other test suites within a test suite collection.

 

Inheriting Profiles

Katalon Studio supports profile inheritance, which allows you to reduce the effort spent on modifying or recreating the same global variables across multiple profiles. The “default” profile is commonly used to store commonly used global variables. When executing a test case, if Katalon Studio does not find a variable within the designated profile, it will look into the “default” profile and use its variables to execute the test.

 

Example 1: Configuring Test Data

Global variables can be used to store test data for different scenarios or user types in Salesforce testing. For example:

WebUI.setText(findTestObject('Object Repository/UsernameField'), '${GlobalVariable.adminUsername}')

WebUI.setText(findTestObject('Object Repository/PasswordField'), '${GlobalVariable.adminPassword}')

In your execution profile, define global variables for adminUsername, adminPassword, moderatorUsername, moderatorPassword, etc.

 

Example 2: Handling Different Environments

When testing Salesforce applications in different environments (e.g., staging, production), you can use global variables to store environment-specific settings:

WebUI.navigateToUrl('${GlobalVariable.salesforceURL}')

In your execution profiles, define global variables for salesforceURL, apiEndpoint, databaseConnection, etc. with values specific to each environment.

 

Best Practices and Tips

  • Store commonly used global variables in the “default” profile to enable inheritance
  • Use descriptive names for global variables to improve readability and maintainability
  • Regularly review and update global variables to ensure they are still relevant and accurate
  • Consider using a data-driven approach by storing test data in external sources like Excel or CSV files

 

Improved test maintenance in Katalon Studio

By allowing for reusable values across multiple test cases and environments, global variables streamline the testing process and reduce redundancy. Here’s how they contribute to better test maintenance:

  1. Centralized Management of Values

Global variables allow testers to define key values in one location, which can then be accessed throughout the project. This centralization means that if a value needs to be updated—such as a URL, username, or password—it can be changed in one place rather than in every individual test case. This significantly reduces the risk of errors and inconsistencies that can arise from manually updating multiple scripts.

  1. Reduction of Redundancy

In many testing scenarios, especially when dealing with similar test cases or workflows, the same values are often required. Instead of duplicating these values across various test cases, global variables enable testers to reference them, thereby reducing redundancy. This not only saves time during the initial setup but also simplifies future updates, as changes are reflected across all test cases that utilize these variables.

  1. Improved Readability and Maintainability

Using global variables enhances the readability of test scripts. Instead of seeing hard-coded values scattered throughout the code, testers can use descriptive variable names. For example, instead of seeing multiple instances of a URL like https://example.com, a global variable like ${GlobalVariable.baseURL} can be used. This approach makes it easier for anyone reviewing the code to understand what each value represents and how it is used.

  1. Environment-Specific Configurations

Global variables can be defined within execution profiles, allowing for easy configuration of different testing environments (e.g., development, staging, production). By creating separate execution profiles, testers can switch between environments without modifying the test scripts themselves. This flexibility is particularly useful in continuous integration/continuous deployment (CI/CD) pipelines, where tests may need to run against different environments frequently.

  1. Scope Control

Katalon Studio allows for the definition of global variables within the context of execution profiles. This means that changes made to global variables in one profile do not affect those in another. For example, if a test suite is configured to run with a “staging” profile, it can use different credentials or URLs than those defined in a “production” profile. This isolation of variable values helps maintain the integrity of tests across different environments.

Conclusion

Global variables and execution profiles in Katalon Studio are powerful tools that can significantly enhance your Salesforce testing efforts. By leveraging these features, you can create more flexible, maintainable, and efficient test scripts that adapt to different testing scenarios and environments.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sanket Dudhe

Sanket Dudhe is a Technical Consultant at Perficient. He has an experience of 4+ years as SDET. He loves technology and hence is curious to learn about new emerging technologies #lovefortechnology.

More from this Author

Categories
Follow Us