Posting Messages and Images to the Log

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

In addition to the informationTestLeft posts to the test log during the test run by default, you can post custom entries (messages and images) to the log.

To work with the test log, you use the methods of the Log object. You get a reference to this object in your test through –

.NET: IDriver.Log property.

Java: driver.getLog method.

Log Methods

Method Description
IDriver.Log.Message Posts an informative message to the log.
IDriver.Log.Error Posts an error message to the log.
IDriver.Log.Warning Posts a warning message to the log.
IDriver.Log.Screenshot Posts a screenshot of the specified test object (window or control) to the log. Accepts objects that implement the SmartBear.TestLeft.TestObjects.IVisualObject interface.
IDriver.Log.Picture Posts an arbitrary image to the log. Accepts System.Drawing.Image objects.

For each message, you can specify additional text that TestLeft will post to the Details panel of the test log. The text can include HTML markup.

You can find images that the appropriate methods post to the test log in the Picture panel of the log.

Note: To log an image of a control, window or entire desktop, we recommend using the IDriver.Log.Screenshot method where possible. The IDriver.Log.Picture method is needed to log arbitrary images, for example, those that your test loads from a file. Some methods of the TestLeft library return images as System.Drawing.Image objects, so you can use the Picture method to post these images to the log.

Method Description
driver.getLog().message Posts an informative message to the log.
driver.getLog().error Posts an error message to the log.
driver.getLog().warning Posts a warning message to the log.
driver.getLog().screenshot Posts a screenshot of the specified test object (window or control) to the log. Accepts objects that implement the com.smartbear.testleft.testobjects.VisualObject class.
driver.getLog().picture Posts an arbitrary image to the log. Accepts java.awt.image.BufferedImage objects.

For each message, you can specify additional text that TestLeft will post to the Details panel of the test log. The text can include HTML markup.

You can view images that the appropriate methods post to the test log in the Picture panel of the log.

Note: To log an image of a control, window or entire desktop, we recommend using the driver.getLog().screenshot method where possible. The driver.getLog().picture method is needed to log arbitrary images, for example, those that your test loads from a file. Some methods of the TestLeft library return images as BufferedImage objects, so you can use the picture method to post these images to the log.

For each message, you can specify additional text that TestLeft will post to the Details panel of the test log. The text can include HTML markup.

You can find images that the appropriate methods post to the test log in the Picture panel of the log.

Note: If you need to log an image of a control, window or entire desktop, we recommend using the Screenshot method where possible. The Picture method is needed to log arbitrary images, for example, those that your test loads from a file. Some methods of the TestLeft library returns images as System.Drawing.Image or BufferedImage objects, so you can use the Picture method to post these images to the log.

Example 1

The code below demonstrates how to post messages of various types to the TestLeft log:

C#

using SmartBear.TestLeft;

public void Test()
{

  // Post a message
  Driver.Log.Message("Message");

  // Post a warning
  Driver.Log.Warning("Warning");

  // Post an error
  Driver.Log.Error("Error");
}

Visual Basic .NET

Imports SmartBear.TestLeft


Public Sub Test()

  ' Post a message
  Driver.Log.Message("Message")

  ' Post a warning
  Driver.Log.Warning("Warning")

  ' Post an error
  Driver.Log.Error("Error")
End Sub

Java

import com.smartbear.testleft.*;


public void Test() throws Exception{

  // Post a message
  driver.getLog().message("Message");

  // Post a warning
  driver.getLog().warning("Warning");

  // Post an error
  driver.getLog().error("Error");
}

Example 2

The following code demonstrates how you can post an image of a control to the test log:

C#

using SmartBear.TestLeft;
using System.Drawing;

public void Test()
{

  // Start tested application
  IProcess notepad = Driver.Applications.Run(@"C:\Windows\notepad.exe");
  // Get a test object (control)
  ITopLevelWindow wndNotepad = notepad.Find<ITopLevelWindow>(new WindowPattern()
  {
    WndClass = "Notepad"
  });

  // Post the object image to the log
  Driver.Log.Screenshot(wndNotepad, "A screenshot");
}

Visual Basic .NET

Imports SmartBear.TestLeft
Imports System.Drawing


Public Sub Test()

  ' Start tested application
  Dim notepad As IProcess = Driver.Applications.Run("notepad.exe")
  ' Get a test object (control)
  Dim wndNotepad As ITopLevelWindow = notepad.Find(Of ITopLevelWindow)(New WindowPattern() With {
            .WndClass = "Notepad"
  })

  ' Post the object image to the test log
  Driver.Log.Screenshot(wndNotepad, "Screenshot")
End Sub

Java

import com.smartbear.TestLeft.*;


public void Test() throws Exception{

  // Start a tested application
  TestProcess notepad = driver.getApplications().run("notepad.exe");
  // Get a test object (control)
  TopLevelWindow wndNotepad = notepad.find(TopLevelWindow.class, new WindowPattern() {{
    WndClass = "Notepad";
  }});

  // Post the object image to the test log
  driver.getLog().screenshot(wndNotepad, "Screenshot");
}

Example 3

For messages you post to the test log, you can specify additional text that will be posted to the Details panel. It can be either plain text or HTML code. The test engine will compile the HTML code and show it in the panel:

In order for TestLeft to recognize the additional text as HTML code, the text must start with a tag.

C#

using SmartBear.TestLeft;


public void Test()
{

  string str = "Message text";
  string exStr = "<b>Details</b> Text";
  Driver.Log.Message(str, exStr);

}

Visual Basic .NET

Imports SmartBear.TestLeft


Public Sub Test()

  Dim str As String = "Message text"
  Dim exStr As String = "<b>Details</b> Text"

  Driver.Log.Message(str, exStr)

End Sub

Java

import com.smartbear.testleft.*;


public void Test() throws Exception{

  String str = "Message text";
  String exStr = "<b>Details</b> Text";

  driver.getLog().message(str, exStr);

}

See Also

Working With TestLeft Test Logs
About Driver Objects

Highlight search results