Implementing Support for New Test Object Methods

In this section, you implement the methods that support the new test object methods you defined for the AllLights test object class.

Analyze the AllLights custom class methods to determine what actions the class performs when a user clicks the Restart button or a light in the grid. You want to simulate these actions when UFT runs the test object methods.

  1. Implement the Restart_replayMethod method.

    When a user clicks within the borders of the RESTART button, the AllLights custom class calls init and update(lights.getGraphics()) to initialize and redraw the application. The Restart_replayMethod method needs to simulate this behavior by calling the same methods.

    To do this, delete the code: return Retval.NOT_IMPLEMENTED; and implement the method as follows:

    public Retval Restart_replayMethod (Object obj){
        AllLights lights = (AllLights) obj;
        return Retval.OK;
  2. Implement the ClickLight_replayMethod method.

    The AllLights custom class performs the algorithm of turning lights on or off in response to a click, when it receives a mouseUp event. Therefore, when UFT runs the ClickLight_replayMethod, and you want to simulate a click on a specific light, you can simply send the AllLights object a mouseUp event with the appropriate coordinates.

    In the method ClickLight_replayMethod, delete the code return Retval.NOT_IMPLEMENTED; and implement the method as follows:

    public Retval ClickLight_replayMethod(Object obj, String Row, String Column) {
        AllLights lights = (AllLights) obj;
        int col_num = Integer.valueOf(Column).intValue();
        int row_num = Integer.valueOf(Row).intValue();
        /* Row and column are 40 pixels wide*/
        Event event = new Event (lights, System.currentTimeMillis(), Event.MOUSE_UP, col_num *40, row_num *40, 0, 0);
        lights.mouseUp(event, col_num *40, row_num *40);
        return Retval.OK;

    Note: To support this code, import java.awt.Event in

    Select File > Save or click the Save button to save the file.