Implementing a Filter for Learning Child Controls

When you instruct UFT One to learn a Web page, the Define Object Filter dialog box opens, enabling you to determine which of the Web page's descendants should be learned with it. When you select All object types, instructing UFT One to learn the custom control with its parent Web page, all of the controls contained within your custom control are also learned as children of that Web page (and siblings of the control itself).

In some situations, there is no need to create test objects for all of the children of a control. For example, when there are no significant operations to perform on the children and no properties to retrieve, or when, for testing purposes, operations performed on the children are viewed as operations performed on the parent control. For example, on a calculator control that contains button controls, there is no need to create test objects for the digit buttons. Pressing the digit buttons performs a Set operation on the calculator object itself, providing a numeric input for a calculator operation.

You can determine which controls UFT One learns by defining a Learn Filter for the test object class you create. You can use the Control\Filter\Learn element in the toolkit configuration file to define basic filtering, or you can implement complex filters by writing a JavaScript function. If you design a filter using a JavaScript function, specify the location and name of the function in the toolkit configuration file.

In the toolkit configuration file, in the Control\Filter\Learn element, you can define:

  • Whether to learn controls represented by this test object class. You can also specify that UFT One should learn controls of this type only if they have children.

  • Whether to learn the controls contained within the controls represented by this test object class. You can also specify that your JavaScript function needs to be called to determine which descendants to learn.

    If you write a JavaScript function to implement the filter, the function must return a SafeArray containing all of the descendant Web elements that you want UFT One to learn. For more information, see Designing JavaScript functions for your toolkit support set.

For more information, see the Toolkit Configuration Schema Help.

You can see an example of defining Learn Filters in the sample toolkit support set for the WebExtSample environment located in %ALLUSERSPROFILE%\Documents\ExtAccTool\Samples\WebExtSample folder.

  • The Filter element for the WebExtBook test object class is defined (in the WebExtSample.xml file) as follows:

        <Learn learn_control="Yes" learn_children="No"/>

    This instructs UFT One to learn WebExtBook test objects without their descendants.

  • The Filter element for the WebExtUsedBooks test object class is defined as follows:

        <Learn learn_control="Yes" learn_children="CallFilterFunc" 
               type="javascript" function="GetChildrenToLearn" />

    This instructs UFT One to learn WebExtUsedBooks test objects, and to call the CallFilterFunc JavaScript function to determine which descendants to learn.

    The GetChildrenToLearn JavaScript function is located in the WebExtUsedBooks.js file, which is defined as the default implementation file in the WebExtSample.xml toolkit configuration file. The GetChildrenToLearn JavaScript function returns all of the radio button descendants of the UsedBooks table control:

    function GetChildrenToLearn()
    // Return all of the radio buttons in the used books table
    return toSafeArray(window._uft.$(_elem).children()[0].getElementsByTagName("input") );

    Note: The _uft.$ indicates that this code uses an isolated jQuery JavaScript function library to provide browser-independent support.

    UFT 14.50 and earlier

    If your toolkit was developed using a UFT version of 14.50 or earlier, the jQuery library is called using only $.

    If errors occur due to conflicting jQuery libraries, we recommend you upgrade your toolkit using UFT 14.51 or later.

After you implement a Learn Filter, you can instruct UFT One to learn your custom controls, and verify that your toolkit support set correctly controls which of the control’s children are learned. For more information on testing your toolkit support set, see Testing the Toolkit Support Set During Development.