Posting Messages to the Log

Applies to TestComplete 15.40, last modified on July 05, 2022

During test run, your keyword tests and script routines can post various messages to the log: error or warning notifications, informative messages, messages of the event type. You can also post images as well as files and file links.

Each message has its text, extended information and priority. In addition, you can specify the font and color settings to be used to display the message in the log. You can also associate images with messages. These images will be shown in the Picture panel of the test log. For more information on logging images, see Posting Images to the Log.

This topic describes the basic principles of posting messages to the log. The way you do this depends on whether you use keyword tests or script routines. We will start describing the scripting methods, since they are the base. Keyword test operations simply provide a visual interface to them.

Posting Messages From Scripts

To post messages to the log, use the following methods of the Log object:

Each of these methods lets you specify the message text, text for Details, priority, the message’s font style and color and an image for the log’s Picture pane.

All parameters except for the message text are optional. So, in the simplest case you can use only one parameter - the message text - to post a message to the log. The following code demonstrates this. It calls the Error method to log an error message with the text An error occurred.

JavaScript, JScript

Log.Error("An error occurred.");

Python

Log.Error("An error occurred.")

VBScript

Log.Error "An error occurred."

DelphiScript

Log.Error('An error occurred.');

C++Script, C#Script

Log["Error"]("An error occurred.");

The following code snippet logs an error with additional information and the highest priority:

JavaScript, JScript

Log.Error("Error Message Text", "Details Info Text", pmHighest);

Python

Log.Error("Error Message Text", "Details Text", pmHighest)

VBScript

Log.Error "Error Message Text", "Details Text", pmHighest

DelphiScript

Log.Error('Error Message Text', 'Details Info Text', pmHighest);

C++Script, C#Script

Log["Error"]("Error Message Text", "Details Text", pmHighest);

pmHighest is a built-in constant for specifying the highest priority. Here is a complete list of these constants:

Constant Value
pmLowest 100
pmLower 200
pmNormal 300
pmHigher 400
pmHighest 500

The priority values that you can use in logging methods are not limited with these constants. To specify the priority you can use any integer number, that is, you can use as many priority levels as needed, not just the predefined ones. The following code snippet demonstrates how to post an informative message with a custom priority value:

JavaScript, JScript

Log.Message("Message Text", "Extended Text", 350);

Python

Log.Message("Message Text", "Extended Text", 350)

VBScript

Log.Message "Message Text", "Extended Text", 350

DelphiScript

Log.Message('Message Text', 'Extended Text', 350);

C++Script, C#Script

Log["Message"]("Message Text", "Extended Text", 350);

The following example demonstrates how to log an image along with a message. It logs a warning with an image of the computer desktop or mobile device screen:

Desktop

JavaScript, JScript

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop);

Python

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop)

VBScript

Log.Warning "Warning Message Text", "Extended Text", pmHighest, Nothing, Sys.Desktop

DelphiScript

Log.Warning('Warning Message Text', 'Extended Text', pmHighest, nil, Sys.Desktop);

C++Script, C#Script

Log["Warning"]("Warning Message Text", "Extended Text", pmHighest, null, Sys["Desktop"]);

Web (Classic)

JavaScript, JScript

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop);

Python

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop)

VBScript

Log.Warning "Warning Message Text", "Extended Text", pmHighest, Nothing, Sys.Desktop

DelphiScript

Log.Warning('Warning Message Text', 'Extended Text', pmHighest, nil, Sys.Desktop);

C++Script, C#Script

Log["Warning"]("Warning Message Text", "Extended Text", pmHighest, null, Sys["Desktop"]);

Mobile

JavaScript, JScript

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Mobile.Device("MyDevice").Desktop.Picture());

Python

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Mobile.Device("MyDevice").Desktop.Picture())

VBScript

Log.Warning "Warning Message Text", "Extended Text", pmHighest, Nothing, Mobile.Device("MyDevice").Desktop.Picture

DelphiScript

Log.Warning('Warning Message Text', 'Extended Text', pmHighest, nil, Mobile.Device('MyDevice').Desktop.Picture());

C++Script, C#Script

Log["Warning"]("Warning Message Text", "Extended Text", pmHighest, null, Mobile["Device"]("MyDevice")["Desktop"].Picture());

In the previous examples, we used the Extended Text string to specify additional information posted along with the log message. You can also specify a string of HTML code in this parameter. The test engine will compile the HTML page and display it in the Details panel of the test log.

The following example demonstrates how to post an HTML page along with a log message. It reads HTML code from a text file to a single string and passes this string as an extended information parameter to the Log.Message method.

JavaScript, JScript

...
var MyFile, str, attr;

attr = Log.CreateNewAttributes();
attr.ExtendedMessageAsPlainText = false;
// Open a text file holding HTML code
MyFile = aqFile.OpenTextFile("c:\\MyHTMLCode.txt", aqFile.faRead, aqFile.ctANSI);

// Read the HTML code from the file to a single string
str = MyFile.ReadAll();

// Post a log message with the HTML page as extended information
Log.Message("Message Text", str, 300, attr);
...

Python

...

attr = Log.CreateNewAttributes()
attr.ExtendedMessageAsPlainText = False
# Open a text file holding HTML code
MyFile = aqFile.OpenTextFile("c:\\MyHTMLCode.txt", aqFile.faRead, aqFile.ctANSI)

# Read the HTML code from the file to a single string
str = MyFile.ReadAll()

# Post a log message with the HTML page as extended information
Log.Message("Message Text", str, 300, attr)
...

VBScript

...
Set attr = Log.CreateNewAttributes
attr.ExtendedMessageAsPlainText = False
' Open a text file holding HTML code
Set MyFile = aqFile.OpenTextFile("c:\MyHTMLCode.txt", aqFile.faRead, aqFile.ctANSI)

' Read the HTML code from the file to a single string
str = MyFile.ReadAll

' Post a log message with the HTML page as extended information
Log.Message "Message Text", str, 300, attr
...

DelphiScript

...
var MyFile, str, attr;
begin
  attr := Log.CreateNewAttributes;
  attr.ExtendedMessageAsPlainText := False;
  // Open a text file holding HTML code
  MyFile := aqFile.OpenTextFile('c:\MyHTMLCode.txt', aqFile.faRead, aqFile.ctANSI);

  // Read the HTML code from the file to a single string
  str := MyFile.ReadAll;

  // Post a log message with the HTML page as extended information
  Log.Message('Message Text', str, 300, attr);
end;
...

C++Script, C#Script

...
var MyFile, str, attr;

attr = Log["CreateNewAttributes"]();
attr["ExtendedMessageAsPlainText"] = false;
// Open a text file holding HTML code
MyFile = aqFile["OpenTextFile"]("c:\\MyHTMLCode.txt", aqFile["faRead"], aqFile["ctANSI"]);

// Read the HTML code from the file to a single string
str = MyFile["ReadAll"]();

// Post a log message with the HTML page as extended information
Log["Message"]("Message Text", str, 300, attr);
...

Posting Messages From Keyword Tests

In keyword tests, you can use the Log Message operation to add messages to the test log. This operation lets you choose the message type (information, error, warning and so on), specify the message text, priority and other parameters. For example, to log an error with the highest priority, follow these steps:

  • Add the Log Message operation to your keyword test.

  • In the operation parameters wizard:

    • Choose Error to specify that we will post an error message.

    • Type An error occurred into the Message text box. This is the text of our message.

    • Switch to the Details tabbed page and type Additional Info text there. This is the extended text of our message.

    Click Next.

  • The second page displays all of the parameters of the message. As you can see, the MessageText parameter contains the message text, and the AdditionalText parameter contains the extended text that we specified on the previous page.

    In our case, we need to specify the priority. To do this, enter 500 into the Priority cell and press Enter. (500 corresponds to the pmHighest constant. See above).

    For detailed information on how to specify parameter values on this page, see Specifying Operation Parameters.

  • Click Finish to close the wizard and to add the operation to the test.

Now after this operation is run, the “An error occurred” error message will be added to the log with the highest priority and the string “Additional Info text” as additional information.

See Also

Posting Messages, Images and Files to the Log
Message Method
Error Method
Warning Method
Event Method
Log Message Operation
Call Object Method Operation
Run Code Snippet Operation

Highlight search results