Working with Java Add-in Extensibility > Implementing Custom Toolkit Support > Understanding Custom Support Classes > Supporting the Record Option

Supporting the Record Option

You can extend UFT support of the recording option only for controls that extend AWT.

If you do not implement support for recording, you still have full support for all of the other UFT capabilities on the custom control, for example, learning the object, running tests on it, checking properties and values, and so forth.

To support recording on a custom control, the custom support class must:

In Tutorial: Learning to Create Java Custom Toolkit Support, you can practice creating support for recording on custom controls.

To add support for recording to a custom support class:

  1. Include the listeners in the support class signature. For example, the ImageButton support class ImageButtonCS listens for Action events:

  2. public class ImageButtonCS extends CanvasCS implements ActionListener {}
  3. Use a constructor for the support class to generate a list containing all of the listeners that you want to register on the custom control, and the methods used to add and remove these listeners.

    You do this by calling the utility method addSimpleListener for each listener. This method accepts three arguments of type String: The name of the listener, the name of the registration method, and the name of the method used to remove the listener.

    In the example below, the Action listener is listed for registration on ImageButton custom controls:

    public ImageButtonCS() {
      addSimpleListener("ActionListener", "addActionListener", "removeActionListener");

    The first time UFT identifies the custom control, it creates an instance of the support class for this custom control. This instance of the support class is used to support all subsequent controls of this custom class. Whenever a custom class instance is created, the support class registers the required listeners on the object using the registration methods you specified.

  4. Override low-level recording (optional):

    To override recording of low-level mouse events:

    protected Object mouseRecordTarget(MouseEvent e) {
        return null;

    To override recording of low-level keyboard events:

    protected Object keyboardRecordTarget(KeyEvent e) {
        return null;
  5. Implement the relevant event handler methods from the listener interface, to send record messages to UFT, using the MicAPI.record methods.

    For example, the following event handler method is implemented in ImageButtonCS, the support class for ImageButton:

    public void actionPerformed(ActionEvent e) {
        try {
                if (!isInRecord())
                MicAPI.record(e.getSource(), "Click");
            } catch(Throwable tr)
                { tr.printStackTrace();

    When an Action event occurs on an ImageButton, UFT records a Click operation on the ImageButton.

    The try ... catch block prevents unnecessary activity if this code is reached when the Java application is running while UFT is idle. The stack trace is printed to the same log file as other Java Add-in Extensibility log messages, enabling you to determine when this method was called inadvertently. For more information, see Logging and Debugging the Custom Support Class.

    For information on recording on wrapper controls, see Supporting Wrapper Controls.

    Note: If MicAPI.record is called when there is no active UFT recording session, nothing happens. If you perform additional calculations or assignments before calling MicAPI.record, make sure that you first call isInRecord to determine whether a recording session is active. If no recording session is active, you may want to avoid certain operations.