Implementing Support for a Test Object Method
In this section you extend UFT One 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.
Test the current functionality of the Click method on an ImageButton.
In UFT One, 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 UFT One User Guide.
Click the Run button or select Run > Run. The Run dialog box opens.
Select New run results folder. Accept the default results folder name.
Click OK to close the Run dialog box.
UFT One 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 One calls Click_replayMethod, which is currently implemented in the ImageButtonCS to return the error code
NOT_IMPLEMENTED
.Click Stop, to stop running the test.
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.
Implement the Click_replayMethod method in ImageButtonCS.
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.
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.
Test the new custom support.
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.
Close the SampleApp application and run it again.
In UFT One, 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.
Next steps: