Extending an Existing Test Object Class

This topic explains how to use Web Add-in Extensibility to extend support for a control that is partially supported by UFT One.

Extend Support for a Partially Supported Control

If there is an existing test object class that provides partial support for your control, but needs some modification, for example, a different naming convention for test objects in the class, or additional or modified test object methods, you create a new test object class to represent the control. When you create the new test object class, you base this test object class on the existing test object class, inheriting all of its test object methods.

You can then extend the functionality of this test object class by defining and implementing additional test object methods and identification properties. In addition, you can override existing test object methods by providing an alternate implementation for them. You define the new or changed methods and properties in the test object configuration file, and design their implementation using JavaScript functions.

To extend an existing test object class, you define the name of the base test object class in the ClassInfo\BaseClassInfoName attribute in the ClassInfo element for the new test object class in the test object configuration file. This declares that the new test object class supports all of the test object methods of the base test object class in addition to any that you define for the new test object class.

Back to top

How to Choose a Base Class

When you choose a test object class to extend consider the following:

  • Your test object class inherits the operation definitions from the test object class. Choose a test object class with a set of operations functionally relevant for your control.

  • To inherit the implementation for the base class operations, your control must include an element of the type that matches the base test object class.

Back to top

How to Make Sure That All Methods and Properties Are Implemented

You must ensure that all of the inherited test object methods are implemented and not only declared. One way to do this is to write JavaScript functions to support each inherited test object method. Another, simpler way is to ensure that the control includes an element of the type that matches the base test object class. This element is referred to as the base element. UFT One can then use its internal implementation for the inherited test object methods that you do not specifically implement for the custom control, communicating with the base element.

In addition, if the control includes a base element, UFT One uses the base test object class implementation to retrieve the identification property values when the following conditions are met:

  • In the test object configuration file, you defined identification properties for the new test object class with the same names as properties of the base test object class.

  • You do not implement a JavaScript function that retrieves the values for those properties.

Back to top

When You Need to Return a Base Element to UFT One

If the base element is the root element of the control that you are supporting, UFT One recognizes the base element and uses the base test class implementation for test object methods and identification properties that you do not implement.

If the base element is not the root element of the control, you must write a JavaScript function that returns this base element to UFT One, and specify the name and location of the JavaScript function in the toolkit configuration file. You specify this information in the Control\Settings element in the toolkit configuration file. For example, if your control is a special kind of table, and is defined as a DIV element (which UFT One normally ignores) that contains a table element (which UFT One normally represents with a WebTable element), you can create a MyWebTable test object class that extends WebTable and map the DIV element to this the MyWebTable test object class.

To return the base element, you implement a JavaScript function named get_base_table in a file named HPTable.js. In the toolkit configuration Settings element for the MyWebTable Control element, you define the func_to_get_base_elem as follows:

<Control TestObjectClass=MyWebTable>
    <Settings>
        <variable name="default_imp_file " value="HPTable.js"/>
        <variable name="func_to_get_base_elem" value="get_base_table"/>
    </Settings>
</Control>

Back to top

Extending Support for Table Objects

If you have a table object in which the table structure is more than a simple WebTable with the <table> tag, you may need additional functions to recognize objects or data from within the table. For example, in some tables, each row may have its own <table> tag. In this case, you must define a function to retrieve the data from the table (usually in the Javascript file for the table object). Then in your toolkit XML file, you add one of the following functions:

  • func_to_get_table_data: Enables you to retrieve an array of table information. This function returns a two-part array. The first part of the array returns the table column strings and the second returns the contents of the rows in the table.
  • func_to_get_cell_elem: Enables you to retrieve data from a specific cell.

These functions are set in the <Settings> section of the Control element in the toolkit configuration file. For details on these functions, see the Web Add-in Extensibility Toolkit Configuration Schema Help.

Back to top

Updating Support if the Object Changes

If you have an object that you update - for example, if it was previously recognized as a WebElement but now you changed it to be recognized as a MyToolkitElement - you can instruct UFT One how to recognize this object in previous test that still use the old object name/type.

In the Settings Element, you add a line with the "other supported types" attribute and then name the previously supported types in the value. This enables UFT One to find the object in its current representation as well as previous ones.

For example:

<Control TestObjectClass=MyWebTable>
    <Settings>
        <variable name="default_imp_file " value="HPTable.js"/>
        <variable name="func_to_get_base_elem" value="get_base_table"/>
	 <variable name="other supported types" value="WebTable"/>
    </Settings>
</Control>

Back to top