Better Logging Support in TestComplete
I have been using TestComplete since May. The test suite has been running since June. Not sure if I used TC in the right way. Now it just acts as a giant Java interpreter to execute all the code in JScript (a fairly slow one in my opinion). I haven’t used too many of TC’s functions.
Anyway if you have to use script test case, you need to deal with logging. TestComplete offers four different levels: event, info, warning, error. Here is my code in my common_function.js file, which stores most of the generic functions:
[javascript toolbar=”true”]
function log_msg()
{
var msg = join_log_args(arguments);
Indicator.PushText(“[msg]: ” + msg);
Log.Message(msg);
}
function log_event()
{
var msg = join_log_args(arguments);
Indicator.PushText(“[event]: ” + msg);
Log.Event(msg);
}
function log_warn()
{
var msg = join_log_args(arguments);
Indicator.PushText(“[warn]: ” + msg);
Log.Warning(msg);
}
function log_error()
{
var msg = join_log_args(arguments);
Indicator.PushText(“[error]: ” + msg);
Log.Error(msg);
}
function log_debug()
{
if(vg_debug) //if debug is on
{
var msg = join_log_args(arguments);
var cl_priority = 200; //low priority
Indicator.PushText(“[debug]: ” + msg);
Log.Message(msg, “”, cl_priority);
}
}
function join_log_args(args)
{
var log_string = “”;
for (var i=0; i < args.length; i++)
{
log_string = log_string + args[i] + ” “;
}
return log_string;
}
[/javascript]
So if you want to log something, you just need to use:
log_error(log_prefix, "this is an error, error code:", error_code);
and it will automatically join all the input parameters together.