Specifying Complex Expressions in Log Messages

Applies to TestComplete 15.63, last modified on April 23, 2024

TestComplete provides special scripting methods and test operations that allow you to post messages to the log. You can post text messages as well as variable values. Besides that, you can specify complex expressions as parameters of methods and operations that post messages to the log. An expression may contain not only text, but also variables, arithmetic operations and calls to functions and properties. TestComplete executes an expression and assigns its result to the parameter of the method or operation.

The following code demonstrates how you can post a message containing both the text and the value of the desired variable to the log. In the example, the value of a local variable is concatenated with the sting constant "The number of children of the Sys object is " and is passed as a parameter of the Log.Message method.

JavaScript, JScript

function Main()
{
  Num = Sys.ChildCount;
  Log.Message("The number of children of the Sys object is " + Num);
}

Python

def Main():
  Num = Sys.ChildCount
  Log.Message("The number of children of the Sys object is " + str(Num))

VBScript

Sub Main
  Set Num = Sys.ChildCount
  Log.Message("The number of children of the Sys object is " & Num)
End Sub

DelphiScript

procedure Main;
var Num: OleVariant;
begin
  Num := Sys.ChildCount;
  Log.Message('The number of children of the Sys object is ' + Num);
end;

C++Script, C#Script

function Main()
{
  Num = Sys.ChildCount;
  Log["Message"]("The number of children of the Sys object is " + Num);
}

To post a complex expression to the log from a keyword test, specify the expression as a parameter of the Log Message operation. Suppose, you want to post a string that contains the text and value of a keyword test variable. In this case:

  • 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, select Code Expression from the Mode drop-down list.
  • Specify the desired code expression in the Value edit box or press the ellipsis button and use the ensuing Edit Expression dialog.
  • Click OK and then Finish to add the Log Message operation to your keyword test.

See Also

Posting Messages to the Log
Adding Variable Values to Log Messages
Log Message Operation

Highlight search results