How to "test" a testobject

Hi,

it seems to me the basic in coding, but I don’t know how to do it in Katalon.

I would like to know if Katalon find an element, and if not, do other thing.

The problem is that I don’t know how to test it:

if(findTestObject(‘Duckduckgo/ClickPrimoElemento’)==true)…

but…it doesn’t work :stuck_out_tongue:

Thanks

Hi,

In if condition you need to pass an action along with the test object like

if (WebUI.getText(findTestObject(‘Duckduckgo/ClickPrimoElemento’))==‘Expected text’{

your rest of the code.

}

or

boolean x= WebUI.verifyAlertPresent(findTestObject(‘Object Repository/IC’))

if (x==true){

}

Not true actually. findTestObject() will return a TestObject if it can find it in your repository, or null if it cannot find it. Here’s a link to the source. You can see in the documentation of the method:

* @return an instance of TestObject or null if test object id is null

There are a couple of things to keep in mind here:

1.) Finding a Test Object from the repository is not the same as finding an element on the page you are testing. If you want to test if an object exists in the repository, you would do something like:

if(findTestObject('Duckduckgo/ClickPrimoElemento') != null) {
	// do something...
}
else {
    // do something else...
}

2.) If you want to see if an element exists on the page, you would need to do something like:

if(WebUI.verifyElementPresent(findTestObject('Duckduckgo/ClickPrimoElemento'), 30, FailureHandling.CONTINUE_ON_FAILURE)) {
    // do something...
}
else {
    // do something else...
}
1 Like

Your comments within the statement are mixed up…

Also not sure what ”Checkboxlist” is, but it’s not a proper object id. The argument must be a String that identifies a Test Object’s location in the repository.

1 Like

Rudra - I fixed your original post example.

It might be (and usually is) better to avoid the negatives and emphasize the positive (truthy) action:

if(findTestObject("ID From Object Repository") ) {
  // Action if test object exists
} else {
  // Action if test object does NOT exist
}