Stage 7: Implement Support for the Identification Properties

In this section you implement support for retrieving the values of identification properties during a test run. UFT One uses identification property run-time values in different standard test object methods, such as GetROProperty. Identification property run-time values are also required for different basic capabilities, such as creating checkpoints and outputting values.

The WebExtBook's identification properties you support are: title, price, min_used_price, and authors. You do not have to implement support for html tag and html id, as this implementation is inherited from WebElement.

In addition, you provide a means for retrieving a value for the logical_name property. This is a property that UFT One uses internally, when creating a test object, to determine the name for the test object. By customizing the value of this property, you instruct UFT One to name the WebExtBook test object according to its title.

If the get_property_value function does not support the logical_name property, the test object is given the name of the test object class (followed by an index, if there is more than one object of the same test object class on the same page).

To support retrieving the run-time values of the WebExtBook's identification properties:

It is possible to specify a JavaScript file and function name for the retrieval of the test object's identification properties. However, in this lesson, you develop your support in the default file and function. Extensibility Accelerator created a stub for the function, with sections to implement for each property you defined.

  1. In the Properties tab in the test object designer, select a property and click the Implementation Code button in the Properties toolbar.

    The WebExtBook.js file opens in a JavaScript Editor. The cursor is placed in the stub provided for the get_property_value function, at the beginning of the section designed to retrieve the selected property's value.

  2. In the get_property_value function, locate the code snippet intended for each of the following properties and edit it to retrieve the property value based on the code below: logical_name, title, price, min_used_price, and authors.

    Alternatively, replace the whole get_property_value function with this implementation:

    function get_property_value(prop)
        if ( prop == "logical_name" || prop == "title" )
        // For the "title" identification property, as well as the
        // "logical_name" property, return the inner text of the
        // second cell in the first row.
            return _elem.rows[0].cells[1].innerText;
        if ( prop == "authors" )
        // To return a list of all the authors, look for all the 
        // children of the first cell in the second row.
            var BookAuthors = "";
            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" )
                    if( AuthorsCount > 0 )
                        BookAuthors += ",";
                    BookAuthors += _elem.rows[1].cells[0].children[i].innerText;
            return BookAuthors;
        if ( prop == "price" )
        // To return the price of the book, return the innerText 
        // property of the first cell in the fourth row.
            return _elem.rows[3].cells[0].children[0].innerText;
        if ( prop == "min_used_price" )
        // To return the lowest price available for a used copy of 
        // the book, return the innerText property of the second 
        // child of the first cell in the fourth row.
            if( _elem.rows[3].cells[0].children.length > 2 )
                return _elem.rows[3].cells[0].children[2].innerText;

Continue to Stage 8: Test and Debug the Support You Designed for the Identification Properties.