Unable to identify object with added string

Good Day,

I’m trying to shorten my script
from this:

WebUI.setEncryptedText(findTestObject(‘loginPage/txtUsername’),GlobalVariable.username)

to this:

TestObject tObj = findTestObject(‘loginPage/’)
WebUI.setEncryptedText(tObj+“txtUsername”,GlobalVariable.username)

as I want to reuse testObject “loginPage” path with other test object

But im encountering this error :
2022-05-26 09:55:37.917 WARN c.k.k.core.testobject.ObjectRepository - Test object with id ‘Object Repository/loginPage/’ does not exist

Why “txtUsername” didn’t identified even if it is added to tObj

Help will be appreciated!

Thanks!

The following code will never work.

     tObj+"txtUsername"

The tObj variable is an instance of com.kms.katalon.core.testobject.TestObject class.
The "txtUsername" literal is an instance of java.lang.String.
The operator + between these 2 types is not defined. So you got an error.


The following would be shorter, would work.

Hi Kazurayam good day,

I see. but is there a way I can make it short as example on this image
with this path as repeatable and long “Clients and Physicians/Clients/Client Physician Assignment”

String abbreviation = 'Clients and Physicians/Clients/Client Physician Assignment'
WebUI.setText(findTestObject(abbreviation + "txtPhysicalLicense"),tabPhysicianAssignment.setValue(....)
...

or even shorter one:

String ABBR = 'Clients and Physicians/Clients/Client Physician Assignment'
WebUI.setText(findTestObject(ABBR + "txtPhysicalLicense"),tabPhysicianAssignment.setValue(....)
...

Even better one.
You can define a short Groovy function that encloses the long “Clients and Physicians/Clients/Client Physician Assignment” and returns a TestObject. You want to call the function repetitively

WebUI.setText(resolveTO('txtPhysicalLicense')),tabPhysicianAssignment.setValue(...)
...

TestObject resolveTO(String name) {
    return findTestObject('Clients and Physicians/Client Physician Assignment/' + name)
}
2 Likes

Great idea!

Thanks Kazurayam! I will definitely try this!