ChildRow Property

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

Description

A log table can have a tree-like structure, that is, its rows can have child rows (in this case, the parent row is called the log folder). For example, the script log may contain folders, which you have created using the Log.CreateFolder or Log.AppendFolder method.

To obtain the child row of the row represented by the given LogTableRow object, use the ChildRow property. The total number of child rows of the given table row is specified by the ChildRowCount property.

Declaration

LogTableRowObj.ChildRow(Index)

Read-Only Property A LogTableRow object
LogTableRowObj An expression, variable or parameter that specifies a reference to a LogTableRow 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 child row. The index is zero-based, that is the first child row has index 0, the second - 1, and so on. Index of the last child row is ChildRowCount - 1.

Property Value

A LogTableRow object corresponding to the desired child row.

Remarks

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

Example

The following example iterates through log rows and posts information they contain to an external text file.

JavaScript

// Global variable
var ExportFile;

function ProcessRows()
{

  // Obtains a log item
  var LogItem = Project.Logs.LogItem(0);

  // Checks whether the log item’s data scheme corresponds to the table
  var LogData = LogItem.Data(0);
  DType = LogData.Scheme.DataType;
  if (DType == 0)
  {
    // Opens a text file for recording
    ExportFileName = "D:\\Work Folder\\ExportedLog\\LogRows.txt";
    FS = getActiveXObject("Scripting.FileSystemObject");
    ExportFile = FS.CreateTextFile(ExportFileName, true);

    // Iterates through the log table rows and exports them to the external file
    for (var i = 0; i < LogData.RowCount; i++)
    {
      // Obtains the current row
      Row = LogData.Rows(i);
      ExportLog(Row, LogData);
    }
    // Closes the file
    ExportFile.Close();
  }

}

function ExportLog(ALogRow, ALogData)
{

  var Scheme = ALogData.Scheme;
  Post = "";
  Count = Scheme.ColumnCount;
  // Iterates through the log columns
  for (var i = 0; i < Count; i++)
  {
    var Column = Scheme.Column(i);
    // If the column does not contain images...
    if (Column.DataType != 4)
    {
      // Obtains the value stored in the cell
      Value = aqConvert.VarToStr(ALogRow.ValueByIndex(i));
      Post = Post + Value + " ";
    }
  }
  // Posts the row to the external file
  ExportFile.WriteLine(Post);

  // If the current log row has child rows, posts them to the external file
  if (ALogRow.ChildRowCount > 0)
  {
    for (var i = 0; i < ALogRow.ChildRowCount; i++)
    {
      var ChildRow = ALogRow.ChildRow(i);
      ExportLog(ChildRow, ALogData);
    }
  }

}

JScript

// Global variable
var ExportFile;

function ProcessRows()
{

  // Obtains a log item
  var LogItem = Project.Logs.LogItem(0);

  // Checks whether the log item’s data scheme corresponds to the table
  var LogData = LogItem.Data(0);
  DType = LogData.Scheme.DataType;
  if (DType == 0)
  {
    // Opens a text file for recording
    ExportFileName = "D:\\Work Folder\\ExportedLog\\LogRows.txt";
    FS = Sys.OleObject("Scripting.FileSystemObject");
    ExportFile = FS.CreateTextFile(ExportFileName, true);

    // Iterates through the log table rows and exports them to the external file
    for (var i = 0; i < LogData.RowCount; i++)
    {
      // Obtains the current row
      Row = LogData.Rows(i);
      ExportLog(Row, LogData);
    }
    // Closes the file
    ExportFile.Close();
  }

}

function ExportLog(ALogRow, ALogData)
{

  var Scheme = ALogData.Scheme;
  Post = "";
  Count = Scheme.ColumnCount;
  // Iterates through the log columns
  for (var i = 0; i < Count; i++)
  {
    var Column = Scheme.Column(i);
    // If the column does not contain images...
    if (Column.DataType != 4)
    {
      // Obtains the value stored in the cell
      Value = aqConvert.VarToStr(ALogRow.ValueByIndex(i));
      Post = Post + Value + " ";
    }
  }
  // Posts the row to the external file
  ExportFile.WriteLine(Post);

  // If the current log row has child rows, posts them to the external file
  if (ALogRow.ChildRowCount > 0)
  {
    for (var i = 0; i < ALogRow.ChildRowCount; i++)
    {
      var ChildRow = ALogRow.ChildRow(i);
      ExportLog(ChildRow, ALogData);
    }
  }

}

Python

def ProcessRows():
  # Obtains a log item
  LogItem = Project.Logs.LogItem[0]
  # Checks whether the log item's data scheme corresponds to the table
  LogData = LogItem.Data[0]
  DType = LogData.Scheme.DataType
  if DType == 0:
    # Opens a text file for recording
    ExportFileName = "D:\\Work Folder\\ExportedLog\\LogRows.txt"
    FS = Sys.OleObject["Scripting.FileSystemObject"]
    ExportFile = FS.CreateTextFile(ExportFileName, True)
    # Iterates through the log table rows and exports them to the external file
    for i in range(0, LogData.RowCount):
      # Obtains the current row
      Row = LogData.Rows[i]
      ExportLog(Row, LogData, ExportFile)
    # Closes the file
    ExportFile.Close()

def ExportLog(ALogRow, ALogData, ExportedFile):
  Scheme = ALogData.Scheme
  Post = ""
  ColumnCount = Scheme.ColumnCount
  # Iterates through the log columns
  for i in range(0, ColumnCount):
    Column = Scheme.Column[i]
    # If the column does not contain images...
    if Column.DataType != 4:
      # Obtains the value stored in the cell
      Value = aqConvert.VarToStr(ALogRow.ValueByIndex[i])
      Post = Post + Value + " "
  # Posts the row to the external file
  ExportedFile.WriteLine(Post)
  # If the current log row has child rows, posts them to the external file
  if ALogRow.ChildRowCount > 0:
    for i in range(0, ALogRow.ChildRowCount):
      ChildRow = ALogRow.ChildRow[i]
      ExportLog(ChildRow, ALogData)

VBScript

' Global variable
Dim ExportFile

Sub ProcessRows

  ' Obtains a log item
  Set LogItem = Project.Logs.LogItem(0)

  ' Checks whether the log item’s data scheme corresponds to the table
  Set LogData = LogItem.Data(0)
  DType = LogData.Scheme.DataType
  If DType = 0 Then
    ' Opens a text file for recording
    ExportFileName = "D:\Work Folder\ExportedLog\LogRows.txt"
    Set FS = Sys.OleObject("Scripting.FileSystemObject")
    Set ExportFile = FS.CreateTextFile(ExportFileName, True)

    ' Iterates through the log table rows and exports them to the external file
    For i = 0 To LogData.RowCount - 1
      ' Obtains the current row
      Set Row = LogData.Rows(i)
      Call ExportLog(Row, LogData)
    Next
    ' Closes the file
    ExportFile.Close
  End If

End Sub

Sub ExportLog(ALogRow, ALogData)

  Set Scheme = ALogData.Scheme
  Post = ""
  Count = Scheme.ColumnCount
  ' Iterates through the log columns
  For i = 0 To Count - 1
    Set Column= Scheme.Column(i)
    ' If the column does not contain images...
    If Column.DataType <> 4 Then
      ' Obtains the value stored in the cell
      Value = aqConvert.VarToStr(ALogRow.ValueByIndex(i))
      Post = Post & Value & " "
    End If
  Next
  ' Posts the row to the external file
  ExportFile.WriteLine Post

  ' If the current log row has child rows, posts them to the external file
  If ALogRow.ChildRowCount > 0 Then
    For i = 0 To ALogRow.ChildRowCount - 1
      Set ChildRow = ALogRow.ChildRow(i)
      Call ExportLog(ChildRow, ALogData)
    Next
  End If

End Sub

DelphiScript

// Global variable
var ExportFile;

// Procedure declaration
procedure ExportLog(ALogRow, ALogData); forward;

procedure ProcessRows();
var LogItem, LogData, DType, ExportFileName, i , Row;
begin

  // Obtains a log item
  LogItem := Project.Logs.LogItem[0];

  // Checks whether the log item’s data scheme corresponds to the table
  LogData := LogItem.Data[0];
  DType := LogData.Scheme.DataType;
  if DType = 0 then
  begin
    // Opens a text file for recording
    ExportFileName := 'D:\Work Folder\ExportedLog\LogRows.txt';
    AssignFile(ExportFile, ExportFileName);
    Rewrite(ExportFile);

    // Iterates through the log table rows and exports them to the external file
    for i := 0 to LogData.RowCount - 1 do
    begin
      // Obtains the current row
      Row := LogData.Rows[i];
      ExportLog(Row, LogData);
    end;
    // Closes the file
    CloseFile(ExportFile);
  end;

end;

procedure ExportLog(ALogRow, ALogData);
var Scheme, Post, Column, Value, ChildRow, Count, i;
begin

  Scheme := ALogData.Scheme;
  Post := '';
  Count := Scheme.ColumnCount;
  // Iterates through the log columns
  for i := 0 to Count - 1 do
  begin
    Column := Scheme.Column[i];
    // If the column does not contain images...
    if Column.DataType <> 4 then
    begin
      // Obtains the value stored in the cell
      Value := aqConvert.VarToStr(ALogRow.ValueByIndex[i]);
      Post := Post + Value + ' ';
    end;
  end;
  // Posts the row to the external file
  WriteLn(ExportFile, Post);

  // If the current log row has child rows, posts them to the external file
  if ALogRow.ChildRowCount > 0 then
  begin
    for i := 0 to ALogRow.ChildRowCount - 1 do
    begin
      ChildRow := ALogRow.ChildRow[i];
      ExportLog(ChildRow, ALogData);
    end;
  end;

end;

C++Script, C#Script

// Global variable
var ExportFile;

function ProcessRows()
{

  // Obtains a log item
  var LogItem = Project["Logs"]["LogItem"](0);

  // Checks whether the log item’s data scheme corresponds to the table
  var LogData = LogItem["Data"](0);
  DType = LogData.Scheme.DataType;
  if (DType == 0)
  {
    // Opens a text file for recording
    ExportFileName = "D:\\Work Folder\\ExportedLog\\LogRows.txt";
    FS = Sys["OleObject"]("Scripting.FileSystemObject");
    ExportFile = FS["CreateTextFile"](ExportFileName, true);

    // Iterates through the log table rows and exports them to the external file
    for (var i = 0; i < LogData["RowCount"]; i++)
    {
      // Obtains the current row
      Row = LogData["Rows"](i);
      ExportLog(Row, LogData);
    }
    // Closes the file
    ExportFile["Close"]();
  }

}

function ExportLog(ALogRow, ALogData)
{

  var Scheme = ALogData["Scheme"];
  Post = "";
  Count = Scheme["ColumnCount"];
  // Iterates through the log columns
  for (var i = 0; i < Count; i++)
  {
    var Column = Scheme["Column"](i);
    // If the column does not contain images...
    if (Column["DataType"] != 4)
    {
      // Obtains the value stored in the cell
      Value = aqConvert["VarToStr"](ALogRow["ValueByIndex"](i));
      Post = Post + Value + " ";
    }
  }
  // Posts the row to the external file
  ExportFile["WriteLine"](Post);

  // If the current log row has child rows, posts them to the external file
  if (ALogRow["ChildRowCount"] > 0)
  {
    for (var i = 0; i < ALogRow["ChildRowCount"]; i++)
    {
      var ChildRow = ALogRow["ChildRow"](i);
      ExportLog(ChildRow, ALogData);
    }
  }

}

See Also

Access Test Log Contents from Tests
ChildRowCount Property

Highlight search results