Stage 5: Implementing a Filter to Prevent Learning Child Objects

In this section, you create a filter to prevent UFT 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:

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

    This instructs UFT 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 for testing, or you can modify <UFT installation folder>\dat\Extensibility\Web\Toolkits\WebExtSample\.xml directly.

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

    // Learn filtering
    // This function instructs UFT 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).