Stage 8: Implementing Support for Recording on the Book Control

By this point in the tutorial, your toolkit support set already enables full OpenText Functional Testing functionality. OpenText Functional Testing recognizes the Book control, can learn it and can run tests on it.

An additional, optional way to create tests in OpenText Functional Testing is by recording operations that a user performs on the application. As you can see in Planning Support for the Book Sample Toolkit, by default OpenText Functional Testing records plain Click operations on the various Web link and image objects within the Book control. It would be more helpful to record Select, GoToAuthorPage, and GoToUsedBooksPage operations on the Book control itself, in response to those same clicks.

To support customized recording on your control, you must instruct OpenText Functional Testing to listen to the relevant events and inform OpenText Functional Testing what test steps to record in response to each event.

To do this you write two types of JavaScript functions:

  • One JavaScript function that uses the RegisterForEvent function in the _util utility object that OpenText Functional Testing exposes in the Web Add-in Extensibility SDK to register for listening to the correct events on the correct elements. The arguments of this function also determine what JavaScript functions OpenText Functional Testing calls when each event occurs.

    In the toolkit configuration file, you specify the name and, optionally, the location of this JavaScript function.

  • One or more JavaScript functions that handle the events by calling the Record function in the _util utility object to inform OpenText Functional Testing what step to add to the test.

    Note: The Record function, and other utility object functions, require a SafeArray type argument. To convert an array to a SafeArray, you can use the toSafeArray (array) function that Web Add-in Extensibility provides. This function is defined in <Extensibility_Accelerator_installdir>\bin\PackagesToLoad\common.js. (This file is also located in the <OpenText Functional Testing installdir>\dat\Extensibility\Web\Toolkits folder.)

For information on the syntax of the utility object functions, see the _util section in the API Reference.

To develop support for recording on the Book control:

Note: You can modify the WebExtSample.xml and WebExtBook.js files in the toolkit support set folder and then later deploy them to OpenText Functional Testing for testing, or you can modify these files in <OpenText Functional Testing installdir>\dat\Extensibility\Web\Toolkits\WebExtSample directly.

  1. In the toolkit configuration file, within the Control element add the following Record\EventListening element:

    <Record>
        <EventListening use_default_event_handling_for_children="false" 
                        use_default_event_handling="false" 
                        type="javascript" 
                        function="ListenToEvents"/>
    </Record>
    

    This instructs OpenText Functional Testing not to use the default Web Event Configuration for handling events on the Book control and its children, but to call the JavaScript function ListenToEvents. Because you did not specify a JavaScript file, OpenText Functional Testing looks for the JavaScript function in the WebExtBook.js file that you specified at the Control level for the WebExtBook test object class.

  2. In the WebExtBook.js file, add the following ListenToEvents function:

    function ListenToEvents( elem )
    {
        // Connect to the "Select" event: When the book name or the 
        // book icon is clicked, call OnSelectClicked.
        _util.RegisterForEvent( _elem.rows[0].cells[0].children[0], "onclick", "OnSelectClicked");
        _util.RegisterForEvent( _elem.rows[0].cells[1].children[0], "onclick", "OnSelectClicked" );
        // Connect to the "Author" event: When an author name is 
        // clicked, call OnAuthorClicked.
        for( var i = 0 ; i < _elem.rows[1].cells[0].children.length ; ++i )
        {
            if( _elem.rows[1].cells[0].children[i].tagName == "A" )
            {
                _util.RegisterForEvent( _elem.rows[1].cells[0].children[i], "onclick", "OnAuthorClicked" );
            }
        }
        // Connect to the "UsedBooks" event: When "Used" is 
        // clicked, call OnUsedBooksClicked.
        if(  _elem.rows[3].cells[0].children.length > 1 )
            _util.RegisterForEvent( _elem.rows[3].cells[0].children[1], "onclick", "OnUsedBooksClicked" );
        return true;
    }
    

    This function registers OpenText Functional Testing to listen to click events on the book's title, image, and authors, and on the Used link. When registering for an event, this function specifies what JavaScript function OpenText Functional Testing must call when the event occurs.

  3. In the WebExtBook.js file add the following event handler JavaScript functions:

    function OnSelectClicked( handlerParam , eventObj )
    {
        // Record the "Select" step
        var arr = new Array();
        _util.Record( "Select", toSafeArray(arr) , 0 );
        return true;
    }
    
    function OnAuthorClicked( handlerParam , eventObj )
    {
        // Record the "GoToAuthorPage" step
        var arr = new Array();
        arr[0] = eventObj.srcElement.innerText; 
        _util.Record( "GoToAuthorPage", toSafeArray(arr) , 0 );
        return true;
    }
    
    function OnUsedBooksClicked( handlerParam , eventObj )
    {
        // Record the "GoToUsedBooksPage" step
        var arr = new Array();
        _util.Record( "GoToUsedBooksPage", toSafeArray(arr) , 0 );
        return true;
    }

    These functions record Select, GoToAuthorPage, and GoToUsedBooksPage on the WebExtBook test object, as planned in Planning Support for the Book Sample Toolkit.

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