Stage 2: Teaching UFT to Identify, Spy, and Learn the UsedBooks Control

After you define the new test object class you must enable UFT to identify the Web controls for which to use this test object class.

As described in Planning Support for the Web Add-in Extensibility Sample UsedBooks Control, a WebExtUsedBooks test object is used to represent a control whose tagName property is div, if the tagName and className properties of the control's first child are table and UsedBooks respectively.

For the WebExtUsedBooks test object class, identification is carried out by a combination of Condition elements in the toolkit configuration file and a JavaScript function.

To define the identification rules for the WebExtUsedBooks test object class:

  1. In the WebExtSample.xml file, within the Controls element, add the following Control element for this test object type:

    <Control TestObjectClass="WebExtUsedBooks">
        <Settings>
            <variable name="default_imp_file" value="WebExtUsedBooks.js"/>
        </Settings>
        <Identification type="javascript" function="IsWebExtUsedBooks">
          <Browser name="*">
            <Conditions type="CallIDFuncIfPropMatch" logic="and">
                <Condition prop_name="tagName" expected_value="div"/>
            </Conditions>
          </Browser">
        </Identification>
    </Control>
    

    This defines that UFT will look for JavaScript functions in the file WebExtUsedBooks.js unless another file is specified. The Identification element includes one Conditions element that specifies that if the tagName property of the control being handled is div (case-insensitive compare), the JavaScript function IsWebExtUsedBooks is called to identify whether to use this test object class to represent the control.

    This tutorial uses the definition above to illustrate the use of the CallIDFuncIfPropMatch value for the Conditions element's Type attribute. However, if you were working with an application that had many controls on a page, or a large DOM structure, a better way to define these identification rules would be to use the following text:

        <Identification type="javascript" function="IsWebExtUsedBooks">
            <HTMLTags>
                <Tag name="div"/>
            </HTMLTags>
        </Identification>
    

    This provides the same functionality, instructing UFT to call the IsWebExtUsedBooks identification function only for div elements, but it provides better performance when learning custom controls and running steps on them.

  2. In the toolkit support set folder, in the Toolkits\WebExtSample folder, create a file named WebExtUsedBooks.js (This is the file for all of the JavaScript functions you design to support the UsedBooks control).

  3. In WebExtUsedBooks.js, add the following JavaScript function:

    function IsWebExtUsedBooks()
    {
        // Verify that the tagName property is "div" and the 
        // className property of the first child (a TABLE element) 
        // is "UsedBooks".
        var firstChild = _elem.children[0];
        if    ( _elem.tagName == "DIV" &&
            firstChild.tagName == "TABLE" &&
            firstChild.className == "UsedBooks" )
            return true;
        return false;    
    }
    

    This JavaScript function checks whether the control meets the conditions that determine that a control should be represented by a WebExtUsedBooks test object.

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