Add a scope to findTestObject method


#1

It would be very helpful to give the ability to search for a TestObject inside the scope of another TestObject.

Method :
findTestObject(String testObjectRelativeId)
findTestObject(String testObjectRelativeId, Map variables)
findTestObject(String testObjectRelativeId, Map variables, TestObject scope )

This will be very helpful for maintenance to avoid having multiple parametered test-objects for components with inputs like these (pseudo-code from angular) :

 <custom-component>
     <div id='123456789'>
         <form>
             <input ng-reflect-name='field1' />
             <input ng-reflect-name='field2' />
             <input ng-reflect-name='field3' />
             <input ng-reflect-name='field4' />
             <input ng-reflect-name='field5' />
              ...
         </form>
     </div>
 </custom-component>
 <custom-component>
     <div id='222222222'>
         <form>
             <input ng-reflect-name='field1' />
             <input ng-reflect-name='field2' />
             <input ng-reflect-name='field3' />
             <input ng-reflect-name='field4' />
             <input ng-reflect-name='field5' />
          ...
         </form>
     </div>
 </custom-component>

Currently, I need to specify each TestObject with xpath for exemple //custom-component/div[@id=’${id}’]/form/input[@ng-reflect-name=‘field…’], and call each time findTestObject with variables.

This would be a prettier solution and I’m sure there are others use cases.

Thank you in advance.


#2

The findTestObject() family of methods actually doesn’t know anything about the DOM. All it’s doing is grabbing Test Objects from the Object Repository, just like you would grab a file from any file system. It’s not until you use methods in the WebUI or WebUiCommonHelper classes that any actual reference to the DOM is made, and the elements defined by your Test Objects are actually located. Therefore, asking for the findTestObject() methods to know anything about the scope of the elements in the DOM isn’t going to work.

However, you can always do this kind of thing yourself within Selenium like so:

TestObject parentObject = ObjectRepository.findTestObject("path/to/my/object");
WebElement parentElement = WebUiCommonHelper.findWebElement(parentObject, 30);
WebElement childElement = parentElement.findElement(By.xpath(".//some//child"));

The “childElement” is located relative to (i.e. within the scope of) “parentElement” in this example.


#3

It’s certainly possible for the Katalon code to be extended in this way but I doubt it would ever happen due to:

  1. The limited use case and limited target audience (just my guess, I could be wrong. Votes will prove the case one way or the other).

  2. The sheer amount of behind-the-scenes work necessary. The DOM beginning at the scope (i.e. parent) object would need to be “realized” and then the search carried out and then the result returned. Sounds extraordinarily messy to me (and maybe error prone, too).

  3. It’s not what the OR is for (as pointed out by Brandon).

  4. The OR is meant to be (or, at least, designed to be) “static”. The DOM is by nature dynamic. “Here be dragons” methinks.

Far better (and easier) in my view, would be to ditch the OR methods and use the DOM’s native interface method element.querySelector in JavaScript (or jQuery’s scoped selectors). But that’s just me… Although, I’m not sure how that would work with data driven test code (not my forte). I could be way off target here!

Good luck!