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 {
            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.''(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.

If you’ve come as an elf, see it through as an elf.

Author Signature for Posts