Creating Support for the ImageControl Custom Class

In this section, you create a custom support class for the ImageControl class in the ImageControlsSupport project.

  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, select UFT Custom Support Class and 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 ImageControl class:

      In the Custom toolkit tree pane, you can see that the ImageControl class is the only class in the com.demo package that is not yet supported.

      In the Custom class inheritance hierarchy pane, you can see the hierarchy of the ImageControl class you have selected. The ImageControl class extends java.awt.Canvas, therefore the Base support class for the ImageControl support class you are creating is CanvasCS.

      Leave the default name, ImageControlCS, for the ImageControl support class.

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

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

    You are creating the ImageControlCS support class only to use it as a base support class for other support classes, not to support actual controls. Therefore, it is not important to which test object class you map the ImageControl custom class.

    Perform the following:

    1. Select Same as base support class. This maps the ImageControl custom class to whichever test object class is mapped to java.awt.Canvas. No direct mapping takes place. The new support class does not implement a to_class_attr method, but inherits it from the base support class.

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

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

    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.

    The left pane displays all of the identification properties whose support is implemented by CanvasCS, and therefore inherited by the new ImageControlCS support class. It enables you to select properties whose support you want to override with new functionality.

    In the Test Object Class Selection screen, you did not select a specific test object class. Therefore, the wizard does not know which test object class is mapped to the ImageControl custom control. As a result, no identification properties are displayed in the right pane.

    1. Select the label property by clicking its 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 ImageControlCS.

    This screen displays the test object methods defined in the test object class you selected.

    In the Test Object Class Selection screen, you did not select a specific test object class. Therefore, the wizard does not know which test object class is mapped to the ImageControl custom control. As a result, no test object methods are displayed in this screen.

    1. Consider that the ImageControl custom control does not have any test object methods that need to be supported.

    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 ImageControl 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 ImageControlCS custom support class.

    1. Consider that you are creating the ImageControlCS support class only to use it as a base support class for other support classes, not to support actual controls. Therefore, it is not necessary to support recording on ImageControl controls.

    2. 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:

    • The ImageControls.xml file is modified to map the ImageControl custom class to its support class—ImageControlCS.

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

      The ImageControlCS class extends CanvasCS and contains only one method stub—label_attr.

    The asterisk (*) next to the ImageControlCS file name (in the ImageControlCS 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.

  8. Implement the label_attr method in the ImageControlCS class.

    1. In Eclipse, in the ImageControlCS.java file, in the label_attr method stub, replace return super.label_attr(obj); with the following code, so that it returns the name of the image file used for the ImageControl (without the full path):

      ImageControl ic = (ImageControl)arg0;
      String res = ic.getImageString();
      if(res == null || res.length() == 0)
              return null;
      int last = res.lastIndexOf('/');
      if(last == -1)
              return res;
      return res.substring(last+1);
      
    2. Click the Save button, or select File > Save to save your changes.