Implementing Support for Recording

One way to add objects to the object repository and create tests in UFT One is by recording. To record a test, UFT One registers to listen to events on the Web elements, and, when an event occurs, UFT One adds the relevant step to the test. By default, UFT One uses the standard Web event configuration to determine the events to which to listen for each Web element, and the steps to record in the test when each event occurs.

If you want to customize recording on a test object class that you defined, you must specify the events that you want to record and the steps that you want UFT One to add to the test when those events occur.

For each test object class on which you want to customize recording, define a Control\Record\EventListening element in the toolkit configuration file. In this element you can specify whether to use standard Web event configuration to handle events on controls represented by this test object class. In addition, you can specify whether to use standard Web event configuration to handle events that take place on those control’s children.

In addition to specifying whether UFT One should use standard Web event configuration, you can specify a JavaScript function that provides more specific event registration (and optionally, the name of the file containing the function). For more information, see the Toolkit Configuration Schema Help.

In addition to the definitions in the toolkit configuration file, you write the following types of JavaScript functions:

  • One JavaScript function (named in the toolkit configuration file) that uses the RegisterForEvent function in the _util utility object to register for listening to the correct events on the correct elements. The arguments of this function also determine what JavaScript functions UFT One calls when each event occurs.

    UFT One calls this function after registering to listen to events according to the standard Web event configuration. The event registration performed by this function overrides any previous registrations for the same events. For events not handled by this function the standard registration is used.

  • One or more JavaScript functions that handle the events, when they occur, by calling the Record function in the _util utility object to inform UFT One what step to add to the test.

    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 <UFT_One_installdir>\dat\Extensibility\Web\Toolkits folder.)

For information on the syntax of the utility object functions, see the _util section in the API Reference. For more information on writing JavaScript functions for Web Add-in Extensibility, see Designing JavaScript functions for your toolkit support set.

You can see an example of customized recording in the sample toolkit support set for the WebExtSample environment located in %ALLUSERSPROFILE%\Documents\ExtAccTool\Samples\WebExtSample folder.

  • In the toolkit configuration file, within the Control element for the WebExtBook test object class, the following Record\EventListening element is defined:

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

    This instructs UFT One not to use the default Web Event Configuration for handling events on the Book control and its children, but to call the JavaScript function RegisterToEvents. A JavaScript file is not defined, therefore UFT One looks for the JavaScript function in the WebExtBook.js file that is specified at the Control level for the WebExtBook test object class.

  • In the WebExtBook.js file, the following RegisterToEvents function is defined:

    function RegisterToEvents( elem )
    {
        // Connect to the "Select" event: When the book name or the 
        // book icon is clicked, call OnSelectClicked.
        _util.RegisterForEvent( window._uft.$(_elem.rows[0].cells[0]).children[0], "onclick", "OnSelectClicked" );
        _util.RegisterForEvent( window._uft.$(_elem.rows[0].cells[0]), "onclick", "OnSelectClicked");
    }
    

    Note: The _uft.$ indicates that this code uses an isolated jQuery JavaScript function library to provide browser-independent support.

    UFT 14.50 and earlier

    If your toolkit was developed using a UFT version of 14.50 or earlier, the jQuery library is called using only $.

    If errors occur due to conflicting jQuery libraries, we recommend you upgrade your toolkit using UFT 14.51 or later.

    This function registers UFT One to listen to click events on the book's title and image. When registering for an event, this function specifies what JavaScript function UFT One must call when the event occurs.

  • 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;
    }
    

    This function records the Select test object method on the WebExtBook test object when the book title or image is clicked.

After you implement support for recording, you can record a test on controls in your environment, and verify that your toolkit support set performs correctly. For more information on testing your toolkit support set, see Testing the Toolkit Support Set During Development.