Creation of Test Object in Object Repository in Runtime

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.

Hi Indurajan

I use this:

  /**
   * 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
  }

4 Likes

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

Hi Russ,
Code worked for me . thanks for the inputs :slight_smile: .

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.

3 Likes

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.

Russ Thomas said:

Hi Indurajan

I use this:

  /**
  • 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
    }

  

  

Hi Russ Thomas,

How to set Shadow Root Parent to this object?

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

Just replace “css” string with any other property.

1 Like

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

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.

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

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.

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

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

A sample Test Case that creates a TestObject runtime

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()