Applies to TestComplete 14.30, last modified on November 21, 2019

Description

The Log.SaveResultsAs method exports the current test log to the HTML, XML, MHT or JUnit-style format. Also, this method allows packing the test log into a ZIP archive. The exported log contains all entries posted from the test start till the SaveResultsAs method call.

If the test is run as part of a project or project suite run, you can choose whether to export the project suite, project, or test item log.

You can also export test logs manually, as explained in Exporting Test Results.

Declaration

Log.SaveResultsAs(FileNameLogFormatExportVisualizerImagesLogScope)

FileName [in]    Required    String    
LogFormat [in]    Optional    Integer Default value: 0 (XML format)   
ExportVisualizerImages [in]    Optional    Boolean Default value: True   
LogScope [in]    Optional    Integer Default value: 0 (full test log)   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

FileName

The file path (when exporting to XML or MHT) or folder path (when exporting to XML or HTML) to save the log to. If the parent folders do not exist, they will be created.

Note: For XML exporting, you can specify either a fully-qualified path to the file that will contain test results or a folder path. If you specify the folder path only, TestComplete will save test results to the Description.tcLog file in this folder.

The destination folder must be different from the location of the current run's log (Log.Path) or any of its subfolders.

LogFormat

The format of the exported log:

Constant Value Description
lsXML 0 XML format (default).

When you use the XML format for log data:

  • The LogScope parameter is ignored.

  • The FileName parameter can specify the file name for export or just a folder. See the note above.

lsHTML 1 HTML format – a web page with accompanying images, stylesheets and other data files. The FileName parameter specifies the folder to save the files. The web page name is index.htm.
lsMHT 2 MHT file – a web page archive (web page with accompanying files packed into one file). MHT files that can be viewed in Internet Explorer, but not Chrome or Firefox.
lsZip 3 ZIP format – a zip archive containing a full TestComplete log in its native format (a .tcLog file). You can view the unpacked log in this format in the Log subfolder of your project or project suite.
lsPackedHTML 4 Packed HTML format – a zip archive included an exported test log in HTML format.
lsJUnit 5 JUnit format – an XML file with a Summary report saved in the JUnit report format. You can view and process the report in any JUnit-style-compatible framework or in a tool like JUnit Viewer, xUnit Viewer, or Allure.

ExportVisualizerImages

Specifies whether to export Visualizer images. Default is True. Use False to reduce the size of the exported log.

LogScope

The scope of the log to be exported. This parameter is applicable only when your test is run as part of a project or project suite. See Test Items Page (Project Editor).

Possible values:

Constant Value Description
lesFull 0 (Default) Export the project suite log.
lesCurrentProject 1 Export the project log.
lesCurrentTestItem 2 Export the log of the current test item.

Note: When exporting to XML, this parameter is ignored and always set to lesFull.

For example, if you have a project suite with several projects and you want to export the results of each project to a separate file, add the SaveResultsAs method with the LogScope parameter set to lesCurrentProject to the last test item of each project.

If you have a project with several test items, to export results of each test item to a separate file, you can call the SaveResultsAs method with the LogScope parameter set to lesCurrentTestItem after each test item run, for example, from the OnStopTest event handler.

Result Value

True if the test log is exported successfully and False otherwise.

Remarks

  • Images are exported in the format specified by the Image format project option.

  • In HTML and MHT logs, links posted by Log.Link are handled as follows:

    • Web and FTP links (starting with http://, https://, www or ftp://) are included. Links without the protocol (for example, mysite.com) are not included.
    • File links (C:\MyFile.txt, \\server\folder\file.txt) are included, and these files are copied to the exported log.
    • Other links (for example, mailto:) are not included in exported logs – the Link column will be empty.

Example

Export to MHT (Single File)

This example shows how you can export the test results to the MHT file:

JavaScript, JScript

function Test()
{
  // Do something
  // ...

  Log.SaveResultsAs("C:\\Work\\Log.mht", lsMHT);
}

Python

def Test():
  # Do something
  # ...
  Log.SaveResultsAs("C:\\Work\\Log.mht", lsMHT)

VBScript

Sub Test
  ' Do something
  ' ...

  Call Log.SaveResultsAs("C:\Work\Log.mht", lsMHT)
End Sub

DelphiScript

procedure Test;
begin
  // Do something
  // ...

  Log.SaveResultsAs('C:\Work\Log.mht', lsMHT);
end;

C++Script, C#Script

function Test()
{
  // Do something
  // ...

  Log["SaveResultsAs"]("C:\\Work\\Log.mht", lsMHT);
}

Export to HTML

This example shows how you can export the results of the entire project run to the HTML file format:

JavaScript, JScript

function Test()
{
  // Do something
  // ...

  Log.SaveResultsAs("C:\\Work\\Log\\Project1\\", lsHTML, true, 1); // Files are created in the Project1 folder
}

Python

def Test1():
  # Do something
  # ...
  Log.SaveResultsAs("C:\\Work\\Log\\Project1\\", lsHTML, true, 1) # Files are created in the Project1 folder

VBScript

Sub Test
  ' Do something
  ' ...

  Call Log.SaveResultsAs("C:\Work\Log\Project1\", lsHTML, true, 1) ' Files are created in the Project1 folder
End Sub

DelphiScript

procedure Test;
begin
  // Do something
  // ...

  Log.SaveResultsAs('C:\Work\Log\Project1\', lsHTML, true, 1); // Files are created in the Project1 folder
end;

C++Script, C#Script

function Test()
{
  // Do something
  // ...

  Log["SaveResultsAs"]("C:\\Work\\Log\\Project1\\", lsHTML, true, 1); // Files are created in the Project1 folder
}

See Also

Exporting Test Results
Exported Results Structure
Test Results
Integration.Integration.ExportResults
Log.Path Property

Highlight search results