Squish tip of the week: How to determine all child objects of a given type

Squish tip of the week: How to determine all child objects of a given type

Need to know the number of check boxes, rows or items associated with a particular parent object?
Perhaps each child object containing a specific flag holds valuable information.

You can tell Squish to find all the parent object’s children, and only the children of a given type.

Here’s how:

Using Squish’s object.children() function, you can retrieve all child objects of a given parent. Further examining each child object by className, id or another attribute, can tell you more about each child object.

In the following example, a list of child objects, containing a specific className and with a maximum quantity retrieval of 1000 items, returns all matching child objects. The filtered list of child objects can be used as a key driving mechanism in other test cases.

def getChildrenOfType(parent, typename, depth=1000):
  children = []   for child in object.children(parent):
    if className(child) == typename:
     children.append(child)
    if depth:
     children.extend(getChildrenOfType(child, typename, depth - 1))
  return children

Click here to learn more about finding and using child objects