Passing Katalon Objects with Parameters to Custom Keywords
Here is a situation I ran into yesterday with the project I'm currently putting together. After doing a search, I need to check the number of results returned before I read any values from the table. In this instance, the table does not appear if there are no results. So what I need to do is check for the existence of the table.
Within Katalon itself, the definition I use refers to a row and column of the table:
'Business Locations/table-Business Locations', [('row') : 2, ('column') : 2]))
This works fine and I can read any of the cells I need. I can also reference this within the test itself using the familiar WebUI.getText(findTestObject('Business Locations/table-Business Locations', [('row') : 2, ('column') : 2]))
Since all the tables work the same way, I set about making a Custom Keyword, to perform this action across the site. The problem comes in when I need to pass that object to the Custom Keyword.
By default, the parameter was a String. When this is done, Katalon tries to look for an object with the name you pass. In this case, the Row and Column parameters are considered part of the name, and that object doesn't exist.
After going around in circles of sending a String when I needed an Object, and getting an Object that didn't exist, I find the correct combination.
My Custom Keyword needs to accept TestObject
as a type AND I need to resolve the Object in the call to the Custom Keyword.
The Custom Keyword looks like this:
boolean verifyObjectPresent(TestObject objectReference) {
try {
WebUiCommonHelper.findWebElement(objectReference,2)
return true;
} catch (Exception e) {
return false;
}
}
Note the TestObject
as the Type.
The object and parameters need to be resolved, then passed using the following call to the Keyword:
boolean elementVisible=CustomKeywords.'commonCode.tools.verifyObjectPresent'(findTestObject('Business Locations/table-Business Locations', [('row') : 2, ('column') : 2]))
Note the findTestObject
before the object I need to pass. This correctly passes the object with the parameters. The Keyword is now set up to handle an Object, not a String, and can find the Object in the Object Repository. The object is then currently identified as Present or not depending on whether or not I get results.
Other articles of interest:
- Creating and Calling Methods for Test Cases in Katalon Studio
- Get the xpath of an object in the Object Repository using findPropertyValue(‘xpath’)
- Selenium based Custom Keyword to Count Table Rows in Katalon Studio
- Checking for the presence of an object without throwing an error
- A Custom Keyword to Verify a List of Product Categories
- Passing Object Names as String Variables in Katalon Studio
- Create a Dynamic Object at Runtime
- To markFailedAndStop or Not To markFailedAndStop?
- How to get the URL of an image/icon with Katalon
- What’s in a Method?
Leave a Reply