Is there a method to create an Object in the Object Repository using Groovy

I want to create objects in the Object Repository ‘on the fly’ using groovy script. Simply creating an object and assigning Properties to it does not appear to work. If I do it like this it does:

TestObject to = findTestObject(‘Object Repository/GenericObject’)
to.addProperty(“id”, ConditionType.EQUALS, ‘foobar’)

But the Generic Object must exist in the Object Repository with at least one configured property or an error is thrown.

In documentation you suggest:
myNewObject = new TestObject(“TheObjectName”) and adding properties to it, this is resulting in a null object.

Can you provide an explicit example of creating an object & adding properties to it ?

Thank you,

I did have to adjust the punctuation for it to run in my environment:
WebUI.navigateToUrl( ‘’ )
TestObject to = new TestObject(‘dynamic’)
to.addProperty(“class”, ConditionType.EQUALS, ‘btn kat-btn-default btn-lg’)
to.addProperty(“tag”, ConditionType.EQUALS, ‘a’)

But it works well, Thank you for all of your help!

This is not working for me, So I set up a simple test:

WebUI.navigateToUrl(‘’)‘mpjunk/Page_Katalon Studio/a_Download now’))


This works Great, clicks the download button.

So I tried this:



TestObject to = new TestObject(“dynamic”)

to.addProperty(‘class’, ConditionType.EQUALS, “btn kat-btn-default btn-lg”)

to.addProperty(‘tag’, ConditionType.EQUALS, “a”)‘to’))


I have tried different values for “dynamic” & “to” but no luck.
it does appear to add the object and values in the log but when used it fails.

Errors and Warnings:

warning - Test object with id ‘Object Repository/to’ does not exist
warning - Test object with id ‘Object Repository/’ does not exist

error - Unable to click on object (Root cause: java.lang.IllegalArgumentException: Object is null)
error - Test Cases/mptest2 FAILED because (of) Unable to click on object (Root cause: java.lang.IllegalArgumentException: Object is null)

If you could please make a working example, I would appreciate it.

Thanks Mark

Hi there,

You don’t need to use findTestObject when you use your created test object as test object parameter in built-in keyword. You only need to pass in the parameter without using findTestObject.You will also need to set a property as active one for detection. Below is an example:



TestObject to = new TestObject("dynamic")

to.addProperty('class', ConditionType.EQUALS, "btn kat-btn-default btn-lg")

to.addProperty('tag', ConditionType.EQUALS, "a")



1 Like

Hi there,

You can create TestObject ‘on the fly’ using the following example:

TestObject to = new TestObject("dynamic")

dynamic.addProperty("id", ConditionType.EQUALS, 'foobar')

The ‘dynamic’ value is the test object’s ID you want to create. You can freely use any other value as you want. This solution doesn’t require you to pass in existing test object in Object Repository.

I am trying to use same with mobile using xpath… that is creating object run time with passing xpath to it and then trying to gettext() from it… but its no working for me…
here is my keyword
def static TestObject makeTO(String xpath) {
TestObject to = new TestObject(“Note”)
to.addProperty(“xpath”, ConditionType.EQUALS, xpath)
Mobile.getText(to, 5)
return to

And calling this keyword in another keyword below :
(new insight.VerifyObjectRepository()).makeTO("//*[@class = ‘android.widget.TextView’ and (text() = ‘GlobalVariable.NoteValue’)]")

Here i am passing text property value from Global Variable.
I am getting error as :
com.kms.katalon.core.exception.StepFailedException: Object Note not found
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:37)