Capturing Images for Simulated User Actions

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

About

When creating or debugging tests, it may be difficult to determine the state of the tested windows and controls before a test command is executed. To make it easier for you to determine it, TestLeft includes Visualizer – a subsystem that automatically captures images of the tested application's windows during the test run.

You can see the captured images in the test log that TestLeft generates during the test run. It differs from the log that your unit testing framework generates (if you are using a unit testing framework):

Automated testing with TestLeft: Automatically captured images in the test log

Click the image to enlarge it.

As you can see, TestLeft logs a message for each test command that simulates user actions, and the captured screenshots are on the Details tab.

Note:

  • TestLeft captures images for any method that simulates user actions like keystrokes, mouse clicks, menu item selection and so on. It captures images before executing the method. That is, an image in the log recorded for some command shows the screen or window state before that command is executed.

  • The captured images have the PNG-24 format.

  • TestLeft stores the captured images in the test log folder.

  • You use Visualizer options to enable or disable the Visualizer functionality during the test run. See below.

    Also, you can use the options to control if Visualizer captures images of the entire screen or images of the top-level windows only. See below.

When to Use Visualizer

Some unit testing frameworks remove TestLeft log files automatically for successful tests, some others do not do this and always store the log files. So, the captured images can take up a lot of space on your hard drive. This can happen even if your tests are not large – you may have lots of smaller tests that run frequently.

To avoid unneeded consumption of hard drive space, Visualizer is disabled by default. If needed, you can enable it in your tests. We recommend that you do this in the following cases:

  • When you run your test for debugging purposes. The captured images will help you retrace the test steps and to understand what happened in the system and in the tested application. Also, if needed, you can attach images to a bug report.

  • When you are creating a test or learning the product. The images may help you understand the test actions better.

  • When you need to capture images for certain test commands only. You can enable or disable Visualizer one or multiple times during the test run to capture images for certain parts of your test only.

Enabling and Disabling Visualizer

Visualizer is disabled by default to save the hard drive space (see above). To enable it, use –

.NET: The Driver.Options.Visualizer.CollectTestVisualizer property.

Java: The driver.getOptions().getVisualizer().getCollectTestVisualizer method.

C#

using SmartBear.TestLeft.Options;

...

public void MyTest()
{

 // Place this code at the beginning of your test, or
 // before the test commands for which you would like to capture images.
 Driver.Options.Visualizer.CollectTestVisualizer =
                VisualizerSettings.VisualizerMode.CaptureImages;

 ...

}

Visual Basic .NET

Imports SmartBear.TestLeft.Options

...

Public Sub MyTest()

 ' Place this code at the beginning of your test, or
 ' before the test commands for which you would like to capture images.
 Driver.Options.Visualizer.CollectTestVisualizer =
                VisualizerSettings.VisualizerMode.CaptureImages

 ...

End Sub

Java

import com.smartbear.testleft.options.VisualizerMode;

...

public void MyTest() {

 // Place this code at the beginning of your test, or
 // before the test commands for which you would like to capture images.
 driver.getOptions().getVisualizer().setCollectTestVisualizer(VisualizerMode.CaptureImages);

 ...

}

To disable Visualizer, use code like this one:

C#

using SmartBear.TestLeft.Options;

...

public void MyTest()
{

 ...

 Driver.Options.Visualizer.CollectTestVisualizer =
                VisualizerSettings.VisualizerMode.Off;

 ...

}

Visual Basic .NET

Imports SmartBear.TestLeft.Options

...

Public Sub MyTest()

 ...

 Driver.Options.Visualizer.CollectTestVisualizer =
                VisualizerSettings.VisualizerMode.Off

 ...

End Sub

Java

import com.smartbear.testleft.options.VisualizerSettings;

...

public void MyTest() {

 ...

 driver.getOptions().getVisualizer().setCollectTestVisualizer(VisualizerMode.Off);

 ...

}

Options

To access Visualizer options, use the Driver.Options.Visualizer property. It returns the VisualizerSettings class that declares helper enumeration types and has two properties for controlling the Visualizer behavior:

Property Description
Driver.Options.Visualizer.CollectTestVisualizer Enables or disables Visualizer (see above).
Should be one of the values of the SmartBear.TestLeft.Options.VisualizerSettings.VisualizerMode enumeration type.
Driver.Options.Visualizer.ImageCaptureStyle Specifies whether Visualizer captures the entire screen or the top-level window of the control on which a test command is going to perform a user action.
Should be one of the values of the SmartBear.TestLeft.Options.VisualizerSettings.CaptureStyle enumeration type.

To access Visualizer options, use the driver.getOptions().getVisualizer() method. It returns the VisualizerSettings class that declares helper enumeration types and the following methods for controlling the Visualizer behavior:

Method Description
driver.getOptions().getVisualizer().getCollectTestVisualizer Returns a value that specifies whether the Visualizer is enabled or disabled.
driver.getOptions().getVisualizer().setCollectTestVisualizer Enables or disables Visualizer (see above).
Should be one of the values of the VisualizerMode enumeration type.
driver.getOptions().getVisualizer().getImageCaptureStyle Returns a value that specifies whether the Visualizer captures the entire screen or the top-level window of the control.
driver.getOptions().getVisualizer().setImageCaptureStyle Specifies whether Visualizer captures the entire screen or the top-level window of the control on which a test command is going to perform a user action.
Should be one of the values of the CaptureStyle enumeration type.

See Also

Creating TestLeft Tests
Running TestLeft Tests

Highlight search results