Format Property

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

Description

The Format property returns the format of the text represented by the given TextLogDataObj object. To obtain the text itself, use the Text property.

Declaration

TextLogDataObj.Format

Read-Only Property Integer
TextLogDataObj An expression, variable or parameter that specifies a reference to a TextLogData object

Applies To

The property is applied to the following object:

Property Value

One of the following values:

Constant Value Description
ltfPlain 0 Plain text
ltfHTML 1 HTML
ltfXML 2 XML
ltfURL 3 Hyperlink

Example

The following example demonstrates how you can obtain the text stored in the test log and define the format of this text.

JavaScript

function ExportTest()
{

  var Logs, LogItem, DataSet, ExportFileName, Format;

  // Obtains project logs
  Logs = Project.Logs;
  // Obtains the desired log item
  LogItem = Logs.LogItem(0);
  // Obtains a dataset stored in the log
  DataSet = LogItem.Data(1);

  // Checks if the dataset stores text data
  if (DataSet.Scheme.DataType == ldtText)

    {
    // Defines the text format and selects an appropriate external file to export the text to
    switch(DataSet.Format)
      {
      case ltfPlain:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt";
        break;
      case ltfHTML:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.html";
        break;
      case ltfXML:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.xml";
        break;
      case ltfURL:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt";
        break;
      }

    // Exports the text from the log to the external file
    FS = getActiveXObject("Scripting.FileSystemObject");
    ExportFile = FS.CreateTextFile(ExportFileName, true);
    ExportFile.WriteLine(DataSet.Text);
    ExportFile.Close();

    }

}

JScript

function ExportTest()
{

  var Logs, LogItem, DataSet, ExportFileName, Format;

  // Obtains project logs
  Logs = Project.Logs;
  // Obtains the desired log item
  LogItem = Logs.LogItem(0);
  // Obtains a dataset stored in the log
  DataSet = LogItem.Data(1);

  // Checks if the dataset stores text data
  if (DataSet.Scheme.DataType == ldtText)

    {
    // Defines the text format and selects an appropriate external file to export the text to
    switch(DataSet.Format)
      {
      case ltfPlain:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt";
        break;
      case ltfHTML:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.html";
        break;
      case ltfXML:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.xml";
        break;
      case ltfURL:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt";
        break;
      }

    // Exports the text from the log to the external file
    FS = Sys.OleObject("Scripting.FileSystemObject");
    ExportFile = FS.CreateTextFile(ExportFileName, true);
    ExportFile.WriteLine(DataSet.Text);
    ExportFile.Close();

    }

}

Python

def ExportTest():
  ExportFileName = ""
  # Obtains project logs 
  Logs = Project.Logs
  # Obtains the desired log item 
  LogItem = Logs.LogItem[0]
  # Obtains a dataset stored in the log 
  DataSet = LogItem.Data[1]
  # Checks if the dataset stores text data 
  if DataSet.Scheme.DataType == ldtText:
    # Defines the text format and selects an appropriate external file to export the text to
    if DataSet.Format == ltfPlain:
      ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt"
    elif DataSet.Format == ltfHTML:
      ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.html"
    elif DataSet.Format == ltfXML:
      ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.xml"
    elif DataSet.Format == ltfURL:
      ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt"
  # Exports the text from the log to the external file 
  FS = Sys.OleObject["Scripting.FileSystemObject"]
  ExportFile = FS.CreateTextFile(ExportFileName, True)
  ExportFile.WriteLine(DataSet.Text)
  ExportFile.Close()

VBScript

Sub ExportTest

  Dim Logs, LogItem, DataSet, ExportFileName, Format

  ' Obtains project logs
  Set Logs = Project.Logs
  ' Obtains the desired log item
  Set LogItem = Logs.LogItem(0)
  ' Obtains a dataset stored in the log
  Set DataSet = LogItem.Data(1)

  ' Checks if the dataset stores text data
  If DataSet.Scheme.DataType = ldtText Then

    ' Defines the text format and selects an appropriate external file to export the text to
    Select Case DataSet.Format
      Case ltfPlain   ExportFileName = "D:\Work Folder\ExportedLog\ExportLog.txt"
      Case ltfHTML    ExportFileName = "D:\Work Folder\ExportedLog\ExportLog.html"
      Case ltfXML     ExportFileName = "D:\Work Folder\ExportedLog\ExportLog.xml"
      Case ltfURL     ExportFileName = "D:\Work Folder\ExportedLog\ExportLog.txt"
    End Select

    ' Exports the text from the log to the external file
    Set FS = Sys.OleObject("Scripting.FileSystemObject")
    Set ExportFile = FS.CreateTextFile(ExportFileName, True)
    ExportFile.WriteLine DataSet.Text
    ExportFile.Close

    End If

End Sub

DelphiScript

procedure ExportTest();
var Logs, LogItem, DataSet, ExportFileName, Format, ExportFile;

begin

  // Obtains project logs
  Logs := Project.Logs;
  // Obtains the desired log item
  LogItem := Logs.LogItem(0);
  // Obtains a dataset stored in the log
  DataSet := LogItem.Data(1);

  // Checks if the dataset stores text data
  if DataSet.Scheme.DataType = ldtText then

    begin
    // Defines the text format and selects an appropriate external file to export the text to
    case DataSet.Format of
      ltfPlain:    ExportFileName := 'D:\Work Folder\ExportedLog\ExportLog.txt';
      ltfHTML:     ExportFileName := 'D:\Work Folder\ExportedLog\ExportLog.html';
      ltfXML:      ExportFileName := 'D:\Work Folder\ExportedLog\ExportLog.xml';
      ltfURL:      ExportFileName := 'D:\Work Folder\ExportedLog\ExportLog.txt';
    end;

    // Exports the text from the log to the external file
    AssignFile(ExportFile, ExportFileName);
    Rewrite(ExportFile);
    WriteLn(ExportFile, DataSet.Text);
    CloseFile(ExportFile);

    end;

end;

C++Script, C#Script

function ExportTest()
{

  var Logs, LogItem, DataSet, ExportFileName, Format;

  // Obtains project logs
  Logs = Project["Logs"];
  // Obtains the desired log item
  LogItem = Logs["LogItem"](0);
  // Obtains a dataset stored in the log
  DataSet = LogItem["Data"](1);

  // Checks if the dataset stores text data
  if (DataSet["Scheme"]["DataType"] == ldtText)

    {
    // Defines the text format and selects an appropriate external file to export the text to
    switch(DataSet["Format"])
      {
      case ltfPlain:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt";
        break;
      case ltfHTML:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.html";
        break;
      case ltfXML:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.xml";
        break;
      case ltfURL:
        ExportFileName = "D:\\Work Folder\\ExportedLog\\ExportLog.txt";
        break;
      }

    // Exports the text from the log to the external file
    FS = Sys["OleObject"]("Scripting.FileSystemObject");
    ExportFile = FS["CreateTextFile"](ExportFileName, true);
    ExportFile["WriteLine"](DataSet["Text"]);
    ExportFile["Close"]();

    }

}

See Also

Access Test Log Contents from Tests
Text Property

Highlight search results