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, 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 GUI test again with the appropriate arguments.