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 com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords 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.openBrowser(’’)

WebUI.navigateToUrl(‘https://gauth.apps.gbraad.nl/’)

WebUI.click(findTestObject(‘Object Repository/Page_/a_Edit’))

WebUI.click(findTestObject(‘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’)

WebUI.click(findTestObject(‘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.
Reason:
groovy.lang.MissingPropertyException: No such property: OTP for class: internal.GlobalVariable
at 2_way_test_variable.run(2_way_test_variable:34)
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:133)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:116)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:83)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1563160444252.run(TempTestSuite1563160444252.groovy:35)

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!

+1

Yep. That’s the best way.

@Russ_Thomas thx for correction :slight_smile: