Saving Test Logs

Applies to TestLeft 15.40, last modified on March 17, 2022

TestLeft generates a full-detailed log of all actions it performs during the test run. The log can also include messages, images, and other entries.

By default, TestLeft stores the test log in a temporary folder and deletes it after the test run is over.

To view and analyze the test log, save it to an external file:

  • Add instructions to your test that will save the test log. To do this, use –

    .NET: The IDriver.Log.Save method.

    Java: The driver.getLog().save method.

    Note: In .NET, if the folder, to which you save the test log, does not exist, the IDriver.Log.Save method will create the folder.

    In Java, if the folder does not exists, the driver.getLog().save method will report an error and will not save the test log. You need to check whether the folder exists and create it manually if needed before you call the save method.

— or —

  • If you use Visual Studio, and you create your tests by using TestLeft MSTest or NUnit test templates, they will save the test log to the default test results folder automatically:

    • TestLeft NUnit tests store their logs to the TestResults folder in their current working folder.

    • TestLeft MSTest tests store their logs to the TestResults folder in their deployment folder.

      Note: MSTest clears the test results folder if the test passes. This allows reducing the amount of disk space the test results occupy. If the test fails, MSTest keeps the results so that you can view and analyze them.

      To keep TestLeft results regardless of the test status, configure MSTest not to clear the test results, or use the IDriver.Log.Save method in your test to save the test results to another location.

    Note: TestLeft xUnit tests do not save their logs automatically. Save the test logs manually (see below).

TestLeft can save its test log in one of the following formats:

  • Unpacked HTML - TestLeft will export the results to a collection of HTML, JSON, image and helper files.

  • Multipart Hypertext Storage - TestLeft will save the results to an MHT file.

The example below demonstrates how to save the test log:

C#

using SmartBear.TestLeft;


public void Test()
{

  string logPath = @"C:\Tests\Logs\";

  // Saves the test log to an MHT file
  Driver.Log.Save(logPath + "log.mht", Log.Format.Mht);

  …

  // Saves the test log to unpacked HTML files
  Driver.Log.Save(logPath, Log.Format.Html);

  …

}

Visual Basic .NET

Imports SmartBear.TestLeft


Public Sub Test()
  Dim logPath As String = "C:\Tests\Logs\"

  ' Saves the test log to an MHT file
  Driver.Log.Save(logPath & "log.mht", Log.Format.Mht)

  ' Saves the test log to unpacked HTML files
  Driver.Log.Save(logPath, Log.Format.Html)

  …

End Sub

Java

import com.smartbear.TestLeft.*;
import java.io.File;


public void Test() throws Exception{

  String logPath = "C:\\Tests\\Logs\\";

  File path = new File(logPath);
  if (! path.exists())
  {
    path.mkdir();
  }

  // Saves the test log to an MHT file
  driver.getLog().save(logPath + "log.mht", Log.Format.Mht);

  // Saves the test log to unpacked HTML files
  driver.getLog().save(logPath, Log.Format.Html);

  …

}

See Also

Working With TestLeft Test Logs
About Driver Objects

Highlight search results