Logging and Debugging the Custom Support Class

When you design your support classes, it is recommended to include writing messages to a log file, to assist in debugging any problems that may arise.

Use the MicAPI.logLine method to send messages to the log file.

To control the printing of the log messages (to prevent all messages from being printed at all times), you create debug flags in each support class. When you call MicAPI.logLine, you provide the appropriate debug flag as the first argument. MicAPI.logLine prints the log messages only when the debug flag that you specified is on.

The following example illustrates how to print log messages in a support class:

private static final String DEBUG_ALLLIGHTSCS = "DEBUG_ALLLIGHTSCS";
public String light_on_positions_attr(Object obj) {
        AllLights lights = (AllLights) obj;
...
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
            if(lights.isSet(j, i)) {
                MicAPI.logLine(DEBUG_ALLLIGHTSCS, "Light "+i+":"+j+" is set");
...
            }
        }
    }
}

In UFT One, you create a test with the following two lines and run it to control the logging. Within the test, list the flags to turn on and the file to which the messages should be written:

javautil.SetAUTVar "sections_to_debug", "DEBUG_ALLLIGHTSCS"
javautil.SetAUTVar "debug_file_name", "C:\JavaExtensibility\Javalog.txt"

If you want to turn on more than one flag simultaneously, enter all of the flag strings consecutively in the second argument (separated by spaces), as in the following example:

javautil.SetAUTVar "sections_to_debug", "DEBUG_ALLLIGHTSCS DEBUG_AWTCALC"

The messages printed by MicAPI.logLine, according to the flags you set, are printed to the specified file when the support class runs. To change the flags controlling the log printing, or to change the file to which they are written, run the UFT One GUI test again with the appropriate arguments.

Debugging Your Custom Toolkit Support

The Java support classes run in the context of the application you are testing. Therefore, if you want to debug your support classes, you can do so in the same way as you would debug the application itself.

To begin debugging, place breakpoints within the support classes, run the application as though you were debugging it, and perform different UFT One operations on the application to reach the different parts of the support classes.

If the application code is stored in Eclipse, you can run it in debug mode from Eclipse. (Right-click the application file and select Debug As > Java Applet (or Application) or Debug As > SWT Application.)

If the application code is not stored in Eclipse, use remote debugging on the application to debug the support classes. For information on remote debugging, see the Eclipse Help.