Find TestObject by script

Is there a way to obtain a TestObject object by groovy script.

I’m trying to do this by string, but I can’t find how to do this in Katalon documentation

I now I can obtain WebElement like this:

WebElement mailList = WebUiBuiltInKeywords.findWebElement(table)

But I need get a TestObject in order to execute WebUiBuiltInKeywords functions like WebUiBuiltInKeywords.mouseOver(TestObject to)

I need the same, could you solve it?

Tks Nguyen

It works well.

We need to make several tests with the same structure but changing only the TestObject, which one we will pass a string as parameter to build it.

The recommendation is build Objects only in Object Repository folder, right?

But unfortunatelly, we will need to desrespect this in some cases

In your circumstance, you could use

TestObject flexibleTestObject = new TestObject()
// need to import com.kms.katalon.core.testobject.ConditionType
flexibleTestObject.addProperty("xpath", ConditionType.EQUALS, "[your xpath here]")

Please keep in mind that we do not recommend to do so.

Hi Nguyen,

I got it, but I think I didn’t explain it well.

Look, using ObjectRepository.findTestObject(String testObjectID) I only can find an object already set in ObjectRepository, right?

So, this is not what I want. I want a script to create an TestObject at runtime passing a xpath as parameter.

I know WebElement.findElement(By.xpath(“xpath”)) returns a WebElement

I need a similar method like above but that returns a TestObject

Hi Renan Brito,

To find a Test Object, you could use ObjectRepository.findTestObject(String testObjectID) or its shorthand findTestObject(String testObjectID)

Best regards,

nta

I was able to change the Xpath value in runtime, first created one dummy Test object and during run time I am able to change xpath values which I am getting from Excel file. See screenshot for more details.

image.png

It can be done as Balraj wrote, but you dont even need excel file, just create TestObject variable and modify its proterty:

TestObject product = new TestObject()
	
	product = WebUI.modifyObjectProperty(product, 'xpath', 'equals', '//*[@id = 'something']', true)
	
	WebUI.click(product)
1 Like

Nguyen Truong An said:

In your circumstance, you could use

TestObject flexibleTestObject = new TestObject()
// need to import com.kms.katalon.core.testobject.ConditionType
flexibleTestObject.addProperty("xpath", ConditionType.EQUALS, "[your xpath here]")

Please keep in mind that we do not recommend to do so.

Why is this not recommended?

David,

That statement is safe to ignore. Pretend it’s not there.

There is nothing wrong with using a published API for the purpose it was intended.

David Barker said:

Nguyen Truong An said:

In your circumstance, you could use

TestObject flexibleTestObject = new TestObject()
// need to import com.kms.katalon.core.testobject.ConditionType
flexibleTestObject.addProperty("xpath", ConditionType.EQUALS, "[your xpath here]")

Please keep in mind that we do not recommend to do so.

Why is this not recommended?

1 Like