# Creation of Test Object in Object Repository in Runtime

**URL:** <https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333>\
**Category:** Integrations\
**Tags:** integrations, katalon-studio\
**Created:** [April 17, 2018, 3:59pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333 "2018-04-17T15:59:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indurajan\_Mohandoss](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@Indurajan\_Mohandoss](https://forum.katalon.com/u/Indurajan_Mohandoss)\
**Post date:** [April 17, 2018, 3:59pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/1 "2018-04-17T15:59:59Z")

</div>

Hi,  
Since Katalon performs all the UI validations based on the TEST OBJECT(which is defined in Object Repository) , **is it possible to Create new TEST Object during runtime ? If possible kindly share your inputs ?**

As we can see, there’s way to modify existing TEST OBJECT from object repository folder using WebUI.modifyObjectProperty. Am looking for a way to create test objects during runtime.

It will be really helpful. Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [April 17, 2018, 4:03pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/2 "2018-04-17T16:03:41Z")

</div>

Hi Indurajan

I use this:

```auto
  /**
   * Construct a Katalon-compatible TestObject in memory.
   * @param css (String) The CSS selector used to find the target element.
   * @return (TestObject) The constructed TestObject. 
   */
  static TestObject makeTO(String css) {
    TestObject to = new TestObject()
    to.addProperty("css", ConditionType.EQUALS, css)
    return to
  }

```

---

<div class="post-metadata">

**Author:** ![Indurajan\_Mohandoss](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@Indurajan\_Mohandoss](https://forum.katalon.com/u/Indurajan_Mohandoss)\
**Post date:** [April 18, 2018, 11:35am UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/3 "2018-04-18T11:35:42Z")

</div>

Hi Russ Thomas,  
Thanks for your reply. As per your code, it will just add property to existing Object from object repository.

Is there a way to insert new TEST object into Object Repository during runtime ? Kindly ,share your inputs, Thanks in advance

---

<div class="post-metadata">

**Author:** ![Indurajan\_Mohandoss](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@Indurajan\_Mohandoss](https://forum.katalon.com/u/Indurajan_Mohandoss)\
**Post date:** [April 18, 2018, 12:54pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/4 "2018-04-18T12:54:02Z")

</div>

> Hi Russ,  
> Code worked for me . thanks for the inputs 🙂 .

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [April 18, 2018, 1:13pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/5 "2018-04-18T13:13:26Z")

</div>

Hi Indurajan

> As per your code, it will just add property to existing Object from object repository.

No, it specifically creates a **new** TestObject, _in memory_ and adds a css property to it.

> Is there a way to insert new TEST object into Object Repository during runtime ?

No, I don’t think so. And, if you think about it, it’s probably not a very good idea: imagine the amount of one-off TOs you might end up with in your repository.

---

<div class="post-metadata">

**Author:** ![Trong\_Bui](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/trong_bui/32/374_2.png) [@Trong\_Bui](https://forum.katalon.com/u/Trong_Bui)\
**Post date:** [April 19, 2018, 8:18am UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/6 "2018-04-19T08:18:31Z")

</div>

Personally, I agree with Russ on this issue. If the TestObject can be created physically, any mistake from the test script will destroy the project with hundreds of unexpected objects.

---

<div class="post-metadata">

**Author:** ![saish](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@saish](https://forum.katalon.com/u/saish)\
**Post date:** [May 18, 2018, 10:29am UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/7 "2018-05-18T10:29:33Z")

</div>

> [Russ Thomas](https://forum.katalon.com/profile/4015/Russ%20Thomas) said:
> 
> Hi Indurajan
> 
> I use this:
> 
> ```auto
> /**
> 
> ```

- Construct a Katalon-compatible TestObject in memory.
- @param css (String) The CSS selector used to find the target element.
- @return (TestObject) The constructed TestObject.  
\*/  
static TestObject makeTO(String css) {  
TestObject to = new TestObject()  
to.addProperty(“css”, ConditionType.EQUALS, css)  
return to  
}

> ```auto
> 
>   
> 
>   
> 
> ```

Hi Russ Thomas,

How to set Shadow Root Parent to this object?

---

<div class="post-metadata">

**Author:** ![Adnan\_shafiq](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Adnan\_shafiq](https://forum.katalon.com/u/Adnan_shafiq)\
**Post date:** [January 1, 2019, 2:14pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/8 "2019-01-01T14:14:08Z")

</div>

Does this have to be a css selector? I mean can’t we us xpath or id or name?

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [January 1, 2019, 3:20pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/9 "2019-01-01T15:20:56Z")

</div>

> [@saish](#):
>
> to.addProperty(“css”, ConditionType.EQUALS, css)

Just replace “css” string with any other property.

---

<div class="post-metadata">

**Author:** ![m.sivakrishna](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@m.sivakrishna](https://forum.katalon.com/u/m.sivakrishna)\
**Post date:** [March 17, 2020, 2:54pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/10 "2020-03-17T14:54:51Z")

</div>

Hi Team,

I would like to know one thing on Objects identification side.  
I have added one object to repository once and after few days, developer changed DOM structure(lets assume) then, will katalon studio repository will automatically create new xpath and continue my test or it will fail due to object issue.  
What I would like to know is , will Katalon create multiple xpaths for one HTML clode and store in repository or only one

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [March 17, 2020, 4:37pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/11 "2020-03-17T16:37:41Z")

</div>

Hi @m.sivakrishna

Katalon generates multiple XPaths for you. If you take a look at any Test Object in the Object Repository and switch to XPath tab you would see multiple locators there. However only one locator (the **Selected Locator** ) will be chosen to locate the element at run-time.

For an auto healing effect (trying multiple locators when the selected locator) fails, please consider subscribe to a KSE license.

---

<div class="post-metadata">

**Author:** ![m.sivakrishna](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@m.sivakrishna](https://forum.katalon.com/u/m.sivakrishna)\
**Post date:** [March 17, 2020, 4:50pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/12 "2020-03-17T16:50:51Z")

</div>

Thanks for your quick reply. Soon we are going to buy the full version…

Can Katalon iterate and select the locator which is working during run time ?

For first run one locator is selected and locator is worked fine  
For second run(same tc) selected locator is not working as dom is changed.

So now, will katalon iterate the rest of the locators(xpaths lets assume) and verify if they are working or not.  
Or do we need to manually change the xpaths in the selected area of object repository as we can see

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [March 17, 2020, 5:26pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/13 "2020-03-17T17:26:06Z")

</div>

Hi @m.sivakrishna

The Auto Healing plugin which is available in the Enterprise version enables test execution to continue by attempting to find a working locators from the set of locators in a Test Object. I think it is what you’re looking for.

---

<div class="post-metadata">

**Author:** ![m.sivakrishna](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@m.sivakrishna](https://forum.katalon.com/u/m.sivakrishna)\
**Post date:** [March 17, 2020, 7:11pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/14 "2020-03-17T19:11:12Z")

</div>

Yes, Thanks for your reply. If you can show us an example or working model for this we can show client to get license

---

<div class="post-metadata">

**Author:** ![joseph.dique01](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/joseph.dique01/32/16103_2.png) [@joseph.dique01](https://forum.katalon.com/u/joseph.dique01)\
**Post date:** [May 18, 2021, 6:06am UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/15 "2021-05-18T06:06:07Z")

</div>

Hi Russ Thomas,

Could you provide a sample code where your created method is used? I’m just new to using Katalon Studio. Hoping for your response. Thanks

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 18, 2021, 12:03pm UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/17 "2021-05-18T12:03:39Z")

</div>

A sample Test Case that creates a TestObject runtime

```auto
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

def createTestObjectByXPath(id, xpath) {
	TestObject tObj = new TestObject(id)
	tObj.addProperty('xpath', ConditionType.EQUALS, xpath)
	return tObj	
}

WebUI.openBrowser('')
WebUI.navigateToUrl("http://demoaut.katalon.com/")

TestObject tObj = createTestObjectByXPath("a_Make Appointment", "//a[contains(., 'Make Appointment')]")

WebUI.verifyElementPresent(tObj, 5, FailureHandling.STOP_ON_FAILURE)
WebUI.closeBrowser()

```

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 18, 2022, 11:45am UTC](https://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/18 "2022-08-18T11:45:08Z")

</div>

Closed on August 18, 2022, 11:45am UTC


