Adding Variable Values to Log Messages

Applies to TestComplete 14.71, last modified on April 22, 2021

TestComplete provides special scripting methods and test operations that allow you to post messages to the log. Besides text messages, TestComplete allows you to post variable values to the test log. This topic describes how you can do this.

Posting Variable Values From Scripts

To add a variable value to a log message, specify the desired variable as a parameter of the Log.Message method. You can also specify the desired variable as part of a string posted to the test log (see the example).

JavaScript, JScript

function Main()
{
  Str = "The value to be posted to the log is ";
  Log.Message(Str + "123");
}

Python

def Main():
  Str = "The value to be posted to the log is "
  Log.Message(Str + "123")

VBScript

Sub Main
  Set Str = "The value to be posted to the log is "
  Log.Message(Str & "123")
End Sub

DelphiScript

procedure Main;
var Str: string;
begin
  Str := 'The value to be posted to the Log is ';
  Log.Message(Str + '123');
end;

C++Script, C#Script

function Main()
{
  Str = "The value to be posted to the log is ";
  Log["Message"](Str + "123")
}

Note: After running these tests, the log will contain the The value to be posted to the log is 123 string.

For more information about the additional parameters that assist you in posting variable values to the test log, see the method's description.

Posting Variable Values From Keyword Tests

To add a variable value to the test log from your keyword test, use the Log Message operation. When you add the operation to your keyword test, the Log Message dialog appears. On the pages of this dialog, you can specify the parameters that will be used to post the desired string to the test log.

To specify the variable to be posted to the test log, do the following:

  • Add the variable to your project. You can do this, for example, via the Add Variable to Keyword Test wizard.

  • Add the Log Message operation to your keyword test.

  • On the first page of the ensuing wizard, press Next.

  • On the second page of the wizard, select the MessageText row and press the ellipsis button.

  • In the ensuing Edit Parameter dialog, you can either select Variable from the Mode drop-down list to post the desired variable to the log, or select Code Expression from the Mode drop-down list to specify the code expression that defines the sting posted to the test log.

    • If you have selected the Variable mode, specify the desired variable name in the Value drop-down list.

    • If you have selected the Code Expression mode, you can either specify the desired code in the Value edit box or press the ellipsis button and use the ensuing Edit Expression dialog. Using this mode, you can, for example, specify the variable as part of a string posted to the log (see the image below).

      You can set a variable of any type (integer, table, object and so on) as a parameter of the Log Message operation. However, the operation processes data of OLE-compatible types only. If the value cannot be converted to text, it is ignored. For example, if you try to specify a DB Table variable in the Value list, an empty string will be posted to the log.
  • Click OK and then Finish to add the Log Message operation to your keyword test.

See Also

Posting Messages, Images and Files to the Log
Message Method
Error Method
Warning Method
Event Method
Log Message Operation

Highlight search results