Is it possible to share gloabal variable value between different testsuite execution?

Scenario:
I am working with katalon Studio version 10.4.3. I have a test scenario in which I have to create a data in a web application and then use that value to complete the flow in a windows desktop application.I have created a profile with global variables that is same for both test executions.

Problem:
The problem is that when the GlobalVaraible value is reset when i run the second execution.
I tried also with a test suite in which i create data in web and then close browser but In this case the lauch application fails with the below error
com.kms.katalon.core.exception.StepFailedException: Cannot invoke “String.length()” because “spec” is null (Root cause: java.net.MalformedURLException: Cannot invoke “String.length()” because “spec” is nulll

How to overcome this problem without using files to store and retrieve data from that file?

2 Likes

Problem Analysis

Your issue stems from a fundamental architectural limitation in Katalon Studio: global variables are test suite scoped, not test suite collection scoped. According to the official Katalon documentation:

“The scope of Global variables is applied in a test suite collection (TSC). During the runtime, modifying the value of global variables in one test suite will not impact the values of global variables in other test suites within the TSC.”

What’s happening in your scenario:

  1. Test Suite 1 (web app) runs and creates data, storing it in a global variable
  2. Test Suite 2 (desktop app) starts with a fresh instance of global variables from the profile
  3. The variable you set in Test Suite 1 is reset to its initial profile value (or null) in Test Suite 2
  4. When Test Suite 2 tries to launch the desktop application using this null variable, you get the MalformedURLException: Cannot invoke "String.length()" because "spec" is null error

Solutions

Solution 1: Use Test Suite Collection with Same Profile (Recommended)

Instead of running test suites separately, create a Test Suite Collection that executes both suites sequentially with the same profile:

Steps:

  1. Go to File > New > Test Suite Collection
  2. Add both test suites to the collection
  3. Assign the SAME profile to both test suites in the Profile column
  4. Set Execution Mode to Sequential
  5. Run the collection

Why this works: When both test suites use the same profile within a single collection execution, they share the same variable scope during runtime. Changes made in Test Suite 1 persist for Test Suite 2.

Important: This only works if you run them as a collection, not as separate executions.


Solution 2: Use Custom Keywords with Static Variables

Create a custom keyword that stores data in a static variable (persists across test suites):

// CustomKeywords.groovy
public class DataStorage {
    private static String sharedData = null
    
    public static void setSharedData(String data) {
        sharedData = data
    }
    
    public static String getSharedData() {
        return sharedData
    }
}

In Test Suite 1 (Web App):

// After creating data in web app
String createdValue = "your_created_data"
CustomKeywords.setSharedData(createdValue)

In Test Suite 2 (Desktop App):

// Retrieve the data
String retrievedValue = CustomKeywords.getSharedData()
// Use retrievedValue to launch desktop app

Solution 3: Use External Data Storage (JSON/Database)

While you mentioned avoiding files, this is the most reliable approach for cross-suite data sharing:

Using JSON file:

// In Test Suite 1 - Write data
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

def data = [createdValue: "your_data"]
new File("data.json").text = JsonOutput.toJson(data)

// In Test Suite 2 - Read data
def jsonFile = new File("data.json")
def data = new JsonSlurper().parse(jsonFile)
String retrievedValue = data.createdValue

Solution 4: Use Katalon TestOps Variables (For CI/CD)

If running via Katalon Runtime Engine or TestOps, use environment variables:

// In Test Suite 1
System.setProperty("SHARED_DATA", createdValue)

// In Test Suite 2
String retrievedValue = System.getProperty("SHARED_DATA")

Key Considerations

Approach Pros Cons
Test Suite Collection Simple, no code changes, variables persist Must run as collection, not separately
Static Variables Works across separate executions Requires custom keyword development
JSON/File Storage Most reliable, works everywhere Requires file I/O, not ideal for sensitive data
Environment Variables Good for CI/CD pipelines Limited to command-line execution

Troubleshooting the MalformedURLException

The error occurs because:

  1. The variable is null when Test Suite 2 starts
  2. The desktop app launch step tries to use this null value as a URL

Quick fix: Add a null check before launching the desktop app:

if (GlobalVariable.yourVariable == null || GlobalVariable.yourVariable.isEmpty()) {
    KeywordUtil.markFailed("Required data not available from previous test suite")
} else {
    // Launch desktop app with the variable
}

References

You can save your profile “data” that you need to share between your two projects to either a JSON file like @Monty_Bagati states or to spreadsheets that are located on your hard drive somewhere–all you need is the pathway to where the file, or spreadsheet, is located and name of the file, or spreadsheet. After you run the first project saving the “data” to file, you can run the second project and read the “data” in from the file.

Although I don’t recommend it, you can also write back your new data to your global variable(s). There was a discussion on this forum about doing that and code too on how to do it–I will let you search for the discussion so that you show interest in the idea. However, if you are not wanting to write to files, that is another alternative. Writing to file would be easier and SAFER. You need to persist your changed data between your two projects and that means writing it out to disk.

1 Like

Please show the source code of your program that threw this Exception. Please make it clear how the string value you passed as URL is, which is possibly malformed.

GlobalVariables reset per test suite execution in Katalon Studio; they don’t persist across separate runs even with shared profiles. The “spec null” error occurs post-WebUI.closeBrowser() as it clears the Web driver context, breaking Desktop launches referencing web globals.

Use Test Suite Collection

Combine into Test Suite Collection (TSC):

  • TS1: Web app → set GlobalVariable.dataId = createdValue
  • TS2: Desktop app → use GlobalVariable.dataId
    Run TSC once; globals share in-memory. Set profile on TSC.

Avoid Files: Execution Profile Params

Profiles > default > Variables → Add dataId as param. In TS1 last step:

import com.kms.katalon.core.configuration.RunConfiguration as RC
RC.setProperty("dataId", createdValue)

In TS2 first step, read via RunConfiguration.getProjectData('dataId'). Run sequentially via CLI/KRE: katalon -runMode=console -projectPath=... -testSuitePath=TS1 -testSuitePath=TS2.​

Fix Spec Null

Don’t WebUI.closeBrowser() in TS1; use WebUI.delay(2) before Desktop switch. Or separate drivers: Set Desktop > Default > spec explicitly without web dependency

I verified this proposal. It did not work.

@dineshh

This post looks like an AI-created halcination. Did you verify this by writing a set of codes and run it before posting ?

I verified this proposal.
This code did not compile.
The com.kms.katalon.core.configuration.RunConfiguration class does not implement the setProperty method. See the javadoc.

This must be another AI-generated halucination.

@virginia.mandracchia doesn’t mention anything about the “web driver context” concern. I wonder why @dineshh was able to end with such a firm tone.

@dineshh

Did AI tell you that?

“without using files” — this condition makes the issue very difficult to solve.

I would rather recommend to you, @virginia.mandracchia, to accept solutions using files as proposed by @Monty_Bagati Solution3. See also

Once you got a working solution using file, then you would be able to plan out a greater solution without using files.

Let me step back to the original question @virginia.mandracchia asked:

Is it possible to share gloabal variable value between different testsuite execution?

Simply, no. Katalon Studio does not allow it.


Let me suggest an alternative approach. I made a post 2 years ago as follows.

Configuring a Katalon Studio project with a JSON file

A quote from its conclusion section:

I think that the built-in features in Katalon Studio GUI around GlobalVariable are designed with an assumption that users will be happy and satisfied with manually updating Execution Profiles (= GlobalVariables); they would never want to update Execution Profiles on disk programmatically during the executions of Test Case scripts. I think that this assumption is appropriate as Katalon Studio is designed for non-programmers.

A post in Katalon user forum discussed how to break this design assumption by overwriting XML files as the serialized format of Execution Profiles. IMHO, their approach has an arguable point. I think we shouldn’t try to modify the behavior of Katalon Studio. Just leave it as is. We can invent an alternative of configuring a Test Suite using Groovy scripting.

You can configure entire “Test Suite Collection” using JSON, though you need to write certain amount of code in Groovy.

Another alternative approach would be to merge the 2 or more Test Suites into a single Test Suite. In the scope of the merged Test Suite, all GlobalVariables will be shared. In other words, I would recommend you not to use any Test Suite Collection.

Let me briefly explain my idea here. Let me assume that you have a set of Test Cases:

[
    [TestCaseA1g, TestCaseA1h],
    [TestCaseA2j, TestCaseA2k],
    [TestCaseB3m, TestCaseB3n], 
    [TestCaseB3p, TestCaseB3q],
]

And you have made a project with 2 TestSuiteCollections; namely TestSuiteCollectionA and TestSuiteCollectionB.

The TestSuiteCollectionA binds 2 TestSuites; namely TestSuiteA1 and TestSuiteA2. The TestSuiteCollectionB bunds 2 TestSuites; namely TestSuiteB1 and TestSuiteB2. The TestSuites comprise with the worker Test Cases (TestCaseA1g, TestCaseA1h, and so on) as the following diagram shows.

I would like to call this project structure as High-rise project.

Now I would set a condition that the TestCaseA1g updates a GlobalVariable.X, which the following TestCaseB3q needs to refer to. In the High-rise project, this condition will never be met. It is a design fault that I locate the TestCaseA1g and the TestCaseB3q into different TestSuites, as these 2 test cases need to share a GlobalVariable.X.


Now, I want to reform the project structure so that it uses NO TestSuiteCollection and uses only a single Test Suite which contains all the Test Cases.

I can reform the above project as follows:

I would like to call this project structure as Low-rise project.

In the Low-rise project, I introduced several new Test Cases named TestCaseC1, TestCaseC2, TestCaseC3, TestCaseC4. I will call them as Controllers. The Controllers will calls the worker Test Cases using the WebUI.callTestCase() keyword ; that’s all the Controller does.

For example, the source code of TestCaseC1 will look like this:

// TestCaseC1
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.callTestCase(findTestCase("Test Cases/TestCaseA1g"), [:])
WebUI.callTestCase(findTestCase("Test Cases/TestCaseA1h"), [:])

The TestSuiteA1 in the High-rise project is replaced with the Controller TestCaseC1 in the Low-rise project. The TestCaseC1 is functionally equivalent to the TestSuiteA1.

Now, the Low-rise project has only a single TestSuite named TestSuiteC. In the scope of TestSuiteC, all of GlobalVariables are shared. The TestCaseA1g updates a GlobalVariable.X, which the following TestCaseB3q can easily refer to. Our problem is solved!

I would recommend the Low-rise project structure to those who struggle with the problem that Global Variables can not be shared across the boundary of Test Suite.

You can reform your High-rise project into a Low-rise project using the ordinary Katalon features; you do not have to write custom codes to read/write JSON files. Easier, isn’t it?

1 Like

agree! Start with a simple property file or CSV to get the data passing working. Trying to architect a complex non-file solution usually just leads to more headaches than it is worth for simple variable passing.

1 Like

@kazurayam I attach the source code below. When this testcase run alone in the testsuite, it runs correctly, I get the error when I group web+windows testcases in one test execution. and run by selecting a browser e.g edge/chrome

Windows.startApplication(‘E:/ABACO/Deploy/bin/ICS-CA.exe’)

Windows.switchToWindowTitle(‘Parvis ABACO’)

// Verify element is present within 10 seconds
Windows.verifyElementPresent(findWindowsObject(‘Object Repository/Client/ABACO-ICS/MainMenuItems/UserAccess/UserAccessMenuItem’), 10)
1 Like

Thanks @kazurayam , @Monty_Bagati for the solutions.

I had already implemented the file based solution where I save the required data from 1 test suite and then read in the other test suite.

The problem in this solution is , with the increase in the number of testcases and changes at the application level later it will be difficult to maintain the test cases.

From my experience with other automation tools, GlobalVariables must not overwrite with each test execution run. They must keeps the previous value until a new value is stored in them. Without this logic i think it minimize the scope of the global variables.(Its a suggestion).

1 Like

@virginia.mandracchia

Many suggestions have been made for this topic. Could you mark a post as SOLUTION :white_check_mark: which best solved the problem mentioned in YOUR topic? Or are you unhappy yet?

1 Like

This is what I do, I write data to a spreadsheet then later read from the same spreadsheet. Works fine.

System.out.println('Full fileupload path = ’ + GlobalVariable.UploadFilePathvar)

String excelFile = (RunConfiguration.getProjectDir() + ‘/Data Files/’) + ‘PassVariables.xlsx’

ExcelKeywords.createExcelFile(excelFile)

workbook = ExcelKeywords.getWorkbook(excelFile)

sheet = workbook.getSheet(‘sheet0’)

ExcelKeywords.setValueToCellByAddress(sheet, ‘A1’, GlobalVariable.UserSurnamevar)

ExcelKeywords.setValueToCellByAddress(sheet, ‘A2’, GlobalVariable.UploadFilePathvar)

ExcelKeywords.saveWorkbook(excelFile, workbook)

In Katalon, GlobalVariables are reinitialized at the start of each test case/test suite execution, so they won’t retain runtime values between executions.