Access Test Log Contents from Tests

Applies to TestComplete 15.69, last modified on November 13, 2024

TestComplete stores all of the test results in XML format in the <Project_Folder>\Logs folder. You can export log contents into XML, HTML or MHT (see Exporting Test Results) in order to view test results in your Internet browser. However, you may need to have test results in a custom format, different from the formats offered by TestComplete. To make this possible, TestComplete provides special program objects which let you access test log contents from tests. You only have to write a keyword test or a script routine which will process the log contents as you need it.

This topic provides advanced information on test log structure and describes the technique used to parse the log contents.

Notes

  • TestComplete does not provide a scripting interface to the test log of the current run. TestComplete is compiling the log during the test execution and this process is only finished when the test is complete. Scripts can access the log only after it has been added to the list of project logs that is displayed in the Project Explorer panel.
  • Scripting access to project suite logs is not available.

General Structure of Test Results

The TestComplete test log has a tree-like structure. It consists of a number of log items organized into a log tree. The topmost item of this structure (the tree root) corresponds to the element which you told TestComplete to run to perform testing. This element can be a project suite, project, project item, test item or script routine. The topmost item contains all other logs generated during the test execution. For example, the project log contains logs for its test items. The test item log, in turn, contains the log of the element which it runs and also logs for its child test items.

Topmost log items (project logs) are displayed in the Project Explorer panel. The hierarchy of child items of the selected log is shown within the test log window that is displayed in the Workspace panel:

Log Items

To access log items in tests, use the Project.Logs property. It returns the LogResults object containing methods and properties that let you enumerate top-level log items.

The LogResults object provides access to project logs listed in the Project Explorer. It does not provide access to the current test log. This is because the test log contents are formed during the test execution and the log is only added to the list of project logs after the test run is finished.

Each log item (the topmost items and the child log items) is represented in tests as the LogItem object. You obtain this object by using the LogResults.LogItem property (see examples below).

The LogItem object contains methods and properties that let you obtain child log items and access a log item’s data.

To obtain access to a log item’s data, use the LogItem.Data property. It returns the object that provides a scripting interface to the data. Note that project suites, projects, project items and scripts form specific logs. For instance, the project log differs from the script log. Therefore, the returned object contains methods and properties specific to the type of data, which the log item stores.

The next section explains how the log item data is organized.

Structure of Log Item Data

The structure of the log item’s data depends on the element (project suite, project or project item), whose results the log item stores. The log item data has a tree-like structure: the item data typically includes a table or tree list with one or more child tables, text fields and images. For instance, the script log contains a tree list and two additional windows - Details and Picture - that display information concerning the selected tree list node. The data shown in the Details and Picture windows is child data relative to the data shown in the tree list.

Parent and child data

Click the image to enlarge it.

The structure of log item’s data and their parent-child relations are described by data schemes. The schemes specify the data types, data type name, provides access to child data schemes and specify other data-specific attributes.

As we mentioned above, to obtain access to the log item’s data you use the LogItem.Data property. This property returns a scripting object that provides access to root data of the log item:

Test Log

Click the image to enlarge it.

Note that the LogItem.Data property is an indexed property because a log item may contain several root log data objects.

TestComplete supports the following type of data objects:

  • Table (this type is used by data that are organized in tables or tree lists).
  • Text.
  • Image.

Therefore, when you use the LogItem.Data property to obtain access to the log item data, the property returns one of the following objects:

These objects contain methods and properties that are specific for the appropriate data type. For instance, PictureLogData object lets you obtain the stored image as Picture object; the TextLogData object lets you get text data, LogTableData provides access to values stored in the table (or tree list).

The LogTableData, TextLogData and PictureLogData objects contain the Scheme property. This property returns the LogDataScheme object that describes the data. It contains a property that lets you determine the data type (table, text or image). If data holds a table, the Scheme property returns the LogTableDataScheme object that provides information about table columns.

The LogDataScheme object also contains the Child and ChildCount property that lets you obtain child data scheme objects.

As we have said, log data can have child data. Currently, access to child data is provided for table data objects (LogTableData). The following section describes how you can parse the stack and obtain access to the child data.

Parsing Log Data

A typical procedure that parses the test log includes the following steps:

  1. Use the Project.Logs property to obtain the LogResults object holding the list of project logs.
  2. Use the LogResults.LogItem property to obtain the LogItem object (it corresponds to the root log item).
  3. Use the LogItem.Data property to obtain the TextLogData, PictureLogData or LogTableData object holding the log item’s data.
  4. Parse the log item’s data.
  5. Repeat steps 3-4 for child items of the root log item. To iterate through child log items, use the LogItem.ChildCount and LogItem.Child properties. The latter property returns the child LogItem object by its index.

To parse the log item data, follow these steps:

  • Use the LogData.Scheme.DataType property to determine the type of data.
    Note: To determine the element (project suite, project or project item), whose results the log item contains, use the LogItem.Name property.
  • Process the log item data depending on its type:

    Text

    If the log item data is of text type, then the LogItem.Data property returns the TextLogData object. Using the Format property of this object you can determine the text format (plain text, HTML or XML) and use the Text property to obtain the text itself.

    Picture

    If the log item data is of picture type, then the given LogItem.Data property returns the PictureLogData object. Using the PictureLogData.Picture property, you can obtain the Picture object holding the stored picture.

    Table

    If the given log item data is of the table type (it can be a generic table or a tree-like list), then the LogItem.Data property returns the LogTableData object. Using properties of this object, you can obtain the values stored in table cells.

    1. Use the LogTableData.Scheme.ColumnCount to obtain the number of table columns. To obtain an object corresponding to a column, use any of the following properties:
    2. Use the LogTableData.RowCount and LogTableData.Rows properties to iterate through table rows. The latter property returns the LogTableRow object that corresponding to the row.
    3. To obtain the value stored in a table cell, use one of the following properties of the LogTableRow object:
      • ValueByName - Returns the value by the column caption.
      • ValueByIndex - Returns the value by column index (zero-based). The total number of columns is specified by the LogItem.Data.Scheme.ColumnCount property.
      • Value - Returns the value by the LogColumn object.
    4. The data stored in the table can have child data (for instance, each row in the Script log has child data displayed in the Details and Picture panels). To obtain the child data, use any of the following properties:

      You can process the child data, using the same technique.

    5. Data of table type can be organized in a tree (as it is, for example, in the Script log). These data are displayed using tree list controls in TestComplete log pages. Each tree node can have nodes (in the Script log the parent node is called a folder). To iterate through child rows, use the LogTableRow.ChildRowCount and LogTableRow.ChildRow properties. ChildRowCount returns the total number of child nodes and the ChildRow property returns the LogTableRow object corresponding to the desired child row. After you have obtained the child row, you can get its contents as described in steps 3 and also parse its child data, like described in step 4.

Examples

You can use the described methods and properties of objects, obtaining log contents, both from keyword tests and scripts.

Obtaining Log Data from Keyword Tests

You can obtain the log data and then save it to file by using the LogResults, LogItemand other mentioned objects' methods and properties in your keyword test. To obtain or change the property value or to call the object's method from a keyword test, use, for instance, the Call Object Method operation. To save the object's reference to a variable, use the Set Variable Value operation and so on. For more information on how to implement common tasks from keyword tests, see Common Tasks for Keyword Test Operations.

Another way is to create a script routine, which obtains log data, and then run this routine from a keyword test. To do this, add the Run Script Routine operation to the test and specify the name of the created routine in the Operation Parameters wizard. After that the log data will be obtained each time, when you execute this test.

Obtaining Log Data from Scripts

The following sample code demonstrates how to process test results from scripts. It iterates through the project logs and saves their contents to a text file.

JavaScript, JScript

// Global variables
var ImgCount, ExportFile, ExportFileName;

// Exporting the log
function ExportLog()
{
  var i, FS;
  
  if(Project.Logs.LogItemsCount > 0)
  {
    // Initializing variables
    ExportFileName = "C:\\ExportLog_JS.txt";
    ImgCount = 0;

    // Creating file. In JScript, use Sys.OleObject instead of getActiveXObject.
    FS = getActiveXObject("Scripting.FileSystemObject")
    ExportFile = FS.CreateTextFile(ExportFileName, true);

    // Exporting the test log contents
    try
    {
      for(i = 0; i < Project.Logs.LogItemsCount; i++)
        ExportLogItem(Project.Logs.LogItem(i));
    }
    finally
    {
      ExportFile.Close();
    }
  }
  else
    // If the project does not contain log items,
    // post a message about this to the test log
    Log.Message("No logs for export.");
}

// Exporting images
function ExportPicture(ALogData)
{
  var s;

  // Generating the image file name
  ImgCount = ImgCount + 1;
  s = aqFileSystem.GetFileFolder(ExportFileName) + "\\" + aqConvert.VarToStr(ImgCount) + ".jpg";
  // Saving image to file
  ALogData.Picture.SaveToFile(s);
  // Saving image file name to the log data file
  ExportFile.WriteLine("Picture: " + s);
}

// Exporting text
function ExportText(ALogData)
{
  ExportFile.WriteLine("Text: " + ALogData.Text);
}

// Exporting row data
function ExportRow(TableScheme, Caption, ARow)
{
  var i, s;
  var Child, ChildRow;
  var ColCount, ChildCount

  // Getting the number of table columns
  ColCount = TableScheme.ColumnCount;
  // Getting the number of child tables
  ChildCount = TableScheme.ChildCount;

  s = Caption;

   // Exporting column data
    for(i = 0; i < ColCount; i++)
      s = s + aqConvert.VarToStr(ARow.ValueByIndex(i)) + "\t";
    ExportFile.WriteLine(s); // Writing data to file
    
    // Exporting child tables data
    for(i = 0; i < ChildCount; i++)
    {
      Child = ARow.ChildDataByIndex(i);
      ExportLogData(Child);
    }
    
    // Exporting child rows (if the data is displayed as a tree)
    for(i = 0; i < ARow.ChildRowCount; i++)
    {
      ChildRow = ARow.ChildRow(i);
      s = "Row " + aqConvert.VarToStr(i + 1) + ":\t";
      ExportRow(TableScheme, s, ChildRow);
    }
}

// Exporting table data
function ExportTable(ALogData)
{
  var TableScheme, Row, i, s;
  
  // Obtaining the table scheme
  TableScheme = ALogData.Scheme;

  // Iterating through table records and exporting table data
  for(i = 0; i < ALogData.RowCount; i++)
  {
    // Obtaining the row object
    Row = ALogData.Rows(i);
    s = "Row " + aqConvert.VarToStr(i + 1) + ":\t";
    // Exporting the row
    ExportRow(TableScheme, s, Row);
  }
}

// Exporting log item's data
function ExportLogData(ALogData)
{
  var Scheme;

  Scheme = ALogData.Scheme;
  
  // Exporting the scheme name
  ExportFile.WriteBlankLines (1);
  ExportFile.WriteLine ("Name: " + Scheme.Name);
  ExportFile.WriteLine("-------------------------------------------");
  
  // Determining the type of log item"s data and
  // exporting the data
  switch(Scheme.DataType)
  {
    case ldtTable :
      ExportTable(ALogData); // Exporting table data
      break;
    case ldtPicture:
      ExportPicture(ALogData); // Exporting picture
      break;
    case ldtText :
      ExportText(ALogData); // Exporting text
      break;
  }
}

// Exporting log items
function ExportLogItem(ALogItem)
{
  var i;

  // Exporting log item's data
  for(i = 0; i < ALogItem.DataCount; i++)
    ExportLogData(ALogItem.Data(i));

  // Exporting child log items
  for(i = 0; i < ALogItem.ChildCount; i++)
    ExportLogItem(ALogItem.Child(i));
}

Python

# Global variables
ImgCount = 0
ExportFile = 0
ExportFileName = 0

# Exporting the log
def ExportLog():
  global ImgCount
  global ExportFile
  global ExportFileName
  if Project.Logs.LogItemsCount > 0:
    # Initializing variables
    ExportFileName = "C:\\ExportLog_Py.txt"
    ImgCount = 0

    # Creating file
    FS = Sys.OleObject["Scripting.FileSystemObject"]
    ExportFile = FS.CreateTextFile(ExportFileName, True)

    # Exporting the test log contents
    try:
      for i in range(0, Project.Logs.LogItemsCount) :
        ExportLogItem(Project.Logs.LogItem(i))
    finally:
      ExportFile.Close()
  else:
    # If the project does not contain log items,
    # post a message about this to the test log
    Log.Message("No logs for export.")

# Exporting images
def ExportPicture(ALogData):
  global ImgCount
  global ExportFile
  global ExportFileName
  # Generating the image file name
  ImgCount = ImgCount + 1
  s = aqFileSystem.GetFileFolder(ExportFileName) + "\\" + aqConvert.VarToStr(ImgCount) + ".jpg"
  # Saving image to file
  ALogData.Picture.SaveToFile(s)
  # Saving image file name to the log data file
  ExportFile.WriteLine("Picture: " + s)

# Exporting text
def ExportText(ALogData):
  global ExportFile
  ExportFile.WriteLine("Text: " + ALogData.Text); 

# Exporting row data
def ExportRow(TableScheme, Caption, ARow):
  global ExportFile

  # Getting the number of table columns 
  ColCount = TableScheme.ColumnCount;
  # Getting the number of child tables
  ChildCount = TableScheme.ChildCount; 

  s = Caption

  # Exporting column data
  for i in range(0, ColCount): 
    s = s + aqConvert.VarToStr(ARow.ValueByIndex(i)) + "\t"
    ExportFile.WriteLine(s) # Writing data to file
    
    # Exporting child tables data 
    for i in range(0, ChildCount):
      Child = ARow.ChildDataByIndex(i)
      ExportLogData(Child)
    
    # Exporting child rows (if the data is displayed as a tree)
    for i in range(0, ARow.ChildRowCount):
      ChildRow = ARow.ChildRow(i)
      s = "Row " + aqConvert.VarToStr(i + 1) + ":\t"
      ExportRow(TableScheme, s, ChildRow)

# Exporting table data
def ExportTable(ALogData):
  
  # Obtaining the table scheme
  TableScheme = ALogData.Scheme; 

  # Iterating through table records and exporting table data
  for i in range(0, ALogData.RowCount):
    # Obtaining the row object
    Row = ALogData.Rows(i)
    s = "Row " + aqConvert.VarToStr(i + 1) + ":\t"
    # Exporting the row
    ExportRow(TableScheme, s, Row)

# Exporting log item's data
def ExportLogData(ALogData):
  global ExportFile
  
  Scheme = ALogData.Scheme
  
  # Exporting the scheme name
  ExportFile.WriteBlankLines (1);
  ExportFile.WriteLine ("Name: " + Scheme.Name); 
  ExportFile.WriteLine("-------------------------------------------");
  
  # Determining the type of log item"s data and 
  # exporting the data
  if Scheme.DataType == ldtTable:
    ExportTable(ALogData) # Exporting table data
  elif Scheme.DataType == ldtPicture:
    ExportPicture(ALogData) # Exporting picture
  elif Scheme.DataType == ldtText:
     ExportText(ALogData) # Exporting text

# Exporting log items
def ExportLogItem(ALogItem):
  
  # Exporting log item's data
  for i in range(0, ALogItem.DataCount):
    ExportLogData(ALogItem.Data(i))

  # Exporting child log items 
  for i in range(0, ALogItem.ChildCount): 
    ExportLogItem(ALogItem.Child(i))

VBScript

' Global variables
Dim ImgCount, ExportFile, ExportFileName

' Exporting images
Sub ExportPicture(ALogData)
  ' Generating the image file name
  ImgCount = ImgCount + 1
  s = aqFileSystem.GetFileFolder(ExportFileName) + "\" + CStr(ImgCount) + ".jpg"
  ' Saving image to file
  ALogData.Picture.SaveToFile s
  ' Saving image file name to the log data file
  ExportFile.WriteLine "Picture: " + s
End Sub

' Exporting text
Sub ExportText(ALogData)
  ExportFile.WriteLine "Text: " + ALogData.Text
End Sub

' Exporting row data
Sub ExportRow(TableScheme, Caption, ARow)
  Dim i, s
  Dim Child, ChildRow, ColCount, ChildCount

  ' Getting the number of table columns
  ColCount = TableScheme.ColumnCount
  ' Getting the number of child tables
  ChildCount = TableScheme.ChildCount

  s = Caption

  ' Exporting column data
  For i = 0 To ColCount - 1
    s = s + aqConvert.VarToStr(ARow.ValueByIndex(i)) + Chr(9)
  Next
  ExportFile.WriteLine(s) ' Writing data to file
  
  ' Exporting child tables data
  For i = 0 To ChildCount - 1
    Set Child = ARow.ChildDataByIndex(i)
    Call ExportLogData(Child)
  Next
    
  ' Exporting child rows (if the data is displayed as a tree)
  For i = 0 To ARow.ChildRowCount - 1
    Set ChildRow = ARow.ChildRow(i)
    s = "Row " + aqConvert.VarToStr(i + 1) + ":" + Chr(9)
    Call ExportRow(TableScheme, s, ChildRow)
  Next
End Sub

' Exporting table data
Sub ExportTable(ALogData)
  Dim TableScheme, Row, i, s

  ' Obtaining the table scheme
  Set TableScheme = ALogData.Scheme

  ' Iterating through table records and exporting table data
  For i = 0 To ALogData.RowCount - 1
    ' Obtaining the row object
    Set Row = ALogData.Rows(i)
    s = "Row " + aqConvert.VarToStr(i + 1) + Chr(9)
    ' Exporting the row
    Call ExportRow(TableScheme, s, Row)
  Next
End Sub

' Exporting log item's data
Sub ExportLogData(ALogData)
  Set Scheme = ALogData.Scheme
  
  ' Exporting the scheme name
  ExportFile.WriteBlankLines 1
  ExportFile.WriteLine "Name: " + Scheme.Name
  ExportFile.WriteLine "-------------------------------------------"
  
  ' Determining the type of log item's data and
  ' exporting the data
  Select Case Scheme.DataType
    Case ldtTable ExportTable(ALogData) ' Exporting table data
    Case ldtPicture ExportPicture(ALogData) ' Exporting picture
    Case ldtText ExportText(ALogData) ' Exporting text
  End Select
End Sub

' Exporting log items
Sub ExportLogItem(ALogItem)
  ' Exporting log item's data
  For i = 0 To ALogItem.DataCount - 1
    ExportLogData ALogItem.Data(i)
  Next

  ' Exporting child log items
  For i = 0 To ALogItem.ChildCount - 1
    ExportLogItem ALogItem.Child(i)
  Next
End Sub

' Exporting the log
Sub ExportLog
  If Project.Logs.LogItemsCount > 0 Then
    ' Initializing variables
    ExportFileName = "C:\Work\ExportedLog\ExportLog.txt"
    ImgCount = 0

    ' Creating file
    Set FS = Sys.OleObject("Scripting.FileSystemObject")
    Set ExportFile = FS.CreateTextFile(ExportFileName, True)

    ' Exporting the test log contents
    Err.Clear
    On Error Resume Next
    For i = 0 To Project.Logs.LogItemsCount - 1
      ExportLogItem Project.Logs.LogItem(i)
    Next
    ExportFile.Close
  Else
    ' If the project does not contain log items,
    ' post a message about this to the test log
    Log.Message "No logs for export."
  End If
End Sub

DelphiScript

// Global variables
var ImgCount, ExportFile, ExportFileName : OleVariant;

// Forward procedure declaration
procedure ExportLogData(ALogData); forward;


// Exporting images
procedure ExportPicture(ALogData);
var
  s : OleVariant;
begin
  // Generating the image file name
  ImgCount := ImgCount + 1;
  s := aqFileSystem.GetFileFolder(ExportFileName) + '\' + aqConvert.IntToStr(ImgCount) + '.jpg';
  // Saving image to file
  ALogData.Picture.SaveToFile(s);
  // Saving image file name to the log data file
  WriteLn(ExportFile, 'Picture: ' + s);
end;

// Exporting text
procedure ExportText(ALogData);
begin
  WriteLn(ExportFile, 'Text: ' + ALogData.Text);
end;

// Exporting row data
procedure ExportRow(TableScheme, Caption, ARow);
var 
  i, s : OleVariant;
  ChildRow, Child, ColCount, ChildCount : OleVariant;
begin
  // Getting the number of table columns
  ColCount := TableScheme.ColumnCount;
  // Getting the number of child tables
  ChildCount := TableScheme.ChildCount;

  s := Caption;

  // Exporting column data
  for i := 0 to ColCount - 1 do 
    s := s + aqConvert.VarToStr(ARow.ValueByIndex(i)) + #9;
  WriteLn(ExportFile, s); // Writing data to file
    
  // Exporting child tables data
  for i := 0 to ChildCount - 1 do
  begin
    Child := ARow.ChildDataByIndex(i);
    ExportLogData(Child);
  end;
    
  // Exporting child rows (if the data is displayed as a tree)
  for i := 0 to ARow.ChildRowCount - 1 do
  begin
    ChildRow := ARow.ChildRow(i);
    s := 'Row ' + aqConvert.VarToStr(i + 1) + ':' + #9;
    ExportRow(TableScheme, s, ChildRow);
  end;
end;

// Exporting table data
procedure ExportTable(ALogData);
var 
  TableScheme, Row, i, s: OleVariant;
begin
  // Obtaining the table scheme
  TableScheme := ALogData.Scheme;

  // Iterating through table records and exporting table data
  for i := 0 to ALogData.RowCount - 1 do
  begin
    // Obtaining the row object
    Row := ALogData.Rows(i);
    s := 'Row ' + aqConvert.VarToStr(i + 1) + ':' + #9;
    // Exporting the row data
    ExportRow(TableScheme, s, Row);
  end;
end;

// Exporting log item's data
procedure ExportLogData(ALogData);
var 
  Scheme : OleVariant;
begin
  Scheme := ALogData.Scheme;
  
  // Exporting the scheme name
  WriteLn(ExportFile, #13#10);
  WriteLn(ExportFile, 'Name: ' + Scheme.Name);
  WriteLn(ExportFile, '-------------------------------------------');
  
  // Determining the type of log item's data and
  // exporting the data
  case Scheme.DataType of
    ldtTable : ExportTable(ALogData); // Exporting table data
    ldtPicture: ExportPicture(ALogData); // Exporting picture
    ldtText : ExportText(ALogData); // Exporting text
  end;
end;

// Exporting log items
procedure ExportLogItem(ALogItem);
var 
  i : OleVariant;
begin
  // Exporting log item's data
  for i := 0 to ALogItem.DataCount - 1 do 
    ExportLogData(ALogItem.Data[i]);

  // Exporting child log items
  for i := 0 to ALogItem.ChildCount - 1 do 
    ExportLogItem(ALogItem.Child[i]);
end;

// Exporting the log
procedure ExportLog;
var 
  i : OleVariant;
begin
  if Project.Logs.LogItemsCount > 0 then
  begin
    // Initializing variables
    ExportFileName := 'C:\Work\ExportedLog\ExportLog.txt';
    ImgCount := 0;

    // Creating file
    AssignFile(ExportFile, ExportFileName);
    Rewrite(ExportFile);

    // Exporting the test log contents
    try 
      for i := 0 to Project.Logs.LogItemsCount - 1 do 
        ExportLogItem(Project.Logs.LogItem[i]);
    finally
      CloseFile(ExportFile);
    end;
  end
  else
    // If the project does not contain log items,
    // post a message about this to the test log
    Log.Message('No logs for export.');
end;

C++Script, C#Script

// Global variables
var ImgCount, ExportFile, ExportFileName;

// Exporting images
function ExportPicture(ALogData)
{
  var s;

  // Generating the image file name
  ImgCount = ImgCount + 1;
  s = aqFileSystem["GetFileFolder"](ExportFileName) + "\\" + aqConvert["VarToStr"](ImgCount) + ".jpg";
  // Saving image to file
  ALogData["Picture"]["SaveToFile"](s);
  // Saving image file name to the log data file
  ExportFile["WriteLine"]("Picture: " + s);
}

// Exporting text
function ExportText(ALogData)
{
  ExportFile["WriteLine"]("Text: " + ALogData["Text"]);
}

// Exporting row data
function ExportRow(TableScheme, Caption, ARow)
{
  var i, s;
  var Child, ChildRow;
  var ColCount, ChildCount

  // Getting the number of table columns
  ColCount = TableScheme["ColumnCount"];
  // Getting the number of child tables
  ChildCount = TableScheme["ChildCount"];

    s = Caption;

   // Exporting column data
    for(i = 0; i < ColCount; i++)
      s = s + aqConvert["VarToStr"](ARow["ValueByIndex"](i)) + "\t";
    ExportFile["WriteLine"](s); // Writing data to file
    
    // Exporting child tables data
    for(i = 0; i < ChildCount; i++)
    {
      Child = ARow["ChildDataByIndex"](i);
      ExportLogData(Child);
    }
    
    // Exporting child rows (if the data is displayed as a tree)
    for(i = 0; i < ARow["ChildRowCount"]; i++)
    {
      ChildRow = ARow["ChildRow"](i);
      s = "Row " + aqConvert["VarToStr"](i + 1) + ":\t";
      ExportRow(TableScheme, s, ChildRow);
    }
}

// Exporting table data
function ExportTable(ALogData)
{
  var TableScheme, Row, i, s;

  // Obtaining the table scheme
  TableScheme = ALogData["Scheme"];

  // Iterating through table records and exporting table data
  for(i = 0; i < ALogData["RowCount"]; i++)
  {
    // Obtaining the row object
    Row = ALogData["Rows"](i);
    s = "Row " + aqConvert["VarToStr"](i + 1) + ":\t";
    // Exporting the row data
    ExportRow(TableScheme, s, Row);
  }
}

// Exporting log item's data
function ExportLogData(ALogData)
{
  var Scheme;

  Scheme = ALogData["Scheme"];
  
  // Exporting the scheme name
  ExportFile["WriteBlankLines"](1);
  ExportFile["WriteLine"]("Name: " + Scheme["Name"]);
  ExportFile["WriteLine"]("-------------------------------------------");
  
  // Determining the type of log item's data and
  // exporting the data
  switch(Scheme["DataType"])
  {
    case ldtTable :
      ExportTable(ALogData); // Exporting table data
      break;
    case ldtPicture:
      ExportPicture(ALogData); // Exporting picture
      break;
    case ldtText :
      ExportText(ALogData); // Exporting text
      break;
  }
}

// Exporting log items
function ExportLogItem(ALogItem)
{
  var i;

  // Exporting log item's data
  for(i = 0; i < ALogItem["DataCount"]; i++)
    ExportLogData(ALogItem["Data"](i));

  // Exporting child log items
  for(i = 0; i < ALogItem["ChildCount"]; i++)
    ExportLogItem(ALogItem["Child"](i));
}

// Exporting the log
function ExportLog()
{
  var i, FS;
  
  if(Project["Logs"]["LogItemsCount"] > 0)
  {
    // Initializing variables
    ExportFileName = "C:\\Work\\ExportedLog\\ExportLog.txt";
    ImgCount = 0;

    // Creating file
    FS = Sys["OleObject"]("Scripting.FileSystemObject")
    ExportFile = FS["CreateTextFile"](ExportFileName, true);

    // Exporting the test log contents
    try 
    {
      for(i = 0; i < Project["Logs"]["LogItemsCount"]; i++)
        ExportLogItem(Project["Logs"]["LogItem"](i));
    }
    finally
    {
      ExportFile["Close"]();
    }
  }
  else
    // If the project does not contain log items,
    // post a message about this to the test log
    Log["Message"]("No logs for export.");
}

See Also

Test Results

Highlight search results