Changing the Name of the Test Object

In this part of the lesson, you extend UFT One support of the ImageButton control to recognize its name as per your plan (Planning Support for the ImageButton Control). To do this, you will learn about the special property methods implemented in ObjectCS: tag_attr and attached_text_attr.

The name of a test object is determined by its tag property. All AWT support classes extend ObjectCS. ObjectCS implements the tag_attr method to check a set of properties in a specified order, and return the first valid value it finds. A valid value is one that is not empty, and does not contain spaces.

In the tag_attr method in the ObjectCS class, the following properties are checked, in the order in which they are listed:

  • label

  • attached_text (for more detail see below).

  • unqualified custom class

The label property is implemented in the custom support class with the label_attr method. In ImageButtonCS, this method currently returns null, as does its superclass, CanvasCS.

The attached_text_attr method is also implemented by ObjectCS. It searches for adjacent static-text objects near the object, and returns their text. This mechanism is useful for controls like edit boxes and list boxes, which do not have their own descriptive text, but are accompanied by a label.

Note: You can teach UFT One to recognize custom static-text objects using the UFT One Custom Static-Text Support Class Wizard, which you access from the Eclipse New dialog box. For more information, see Learning to Support a Custom Static-Text Control.

In ImageButton, the attached_text property is empty, so UFT One must use a fallback mechanism. It uses the unqualified custom class, which is the name of the class, without the package name. In this case, the custom class: com.demo.ImageButton resulted in the name ImageButton for test object.

To change the name of a custom control test object, do not override the tag_attr method in the support class. Instead, make use of its existing implementation, and override the method label_attr.

  1. Override the label_attr method in the ImageButtonCS class.

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

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

      Note: You do not have to deploy the toolkit support to UFT One again because you changed only Java class files and not configuration files.

  2. Test the new custom support.

    Run the application and view the ImageButton control with the UFT One Object Spy, as described in Planning Support for the ImageButton Control.

    Note: You can use an open UFT One session (running with the ImageControls custom toolkit support loaded), but you must close the SampleApp application, and run it again, for the changes you made in the custom support to take effect.

    UFT One now recognizes the ImageButton as a JavaButton named JavaExt1.gif.

Next steps: