Stage 5: Implementing a Filter to Prevent Learning Child Objects

In this section, you create a filter to prevent UFT One from learning all of the UsedBooks control's children along with the control.

You implement this in the toolkit configuration file and in the JavaScript file.

To filter the children learned with the UsedBooks control:

  1. In the WebExtSample.xml file, within the Control element defined for the WebExtBook test object class, add the following Filter element:

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

    This instructs UFT One to learn WebExtUsedBooks test objects when learning their parent Web pages, and to call the JavaScript function GetChildrenToLearn to determine which children to learn. The JavaScript function returns a SafeArray of the controls descendants that should be learned with the control.

    Note: You can modify the WebExtSample.xml file in the toolkit support set folder and then later deploy it to UFT One for testing, or you can modify <UFT_One_installdir>\dat\Extensibility\Web\Toolkits\WebExtSample\.xml directly.

  2. In the WebExtUsedBooks.js file, add the following functions:

    // Learn filtering
    // This function instructs UFT One which child objects of a 
    // UsedBooksTable should be learned with the object is learned. 
    function GetChildrenToLearn()
        // Return all of the radio buttons in the UsedBooks table
        return toSafeArray(GetTableElem().getElementsByTagName("input") );

    This ensures that only the radio buttons are learned, as planned in the outset of this lesson.

To complete this stage, perform the procedures in Deploying and Testing the Toolkit Support Set (for Stage 5).