Still finding the issue unable to make the Local variable in one test case as Global Variable and use in another test case Katalon Version 6.3.3

I have initialized one variable in one TC as “GlobalVariable” and tried to use the same variable in another TC’s unable to do the initialization.

Getting the below error:
10-21-2019 09:24:01 AM Test Cases/SimpleTest/Sample11

Elapsed time: 0.677s

Test Cases/SimpleTest/Sample11 FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: x for class: internal.GlobalVariable
at Sample11.run(Sample11:23)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)

Requesting your support to solve the issue

the global variable must exist in the given profile (aka declared by click-click) before to ‘initialize’ it (assign value)
or use metaprograming (search the forum for the solution) to declare it ‘on the fly’

hello

here keyword to add global variable in runtime

import internal.GlobalVariable

public class CreateGlobalVariables {

	@Keyword
	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
	}
}

Hi,

Thanks for help.
Still I am finding the issue. I have tried to initialize a variable in the TC and used the same variable in the other TC to get the value. Getting the below error:

10-22-2019 10:06:39 AM Test Cases/SimpleTest/Sample11

Elapsed time: 0.467s

Test Cases/SimpleTest/Sample11 FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: x for class: Script1571299931092
at Sample11.run(Sample11:24)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1571727992293.run(TempTestSuite1571727992293.groovy:35)

if you tried to run the test cases manualy (one by one) this method won’t work.
the instance of the globalvariable class it is scoped to a running testsuite
during manual run, the instance created by the gui is used (which is not updated by the metaprograming hook)

Hi Ibus,

I have placed the cases in a test suite, itself and executing the scenario. Please find the attached screenshot. Correct me if I am wrong any where

The above TC of Agency user should be able to create contract with amount has the following TC in it:

From here the Highlighted case has this value of New_Contract and I am trying to get this value into the Sample11 TC.