Tutorial: Learning to Create Java Custom Toolkit Support > Learning to Support a Simple Control > Creating a New UFT Custom Support Class

Creating a New UFT Custom Support Class

In this section you create a custom support class for the ImageButton control, as part of the ImageControls toolkit support. To do this, you use one of the wizards provided by the UFT Java Add-in Extensibility plug-in in Eclipse. The details you specify in each wizard screen reflect the decisions you made when planning the custom support. In the subsequent sections you implement the methods that the wizard creates in this class.

Note: The following sections describe only the options in the wizard screens that are relevant to this lesson. For a complete description of all options available in the wizard screens, see Using the UFT Java Add-in Extensibility Eclipse Plug-In.

  1. Open the New UFT Custom Support Class wizard.

    1. In the Eclipse Package Explorer tab, select the new UFT Java Add-in Extensibility project, ImageControlsSupport. Select File > New > Other. The New dialog box opens.

    2. Expand the Unified Functional Testing folder and select UFT Custom Support Class.

    3. Click Next. The Custom Class Selection screen opens.

  2. Select the custom class to support, and set the options for the support class.

    1. Expand the com.demo package and select the ImageButton class.

      In the Custom toolkit tree pane, you can see the structure of the ImageControls project, which you selected for the custom toolkit class location, in Creating a New UFT Java Add-in Extensibility Project. The com.demo package contains the ImageControls custom toolkit, with its custom classes, as described in Preparing for This Lesson.

      Note: The com.sample package is included in the ImageControls sample project, only to provide convenient access for running the sample application. The main content of the ImageControls project is the ImageControls custom toolkit, contained in com.demo package.

      In the Custom class inheritance hierarchy pane, you can see the hierarchy of the ImageButton class you have selected. It extends the ImageControl class, which is part of the same toolkit, and is therefore shown in black.

      The ImageControl custom class is not supported, but the Canvas class does have a matching support class, provided in the com.mercury.ftjadin.support.awt.cs package. Therefore the Base support class for the ImageButton support class you are creating is CanvasCS. This is the class that your new support class extends.

      The Controls of this class represent top-level objects option is disabled because the ImageButton class is not a container class.

      The name for the ImageButton support class is, by default, ImageButtonCS. It is recommended to keep the default name.

    2. Click Next. The Test Object Class Selection screen opens.

  3. Select a test object class to represent the custom control.

    In this screen, you map the custom control to a test object class. In UFT tests, the custom class controls are represented by test objects of this test object class. This is the first and most important decision you make when creating a custom support class.

    In the previous screen, you determined the support class that the new support class extends. When the test object mapped to the class whose support you are extending is also a logical test object for the custom class, you select Same as base support class. The ImageButtonCS class extends CanvasCS, whose test object class does not adequately represent ImageButton controls.

    The existing JavaButton test object does answer the needs of your custom support.

    1. Select the Existing test object class option and select JavaButton from the list. The list of existing test objects contains all of the Java objects that UFT currently supports. If you define new test objects for custom support, they are included in the list as well.

    2. Click Next. The Custom Support Test Object Identification Properties screen opens.

  4. Determine the set of test object identification properties to implement in ImageButtonCS.

    This screen displays the identification properties supported by the base support class you are extending, as well as additional properties that are defined in the test object class you selected, but are not yet supported. It enables you to select properties whose support you want to implement or override with new functionality and to add new properties.

    The left pane shows all of the identification properties whose support is implemented by CanvasCS, and therefore inherited by the new ImageButtonCS support class. For most of the properties in this list, the default implementation is sufficient.

    1. Select the label property by clicking the check box. After you finish generating the support files using the wizard, you will override the existing support for this property with a custom implementation that matches the needs of the custom control.

    2. Click Next. The Custom Support Test Object Methods screen opens.

  5. Determine the set of test object methods to implement in ImageButtonCS.

    This screen displays the test object methods defined in the test object class you selected. It enables you to select methods whose support you want to implement or override with new functionality and to add new methods.

    The left pane shows all of the test object methods (defined in the test object class you selected) whose support is implemented by CanvasCS, and therefore inherited by ImageButtonCS. This existing implementation is sufficient for ImageButton so there is no need to select any methods to override.

    In the right pane, you can see the test object methods that are defined for the JavaButton test object class, but are not supported by CanvasCS.

    1. Note that there is only one such method—Click(Object obj, String button). After you finish generating the support files using the wizard, you will implement the ImageButton support for this method.

    2. Click Next. The Custom Control Recording Support wizard screen opens.

  6. Determine the set of events for which to listen, to support recording on the ImageButton control.

    This screen displays the event listeners implemented by the support class you are extending. It enables you to select event handler methods whose implementation you want to override with new functionality and to add new event listeners to implement.

    In the left pane, you can see the listeners implemented by CanvasCS. You do not have to override any of these for the ImageButtonCS custom support class.

    In the right pane, you specify the listeners you want to add for ImageButtonCS. Each listener you select implies a set of event handler methods that the wizard adds to the support class.

    Perform the following:

    1. Click Add to add the ActionListener.

      The Listener dialog box opens.

    2. If it is not already selected, select java.awt.event.ActionListener from the Listener list. If the selected listener had more than one registration method, you would also select a method from the Registration method list.

    3. Click OK. The Listener dialog box closes and the ActionListener, and all of the event handler methods it includes, are added to the list in the right pane of the wizard screen.

    4. On the Custom Control Recording Support screen, select the Override low-level mouse event recording check box to prevent low-level events (coordinate-based operations) from being recorded instead of the events you want to record. For more details on this option, see Understanding Event Recording Support.

    5. Click Finish. The Custom Control Support Class Summary screen opens.

  7. View the custom control support class summary.

    Review the planned content of the custom support class, and click OK.

    The following changes are made in the ImageControlsSupport project:

    • A new UFT custom support class, ImageButtonCS, is created in the com.mercury.ftjadin.qtsupport.imagecontrols.cs package. The file is opened and displayed in a tab in the right pane.

    • A new ImageControlsTestObjects.xml file is created in the Configuration\TestObjects folder.

    • The ImageControls.xml file is modified.

    For a detailed explanation of these changes, see Understanding the New Custom Support.

    The asterisk (*) next to the ImageButtonCS file name (in the ImageButtonCS tab) indicates that it has not been saved. The changes made by the wizard are codependent, and must be saved to prevent discrepancies. Select File > Save, or click the Save button.