Trying to save a bookingId to use in another test but im getting an error

Hi, me again. So ive managed to work out (I think) how to save the number to a global variable but when I try to use the variable in another test im getting an error:

=============== ROOT CAUSE =====================
Caused by: groovy.lang.MissingPropertyException: No such property: myNumber for class: Script1683208133654

Reason:
com.kms.katalon.core.exception.StepErrorException: Call Test Case ‘Test Cases/BookingID for log in’ failed because of error(s)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:66)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:74)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
at 2 -Ocean Cruise for 2 guests a full booking for SOA products excel fiddling.run(2 -Ocean Cruise for 2 guests a full booking for SOA products excel fiddling:64)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1683217407496.run(TempTestCase1683217407496.groovy:25)
Caused by: groovy.lang.MissingPropertyException: No such property: myNumber for class: Script1683208133654
at BookingID for log in.run(BookingID for log in:30)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
… 18 more

This is my test:
WebUI.waitForElementVisible(findTestObject(‘Search drop down/Page_Checkout/BookingID’), 15)

//Get the ID attribute value of an element and store it in a variable
String myId = WebUI.getText(findTestObject(‘Search drop down/Page_Checkout/BookingID’))

//If this comes back with alpha characters, it will fail
//Parse int will try to convert the value from a String type to a Number type
GlobalVariable.bookingId = Integer.parseInt(myId)

Then I want to use it in another test using this:

def myId = GlobalVariable.bookingId

WebUI.setText(findTestObject(‘MMB/Page_xxx/Booking number’), myNumber.toString())

to put it in this text box
image

this is the code:

But im struggling someone take pity on me please!

Where is “myNumber” defined and populated? If it is supposed to be your Global Variable, then just use that.

WebUI.setText(findTestObject('MMB/Page_xxx/Booking number'), GlobalVariable.bookingId.toString())

And:
Edit: are you familiar with the difference between getAttribute and getText?

String myId = WebUI.getText(findTestObject('Search drop down/Page_Checkout/BookingID'))
WebUI.comment("Id is ${myId}")

Perhaps, this may be:

String myId = WebUI.getAttribute(findTestObject('Search drop down/Page_Checkout/BookingID'), "value")
WebUI.comment("Id is ${myId}")

You probably have your GlobalVariable.bookingId defined as a Number because you plan to store an Integer in it, however, unless you are going to do some Math on it, like adding and subtracting, you should just define it as a String.

Here you have to use two statements to get your bookingId:

String myId = WebUI.getText(findTestObject('Search drop down/Page_Checkout/BookingID'))

GlobalVariable.bookingId = Integer.parseInt(myId)

Instead, if your global variable was defined as a String, you could just use:

GlobalVariable.bookingId = WebUI.getText(findTestObject('Search drop down/Page_Checkout/BookingID'))

And, from that, you would only need to put the variable back into the textbox:

WebUI.setText(findTestObject('MMB/Page_xxx/Booking number'), GlobalVariable.bookingId)

Edit: Another possibility for defining a Number is if you have a String that is a number reference in which you want to drop any leading zeros, like a Customer Number (reference 001682), then you can convert your String to a Number, which will drop all leading zeros. You are not going to do any Math on this number, but you just want it in its simplest form for some other purpose, like a filename. Then you can store your “new” reference back to a String. Otherwise, just use a String like you would for such numbers as SSN or SIN (government ids).

2 Likes

grylion54,

thank you so much for your help. I am just running it through now, but wanted to say thanks for taking the time to help me. I have been in Spain, hence the delay in responding back.

1 Like

It worked like a dream. I am forever in your debit, this is a big step forward for me in something that I wanted to do for ages and have spent ages on it until this point. :heart_eyes:

1 Like