Using variable in Object's Properties

Hi

How can I use a variable in object’s properties? I try to tap on a element with text equal to variable ‘randomNumber’ value.

3.png

Try switching to script mode (at least I am doing so) and use:

The solution throws:

FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject) values: [TestObject - ‘Object Repository/TEST1/LIST_SELECTION’]

4.png

Ok, I usually explicitly define TestObject, and set the last parameter to “true”:

TestObject new_value = WebUI.modifyObjectProperty(findTestObject(‘TEST1/LIST_SELECTION’), ‘text’, ‘equals’, randomNumber, true)

I tried to define the TestObject and to set the last parameter to true and I have the same error. As i see the method ‘modifyObjectProperty’ has a prefix WebUI and i use the script to test a mobile app. Maybe that’s the problem?

Sorry, my bad! I didn’t see you were asking a mobile testing question.

bump

Please refer to this guide: https://docs.katalon.com/pages/viewpage.action?pageId=12419075.

There’s a dot and an extra space. It should be this:
https://docs.katalon.com/pages/viewpage.action?pageId=12419075

Thanks for the reply!
I tried the solution from Vinh Nguyen, but with poor results.
After that i found this function: https://docs.katalon.com/display/KD/[Mobile]+Select+List+Item+By+Label
that works great for my example!

Using it as:
Mobile.selectListItemByLabel(findTestObject(‘TEST1/LIST_SELECTION’), randomNumber, 10)
is taping the row that i just created!

I had similar issue while putting a variable in objects xpath
Variable name :DocTitle=‘Test Document’

original Xpath : //a[contains(@id,‘tableRecord’) and (text() =‘Test Doc’)]
(Need to replace text with dynamic document name )

Modified Xpath in script :
TestObject new_value = WebUI.modifyObjectProperty(findTestObject(‘Favourite Documents/Page_Documents List/Test’), ‘text’,

'equals', DocTitle, true)  

but its not working…
Thanks in advance

Hi Usha,

Could you try defining the original xpath as:

//a[contains(@id,'tableRecord') and (text() ="${docTitle}")]

And then when you want to substitute the docTitle for your given test:

TestObject new_value = findTestObject('Favourite Documents/Page_Documents List/Test', [('docTitle') : 'My Specific Doc Title'])

This should replace the ${docTitle} in your original xpath with the value ‘My Specific Doc Title’.

Hope this helps,

Chris

4 Likes

You need to use Double quotes string to enclose String interplation ${}

//a[contains(@id,'tableRecord') and (text() ="${docTitle}")]

see http://groovy-lang.org/syntax.html#_string_interpolation

3 Likes

FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Unable to verify object ‘Object Repository/Favourite Documents/Page_Documents List/Test’ is present (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Favourite Documents/Page_Documents List/Test’ located by ‘By.xpath: //a[contains(@id,‘wtFavoritesTableRecord’) and (text() =“${docTitle}”)]’ not found)

I think its still not recognizing my the variable :frowning:

2018-10-03 12_44_42-NLAPDDW522 - Desktop Viewer.png

2018-10-03 12_45_16-NLAPDDW522 - Desktop Viewer.png

2018-10-03 12_45_44-NLAPDDW522 - Desktop Viewer.png

Ushaj,

Please show your test case script to us. Possibly you need to wait for an HTML element explicitly.

new_value =findTestObject(‘Favourite Documents/Page_Documents List/Test’, [(‘docTitle’) : DocTitle])

WebUI.verifyElementPresent(findTestObject(new_value), 50)

What is this? It looks nonsense to me. How come you have a nested calls for findTestObject()

Do you want this?

WebUI.verifyElementPresent(    findTestObject('Favourite Documents/Page_Documents List/Test',        [('docTitle') : DocTitle]),    50)

where it is nested??
Tjhere are two different lines…

kazurayam said:

What is this? It looks nonsense to me. How come you have a nested calls for findTestObject()

Do you want this?

WebUI.verifyElementPresent(    findTestObject('Favourite Documents/Page_Documents List/Test',        [('docTitle') : DocTitle]),    50)

It is not nested… there are two different lines

Your code can be rewritten as follows.

WebUI.verifyElementPresent(    findTestObject(        findTestObject(            'Favourite Documents/Page_Documents List/Test',            [('docTitle') : DocTitle])    ),    50)

Don’t you find nested findTestObject() calls here?