Test object value retrieving from Selected Locator

The javadoc of TestObject is published here:

https://docs.katalon.com/javadoc/com/kms/katalon/core/testobject/TestObject.html

(this page was not availabe a year ago, it was just recently published. See API doc does not cover TestObject for the history)

If you read it and write a bit of code, you can see the internal of a TestObject.


The following GitHub project of mine contains a Test Case named “main/howToGetSelectedLocators”

The source of the test case is as follows:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.SelectorMethod
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
/**
 * This test case script shows how to retrieve "Selected Locator" of TestObject
 * 
 * The javadoc of TestObject is here
 * https://docs.katalon.com/javadoc/com/kms/katalon/core/testobject/TestObject.html
 */
TestObject testObjectAttribute = findTestObject("Page_CURA Healthcare Service/a_Make Appointment_BASIC")
String selectedLocatorAttribute = testObjectAttribute.getSelectorCollection()[SelectorMethod.BASIC]
WebUI.comment("selectedLocatorAttribute='${selectedLocatorAttribute}'")

TestObject testObjectCSS = findTestObject("Page_CURA Healthcare Service/a_Make Appointment_CSS")
String selectedLocatorCSS = testObjectCSS.getSelectorCollection()[SelectorMethod.CSS]
WebUI.comment("selectedLocatorCSS='${selectedLocatorCSS}'")

TestObject testObjectXPATH = findTestObject("Page_CURA Healthcare Service/a_Make Appointment_XPATH")
String selectedLocatorXPATH = testObjectXPATH.getSelectorCollection()[SelectorMethod.XPATH]
WebUI.comment("selectedLocatorXPATH='${selectedLocatorXPATH}'")

When executed, it emits following output:

...
selectedLocatorAttribute='//a[@id = 'btn-make-appointment']'
...
selectedLocatorCSS='#btn-make-appointment'
...
selectedLocatorXPATH='//a[@id='btn-make-appointment']'
...
1 Like