How to pass a variable from one Test Case to another without using Excel/Data Binding?

Hi everyone, I’m really struggling with something that feels like it should be simple. I have Test Case A which generates a random dynamic string (like a unique user ID or an order number). I need to use that exact same string in Test Case B right after it.

I’ve been trying to figure this out for two days. I read online that I should use Data Binding, but that requires setting up an external Excel spreadsheet or a CSV file. I don’t want to do that because this value is generated on the fly, and managing a spreadsheet just for one dynamic variable feels like total overkill and ruins the automation flow.

I tried creating a local variable in Test Case A and then using the callTestCase keyword to run Test Case B inside it, but Test Case B just uses its own default variable value and completely ignores what happened in Test Case A. I also tried setting a variable in the local “Variables” tab of the script, but I can’t seem to access it from the other script.

How do I pass a piece of data from one test case to another purely in the script? Please help, I’m completely stuck!

Why Your Current Approach is Failing

In Katalon Studio, Local Variables are strictly scoped to the specific test case they are created in. When Test Case A finishes executing, its local memory is wiped clean. Test Case B has no native way to look backward into the memory history of Test Case A.

While WebUI.callTestCase() can pass variables, it only passes them downward (from caller to callee) as an argument, which doesn’t solve the issue if you are running a sequence of independent tests inside a Test Suite.

The Industry-Standard Solution

The robust, scalable way to share dynamic data across multiple test cases without external files is by using Global Variables housed within an Execution Profile.

Global Variables persist throughout the entire lifecycle of the Test Suite execution. Test Case A can write data to a Global Variable, and Test Case B can immediately read that data.

Step-by-Step Implementation

  1. Create the Global Variable:

    • In the Object Repository/Tests Explorer sidebar, expand Profiles.

    • Open your default profile (or create a new one).

    • Click Add and create a variable (e.g., Name: dynamicID, Type: String, Value: '' leave it blank).

  2. Update the Value in Test Case A:

    • Assign your dynamically generated value directly to the Global Variable using Groovy assignment.
  3. Retrieve the Value in Test Case B:

    • Call the Global Variable directly in your steps.

Code Implementation

Test Case A (The Generator):

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

// Simulate generating a dynamic value (e.g., an Order ID)
String generatedOrder = "ORDER_" + System.currentTimeMillis()

// Store it in the Global Variable so it persists
GlobalVariable.dynamicID = generatedOrder

WebUI.comment("Saved to Global Variable: " + GlobalVariable.dynamicID)

Test Case B (The Consumer):

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

// Read the value that was saved by Test Case A
String orderToProcess = GlobalVariable.dynamicID

// Use it in your test steps (e.g., typing it into an input field)
WebUI.comment("Retrieved from Global Variable: " + orderToProcess)

// Example usage:
// WebUI.setText(findTestObject('Page_Dashboard/input_SearchOrder'), orderToProcess)

Note on Test Execution: For this to work seamlessly, make sure you run these test cases sequentially inside a Test Suite. If you run Test Case B individually by clicking the “Run” button, the Global Variable will revert to its default blank value because Test Case A never ran to populate it.

The solution is to use Global Variables — they persist throughout the entire Test Suite execution lifecycle, so Test Case A can write data to them and Test Case B can immediately read it

Why Your Current Approach Fails

Approach Problem
Local Variables Strictly scoped to the specific test case; wiped clean when Test Case A finishes
callTestCase() Only passes variables downward (from caller to callee) as arguments, not upward
Variables tab Can’t access local variables from other scripts

Industry-Standard Solution: Global Variables

Step 1: Create the Global Variable

  1. In Object Repository/Tests Explorer sidebar, expand Profiles

  2. Open your default profile (or create a new one)

  3. Click Add and create a variable:

    • Name: dynamicID

    • Type: String

    • Value: '' (leave blank) [forum.katalon.com:2]

Step 2: Update the Value in Test Case A (Generator)

groovy

**import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

// Simulate generating a dynamic value (e.g., an Order ID)
String generatedOrder = "ORDER_" + System.currentTimeMillis()

// Store it in the Global Variable so it persists
GlobalVariable.dynamicID = generatedOrder

WebUI.comment("Saved to Global Variable: " + GlobalVariable.dynamicID)**

Step 3: Retrieve the Value in Test Case B (Consumer)



**`import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI`
`import internal.GlobalVariable as GlobalVariable`

*`// Read the value that was saved by Test Case A`*
`String orderToProcess = GlobalVariable.dynamicID`

*`// Use it in your test steps (e.g., typing into an input field)`*
`WebUI.comment("Retrieved from Global Variable: " + orderToProcess)`

*`// Example usage:`*
*`// WebUI.setText(findTestObject('Page_Dashboard/input_SearchOrder'), orderToProcess)`***

Critical Requirement: Run in Test Suite

For this to work, run both test cases sequentially inside a Test Suite:

Test Suite
├── Test Case A (generates dynamicID)
├── Test Case B (uses dynamicID)

Important: If you run Test Case B individually by clicking “Run”, the Global Variable will revert to its default blank value because Test Case A never ran to populate it.

Why Global Variables Work

Feature Benefit
Persistence Data survives across test case boundaries throughout Test Suite lifecycle
No external files Pure script-based sharing without Excel/CSV overhead
Dynamic values Handles on-the-fly generated data (timestamps, random IDs, order numbers)

Bottom line: Global Variables are the built-in mechanism for sharing dynamic data across test cases without external data files

There can be 2 types of approaches for your solution as listed below

Scenario 1: Test Case B is called from Test Case A using callTestCase()

In this case, you do not need Excel, Data Binding, or Global Variables.

You can pass variables directly as parameters:

// Test Case A

String dynamicOrderNo = "ORD_" + System.currentTimeMillis()

WebUI.callTestCase(
    findTestCase('Test Cases/Test Case B'),
    ['orderNo' : dynamicOrderNo]
)

In Test Case B, create a variable named orderNo in the Variables tab and use it:

println("Received Order Number: " + orderNo)

This is the cleanest approach when one test case directly invokes another.

Scenario 2: Test Case A and Test Case B are executed separately inside a Test Suite

If Test Case A generates a value and Test Case B needs to consume it later, then Global Variables are the recommended approach.

Test Case A

import internal.GlobalVariable as GlobalVariable

String dynamicOrderNo = "ORD_" + System.currentTimeMillis()

GlobalVariable.dynamicOrderNo = dynamicOrderNo

println("Generated Order Number: " + dynamicOrderNo)

Test Case B

import internal.GlobalVariable as GlobalVariable

println("Retrieved Order Number: " + GlobalVariable.dynamicOrderNo)

Why your current approach isn’t working

A local variable such as:

String orderNo = "12345"

exists only within the scope of that test case. Once Test Case A finishes, its memory is cleared, and Test Case B cannot access that variable.

Similarly, variables defined in the Variables tab belong only to that specific test case unless they are explicitly passed through callTestCase() or stored somewhere shared (such as a Global Variable).

can it be applied with keywords as well ?

You can pass local variables in the parameter list of your Keywords. Global Variables can either be passed as a parameter or not as they are “global” and your Keyword will recognize them.

CustomKeywords.'com.Customers.mainCustomer'("Smith")

@Keyword
public void mainCustomer(String lastname) {
  ...

}

Note: You have to include the following line at the top of your code for your Global Variables to be recognized.

import internal.GlobalVariable as GlobalVariable

you have two options depending on how your test cases run

if Test Case A calls Test Case B using WebUI.callTestCase(), pass the variable directly as a map parameter:

// Test Case A
String dynamicID = "USER_" + System.currentTimeMillis()
WebUI.callTestCase(findTestCase('Test Case B'), ['sharedID': dynamicID])

then in Test Case B, add a variable named sharedID in its Variables tab and reference it directly in the script. You were close with this approach, but you need to define the variable in Test Case B’s Variables tab so it receives the passed value

if Test Case A and Test Case B run independently in a Test Suite, use a Global Variable. Create one in your default Execution Profile (e.g. dynamicID), then in Test Case A set GlobalVariable.dynamicID = generatedValue, and read it in Test Case B. The value persists for the entire Test Suite run but resets if you run Test Case B standalone

pls check above solutions and let us know pls