Stage 9: Implementing Support for Dynamic List of Values for AuthorName

Using Web Add-in Extensibility, you can provide the UFT user a list of possible values to use for a test object method argument, based on the run-time values of the specific control. For example, the GoToAuthorPage test object method of the WebExtBook test object class receives an AuthorName argument. It is easier for the UFT users if they can select an author name from a list of possibilities instead of typing the name. However, this list is different for each WebExtBook control.

In the test object configuration file, you defined the DynamicListOfValues attribute for the AuthorName argument as true, instructing UFT to request the list of possible values from the control when creating a test step.

In the toolkit configuration file, you can specify the file name and function name of the JavaScript function that UFT must call to retrieve the list of values. By default, UFT requests the list of values by calling the get_list_of_values JavaScript function from the WebExtBook.js file that you specified at the Control level for the WebExtBook test object class. UFT calls the JavaScript function for every argument whose DynamicListOfValues attribute is set to true in the test object configuration file. The parameters provided to this function indicate the test object method and argument for which the values are being requested.

In this section, you implement the get_list_of_values JavaScript function, to return the author names from the Book control.

To provide a dynamic list of values for the AuthorName argument in the GoToAuthorPage test object method:

In the WebExtBook.js file add the JavaScript functions:

// Dynamic list of values implementation
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function get_list_of_values( method, argIndex )
{
    // When creating a step with the GoToAuthorPage test 
    // object method, provide a list of the authors of this book
    // that can be used for the method's argument.
    if (method == "GoToAuthorPage")
    {
        return get_GoToAuthorPage_list_of_values(argIndex);
    }
    return null;
}
function get_GoToAuthorPage_list_of_values(argIndex)
{
    var arr = new Array();
    if( argIndex > 1 )
        return toSafeArray(arr);
    // Retrieve all authors
    var AuthorsCount = 0;
    for( var i = 0 ; i < _elem.rows[1].cells[0].children.length ; ++i )
    {
        if( _elem.rows[1].cells[0].children[i].tagName == "A" )
        {
            arr[AuthorsCount]="\""+_elem.rows[1].cells[0].children[i].innerText+"\"";
            AuthorsCount++;
        }
    }
    return toSafeArray(arr);
}

This returns a list of the book's authors, each enclosed in quotation marks.

The Book custom control is now fully supported, according to the specifications you decided on when planning your custom support.

Note: You can modify the WebExtSample.xml file in the toolkit support set folder and then later deploy it to UFT for testing, or you can modify <UFT installation folder>\dat\Extensibility\Web\Toolkits\WebExtSample\.xml directly.

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