Stage 4: Implementing Support for the WebExtBook's Test Object Methods

After enabling UFT One to recognize the custom controls, you must provide support for running test object methods. For each test object method that you defined in the test object configuration file, you must write a JavaScript function that UFT One runs to perform the step on the control.

In the toolkit configuration file, you need to specify the JavaScript file in which UFT One should look for the JavaScript functions and, optionally, the name of the function to use for each test object method.

In this section, you provide support for the WebExtBook's test object methods: Select, GoToAuthorPage (AuthorName), and GoToUsedBooksPage.

It is possible to specify a JavaScript file and function for each test object method in the toolkit configuration file. However, in this lesson, you develop support for running test object methods in the simplest way possible. At the Control element level, you define one JavaScript file that UFT One uses by default for all test objects methods defined within this element. As for the JavaScript function names, by default, searches in the specified file for a JavaScript function with the same name as the test object method. Therefore, you do not need to specify the function names in the toolkit configuration file, but only to create the JavaScript functions with the correct names.

To develop support for the WebExtBook test object methods:

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

    <Settings>
        <Variable name="default_imp_file" value="WebExtBook.js"/>
    </Settings>
    

    This instructs UFT One to search for JavaScript functions in the WebExtBook.js file (in the <UFT_One_installdir>\dat\Extensibility\Web\Toolkits\WebExtSample folder).

    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 WebExtBook.js file that you created in Stage 1: Creating the Toolkit Support Set, paste the text below to create JavaScript functions for each test object method: Select, GoToAuthorPage (AuthorName), and GoToUsedBooksPage.

    Note: The _elem object is a reserved object that UFT One uses to refer to the HTML control currently being handled.

    // Run implementation
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // This section contains the functions that carry out the 
    // test object methods.
    function Select()
    {    // Click the link in the second cell of the first row.
         _elem.rows[0].cells[1].children[0].click();
    }
    function GoToAuthorPage(AuthorName)
    {    // Look for the specified author name among the children 
         // of the first cell in the second row and click it.
         var bWasFound = false;
         for( var i = 0 ; i &lt; _elem.rows[1].cells[0].children.length ; ++i )
        {
             if( _elem.rows[1].cells[0].children[i].innerText == AuthorName )
            {
                 _elem.rows[1].cells[0].children[i].click();
                 bWasFound = true;
                 break;
            }
        }
        if( bWasFound == false )
             throw ("Author name not found !");
    }
    function GoToUsedBooksPage()
    {    // Click the link in the first cell of the third row.
         _elem.rows[3].cells[0].children[1].click();
    }
    

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