Creation of Test Object in Memory


This is a companion discussion topic for the original entry at


It doesn’t touch the OR. It should say

Creation of TestObject in Memory at Runtime


The above code is out of date. TO will be created but will not be usable. Correct way:
EDIT: The code works correctly, my mistake. Another way to achieve the same would be:

TestObject createTestObjectXpath(String name, String xpath){
TestObject to = new TestObject(name)
to.getSelectorCollection().put(SelectorMethod.XPATH, xpath)
return to

Similarly for CSS-based objects
P.S. You can avoid giving TO a name, but I highly suggest it as it will help when debugging (the printed error message will mention object’s name / id)


Not true.

    'Nav to Katalon "About us" page'
    WebUI.verifyLinksAccessible(["", ""])
    'Navigate to Katalon home page using makeTO'
    TestObject to = makeTO(".navbar-header a.navbar-brand")
    'Check makeTO sent us to the correct page'
    String sURL = WebUI.getUrl()
    if(sURL != "") {
      KeywordUtil.markFailedAndStop("Something went wrong")



You can create a TestObject instance with XPath just similarly.

static TestObject makeTOwithXPath(String xpath) {
	TestObject to = new TestObject()
	to.addProperty("xpath", ConditionType.EQUALS, xpath)
	return to


@ kazurayam
@ Russ_Thomas
I stand corrected. I confirm both of the above snippets working correctly.
It was a while ago that I tried to create TO like this but it would not work (katalon would try to use an empty locator, not xpath provided by me, as if this was an empty TO).
Thank you for your answers and the provided snippets.