Implementing Support for a Test Object Method

In this section you extend UFT support of the ImageButton, to support a Click-the-button test object method. To do this, you must implement the Click_replayMethod in the custom support class, to call the appropriate MicAPI function.

  1. Test the current functionality of the Click method on an ImageButton.

    1. In UFT, create a new GUI test, add the JavaExt1.gif button to the object repository, and add a step with this object. For instructions on how to do this, see the Micro Focus Unified Functional Testing User Guide.

    2. The ImageButton is recognized as a JavaButton item (note the icon used) named JavaExt1.gif. The Click operation is the default operation for this item, as it is for all JavaButton items.

    3. Click the Run button or select Run > Run. The Run dialog box opens.

    4. Select New run results folder. Accept the default results folder name.

    5. Click OK to close the Run dialog box.

      UFT runs the test, and an error message is displayed. Click Details on the message box. The following information is displayed:

      The reason for this error is that to run the Click operation, the UFT calls Click_replayMethod, which is currently implemented in the ImageButtonCS to return the error code NOT_IMPLEMENTED.

    6. Click Stop, to stop running the test.

  2. Implement the Click_replayMethod method in ImageButtonCS.

    1. Replace the Click_replayMethod method stub, with the following code:

      public Retval Click_replayMethod(Object obj, String button) {
              ImageButton ib = (ImageButton) obj;
              MicAPI.mouseClick((Object) ib, ib.getWidth() / 2, 
                      ib.getHeight() / 2);
              return Retval.OK;
          }

      Note: When the wizard created the ImageButtonCS.java file, it automatically added the import com.mercury.ftjadin.custom.MicAPI, required to support this code.

    2. Click the Save button, or select File > Save.

      Note: This implementation ignores the button argument. For an implementation that takes this argument into account, you could call a different MicAPI.mouseClick method.

  3. Test the new custom support.

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

    1. Close the SampleApp application and run it again.

    2. In UFT, run the test you created above. The test run completes successfully. As you can see, the click counter in the edit box is increased when the test executes the Click operation.