Enhancing the recording behavior

You can enhance the recording behavior for a user action on a control by extending the processMouseEvent() API. Functional Tester framework calls the processMouseEvent() API when a mouse event happens on a control. The processMouseEvent() API tells the Functional Tester framework which method has to be recorded for the mouse action.


Before you begin

For example, when you click a button control, the button().click() method is recorded. You can modify this behavior and add more information by extending the processMouseEvent() API of the proxy. This API is available only for GUI proxies.

You can extend the methods listed in Table 1:


Table 1. Extensible proxy methods

Java .Net
void processMouseEvent(IMouseActionInfo action) void ProcessMouseEvent(IMouseActionInfo action)
void processSingleMouseEvent(IMouseActionInfo action) void ProcessPreDownMouseEvent(IMouseActionInfo action)
void processHoverMouseEvent(IMouseActionInfo action) void ProcessPreUpMouseEvent(IMouseActionInfo action)
  void ProcessHoverMouseEvent(IMouseActionInfo action)

Related tasks

Create a proxy class

Add more control properties

Add more data types for a control

Enhancing the recording behavior with SubItems

Extending data driving

Change the role of a control

Modifying the recognition properties and weight of a control

Change the mappability of a control

Mapping proxies to controls

Deploy a proxy

Debugging the proxy code


Proxy recording APIs


Before you begin

processxxxMouseEvent() APIs

There are many processxxxMouseEvent() APIs available, but the main API that is used for any mouse event is processMouseEvent(). You can extend the rest of the processxxxMouseEvent() APIs the way you want. The following Java and .Net implementations of the processMouseEvent() API explain how the rest of the processxxxMouseEvent() APIs are related.

The following example shows the Java implementation of processMouseEvent():

public void processMouseEvent(IMouseActionInfo action)
{
  int eventState = action.getEventState();
  if ( eventState == IMouseActionInfo.PRE_DOWN ||
     eventState == IMouseActionInfo.PRE_UP ||
     eventState == IMouseActionInfo.POST_UP )
    processSingleMouseEvent(action);
  else if ( eventState == IMouseActionInfo.HOVER )
    processHoverMouseEvent(action);
}

The following example shows the .Net implementation of processMouseEvent():

public override void ProcessMouseEvent(IMouseActionInfo action)
{
  switch (action.GetEventState())
  {
    case MouseActionStates.PRE_DOWN:
      if (action.GetClickCount() == 1)
        ProcessPreDownMouseEvent(action);
      break; 
    case MouseActionStates.PRE_UP:
    // if one click, and it's not a drag, then, we're Done(no need to processPreUpMouseEvent)
      if (action.GetClickCount() != 1 || action.IsDrag())
        ProcessPreUpMouseEvent(action);
        break;
    case MouseActionStates.HOVER:
      ProcessHoverMouseEvent(action);
      break;
    }
  }
}

IMouseActionInfo interface

The processMouseEvent() API obtains the MouseEvent details, such as EventState, screen coordinates, and number of events, and uses these details to decide which method is recorded. The setMethodSpecification() method of IMouseActionInfo is used to return a MethodSpecification() object as a result of the processMouseEvent() API.

MethodSpecification class

The MethodSpecification object represents the method that is being recorded for a particular event. It is initialized with the method name and the parameter is set to the IMouseActionInfo object that is being passed to processMouseEvent(). The recorder picks up this method and records for a given user action.


Example

The following sample code extends the processMouseEvent() to change the recording behavior. By default, when you click once, the click() method is recorded. When you double-click, the doubleClick() method is recorded. In this sample the processSingleMouseEvent() API is overridden to swap the recording of click() and doubleClick() methods.

The following sample represents extending the processMouseEvent() in Java:

import com.rational.test.ft.domain.IMouseActionInfo;
import com.rational.test.ft.sys.MethodSpecification;
.
.
public void processSingleMouseEvent(IMouseActionInfo action)
{
  String method = null;
  int clicks = action.getClickCount();  
  if (clicks == 1)
                  // usually when clicks == 1,  the method is click, now we've changed to method to doubleClick
    method = "doubleClick"; //method = "click";
  else if (clicks == 2)
                  // usually when clicks == 2,  the method is doubleClick, now we've changed to method to click
    method = "click"; // method = "doubleClick";
  else 
    method = "nClick";
  
  // The method to be recorded is represented using this class in RFT
  MethodSpecification methodSpec = MethodSpecification.proxyMethod(this, method,null);
    
         // The method for the user action is set here
  action.setActionMethodSpecification(methodSpec);
  }


What to do next

After successfully developing and deploying this proxy code, the way that the click() and doubleClick() methods are recorded is swapped.

+

Search Tips   |   Advanced Search