No such property: OTP for class: internal.GlobalVariable

Hi I dont know why but I keep getting this error. Am i calling the global variable wrongly?

I called the global variable as : GlobalVariable.OTP

What error?

Please read this paying particular attention to points 3 and 4.

I generated a global variable and stored a value generated during the test case. The code is shown below.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable


WebUI.navigateToUrl(‘’)‘Object Repository/Page_/a_Edit’))‘Object Repository/Page_/a_Add’))

WebUI.setText(findTestObject(‘Object Repository/Page_Add account/input_Account name_keyAccount’), ‘username’)

WebUI.setText(findTestObject(‘Object Repository/Page_Add account/input_Secret key_keySecret’), ‘somesecretkey’)‘Object Repository/Page_Add account/a_Add’))

String code = WebUI.getText(findTestObject(‘Object Repository/Page_/h3_764180’), FailureHandling.CONTINUE_ON_FAILURE)

CustomKeywords.‘variable.vars.addGlobalVariable’(‘OTP’, code)

Then, in another test case i called this global variable to be used as an input :

WebUI.setText(findTestObject(‘Page_Administrator Portal Login/input_Continue_token’), GlobalVariable.OTP)

Then I get the following error:

2019-07-15 11:14:21.358 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/2_way_test_variable FAILED.
groovy.lang.MissingPropertyException: No such property: OTP for class: internal.GlobalVariable
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.TestCaseExecutor.runScript(
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
at com.kms.katalon.core.main.TestCaseExecutor.execute(
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(
at com.kms.katalon.core.main.TestSuiteExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$ Source)

did you run the test manually, or in a suite?

CustomKeywords.‘variable.vars.addGlobalVariable’(‘OTP’, code)

please show also the code of the custom keyword used.

however, note that, adding/updating GlobalVariables ‘on the fly’ it is scoped to test-suites only.
when running the testcases manually, you have to create/update manually the needed global too

That might be the case then because what i am doing is to use the global variable through multiple test suite through test suite collection.

So just to clarify, does this mean that it is impossible/there is no (other) way to bring global variable across to other test suites?

And yes the code is the same as the GlobalVariables ‘on the fly’ code that can be found on Katalon web!

In my understanding, for what i find out up to now (but I may be wrong) this is how the Globals are working:

When you run manually, it is used the class instance with the values defined in GUI. So, for a variable to persist across test-cases … you have to manually pick the value from first TC and update it in the GUI, then run the second one.

When a test suite is running, a new instance is created (picking the values defined in the gui as defaults) which will persist (you can add new, modify) until the suite is ended.

So … it you are asking if you can use this approach in a test collection … i don’t think it is possible.

As a solution, you can export the values needed to an external file and use that to export variables across cases/suites.

I see… thanks for the help and info! It help me clarify things regarding global variable in Katalon. The thing is, I was using global variables as one my test condition requirement is that there should be minimal usage of external file (excel, etc) and along the line of using only in-app functions as much as possible. But for now I have found another way without using Global Variable, thanks again!


Yep. That’s the best way.

@Russ_Thomas thx for correction :slight_smile: