LogItem Property

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the LogItem property to obtain the project’s top-level log item by its index in the project’s log items list. The top-level log items are listed under the Project_Suite_Name Logs | Project_Name Logs node in the Project Explorer panel.

To obtain the total number of a project’s top-level log items, use the LogItemsCount property.

Declaration

LogResultsObj.LogItem(Index)

Read-Only Property A LogItem object
LogResultsObj An expression, variable or parameter that specifies a reference to a LogResults object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired log item in the list of project’s log items. The index is zero-based, that is, the first log item has index 0, the second - 1, and so on. Index of the last log item is LogItemsCount - 1.

Property Value

A LogItem object corresponding to the desired top-level project log item.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the LogItem property in square brackets: LogItem[Index].

Example

The code below obtains a collection of logs that belong to the current project and posts the name and status of each log item to the test log.

JavaScript, JScript

function LogResultsExample()
 {
   // Obtains a collection of logs
   var LogsCol = Project.Logs;
   // Obtains the total number of log items in the collection
   var Num = LogsCol.LogItemsCount;
   
   if ( Num > 0 )
   {
     // Iterates through the items
     for (var i = 0; i < Num; i++)
     {
       var LogItem = LogsCol.LogItem(i);
       var Name = LogItem.Name;
       var Status = LogItem.Status;
       Log.Message("The " + Name + " item has the following status: " + Status);
     }
   }
   else 
     Log.Message("The collection has no log items.");

 }

Python

def LogResultsExample():
  # sObtains a collection of logs
  LogsCol = Project.Logs
  # Obtains the total number of log items in the collection
  Num = LogsCol.LogItemsCount
  if Num > 0:
    # Iterates through the items
    for i in range(0, Num):
      LogItem = LogsCol.LogItem[i]
      Name = LogItem.Name
      Status = LogItem.Status
      Log.Message("The " + Name + " item has the following status: " + str(Status))
  else:
    Log.Message("The collection has no log items.")

VBScript

Sub LogResultsExample()

  ' Obtains a collection of logs
  Set LogsCol = Project.Logs
  ' Obtains the total number of log items in the collection
  Num = LogsCol.LogItemsCount
  
  If Num > 0 Then
    ' Iterates through the items
    For i = 0 to (Num - 1)
      Set LogItem = LogsCol.LogItem(i)
      Name = LogItem.Name
      Status = LogItem.Status
      Log.Message("The " & Name & " item has the following status: " & Status)
    Next
  Else 
    Log.Message("The collection has no log items.")
  End If
  
End Sub

DelphiScript

function LogResultsExample;
var LogsCol, Num, i, LogItem, Name, Status;
begin

   // Obtains a collection of logs
   LogsCol := Project.Logs;
   // Obtains the total number of log items in the collection
   Num := LogsCol.LogItemsCount;
   
   if ( Num > 0 ) then
   begin
     // Iterates through the items
     for i := 0 to (Num - 1) do
     begin
       LogItem := LogsCol.LogItem[i];
       Name := LogItem.Name;
       Status := LogItem.Status;
       Log.Message('The ' + Name + ' item has the following status: ' + Status);
     end
   end
   else 
     Log.Message('The collection has no log items.');
end;

C++Script, C#Script

function LogResultsExample()
 {
   // Obtains a collection of logs
   var LogsCol = Project["Logs"];
   // Obtains the total number of log items in the collection
   var Num = LogsCol["LogItemsCount"];
   
   if ( Num > 0 )
   {
     // Iterates through the items
     for (var i = 0; i < Num; i++)
     {
       var LogItem = LogsCol["LogItem"](i);
       var Name = LogItem["Name"];
       var Status = LogItem["Status"];
       Log["Message"]("The " + Name + " item has the following status: " + Status);
     }
   }
   else 
     Log["Message"]("The collection has no log items.");
   
}

See Also

Access Test Log Contents from Tests
LogItemsCount Property
LogItem Object

Highlight search results