Create/change variables from test script

Hi guys, I’d like to ask if it is possible to create and change global variables in a test case.

I want to pass a variable from TC1 to TC2 (var1 is created in TC1, it finishes, TC2 starts and var1 can be used in TC2 execution).

Are there any available methods to access (global) variables? Or is there any other way how to achieve behavior I mentioned above, maybe TestData? I found only get methods in documentation, no set methods for TestData class.

Thanks!

It’s working, thank you.

Please try this link

Example for using:

TC1:

import internal.GlobalVariable

GlobalVariable.var1 = 'sample value'

TC2:

import internal.GlobalVariable

println GlobalVariable.var1

1 Like

@duyluong said:
Please try this link

Example for using:

TC1:

import internal.GlobalVariable

GlobalVariable.var1 = ‘sample value’

TC2:

import internal.GlobalVariable

println GlobalVariable.var1

Thanks, This worked for me.

you should run these test cases in test suite and set TC1 first and then TC2

Is there a way to make these persistent after a run ends? I’m using an Excel to drive the data for my GlobalVariables, but would like to only run it whenever I change environments or we run a test suite. Currently, I have to have the TestHook run before every test case.

for (int index = 0; index < environmentData.getRowNumbers(); index++) {

String variableName = environmentData.internallyGetValue(‘Name’, index)

String variableValue = environmentData.internallyGetValue(env, index)

‘This is only for String values. Any integers for timeouts should be universal across environments’

GlobalVariable[variableName] = variableValue

logger.info(('Environment variable ’ + variableName + ’ set to ’ + variableValue) + ‘.’)

}

Hi! tks for the information
Is it possible to do the same “pass variable value”, to a Data File with Data Type Internal Data?

Hello,

what is the command in the recorder for creating a variable ? how can I call it in the test cases then? thank you

in selenium ide i was using store | variable_content | var
and then echo ${var} was showing me variable_content

how do i do it here?

Admittedly I have not tried it yet, but how does the GlobalVariable aspect behave with respect to parallel execution on multiple browsers? Will each thread have its own GlobalVariable space / object ?

AFAIK Katalon uses ThreadLocal instances of WebDriver, thus all variables would be thread-safe during parallel execution.