Stage 3: Implementing Support for the WebExtUsedBooks Test Object Methods

In the test object configuration file you defined the test object methods available for WebExtUsedBooks test objects. For UFT One to run these test object methods, the methods must actually be implemented.

You must provide implementation for different types of test object methods.

Implementing Test Object Methods Inherited from WebTable

In the test object configuration file, you defined that the WebExtUsedBooks test object class extends the base class WebTable. For the inherited WebTable test object methods that you do not override, UFT One can use its internal implementation by interacting with the table base element defined within the UsedBooks control. Because the table element is not the root level of the UsedBooks control, you must inform UFT One that the table element is the base element. To do this you must write a JavaScript function that returns the base element, and specify its name in the toolkit configuration file.

To instruct UFT One to use the table Web element as the base element:

  1. In the WebExtSample.xml file, within the Settings element that you defined in the Control element for the WebExtUsedBooks test object class, add the following Variable element:

    <Control TestObjectClass="WebExtUsedBooks">
        <Settings>
            <variable name="func_to_get_base_elem" value="GetTableElem"/>
        </Settings>
    </Control>
    

    This instructs UFT One to call a JavaScript named GetTableElem (in the file WebExtUsedBooks.js) to return the base element that supports the inherited WebTable test object methods.

  2. In the WebExtUsedBooks.js file, add the following JavaScript function:

    function GetTableElem()
    {
        // Get the <table> element (the first child of the <div> 
        // element which is the root of the UsedBooks control)
        return _elem.children[0];
    }
    

    This JavaScript function returns the table element, which is the first element within the div element that defines the UsedBooks control. This element supports the test object methods inherited from WebTable that are not implemented by WebExtUsedBooks.

    Other JavaScript functions that you write in this file can also use the GetTableElem() function to access the table element in the UsedBooks control.

Back to top

Implementing the New Test Object Method SelectBook

To support the SelectBook test object method for the WebExtUsedBooks test object class, write the SelectBook JavaScript function in WebExtUsedBooks.js. This is the function that UFT One calls to run the SelectBook test object method. It simulates selecting the radio button for the specified book, and clicking Select.

Add the following JavaScript function to the WebExtUsedBooks.js file:

function SelectBook( BookIndex )
// Select the radio button for the specified index 
// and clicks the "Select" link.
{
    if( BookIndex > BookCount() )
        throw "Book index is out of range !"
    //Select the radio button corresponding to the specified index
    GetTableElem().rows[1+BookIndex].cells[0].children[0].click();
    //Click the "Select" link (the 3rd child of the <div> element)
    _elem.children[2].click();
    //Add a log message to the event log to assist in debugging
    _util.LogLine("Book Selected",1);
}

Back to top

Overriding the Implementation of the Inherited Test Object Method RowCount

  1. In the WebExtSample.xml file, add the following Run element within the Control element that defines the WebExtUsedBooks support.

    <Run>
        <Methods>
            <Method name="RowCount" type="javascript" function="BookCount" />
        </Methods>
    </Run>
    

    This defines that the RowCount test object method is implemented by the JavaScript function BookCount.

  2. In the WebExtUsedBooks.js file, add the BookCount JavaScript function, which decreases the row count of the UsedBooks control, to return the number of books in the table:

    function BookCount()
    // This function overrides the RowCount test object method 
    // inherited from WebTable, so that it counts only book rows.
    {
        var table = GetTableElem();
        if( table.rows.length < 2 )
            return 0;
        return table.rows.length - 2;
    }
    

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

Back to top