Alternatives to Region Checkpoints

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

Region checkpoints in TestComplete let you verify that an onscreen object or its area in your application under test is displayed correctly. This verification is done by performing a pixel-by-pixel comparison of the actual image of the object or area with the baseline image stored in your test project’s Stores > Regions collection.

Using region checkpoints is not the only way to verify that an onscreen object in your application under test is displayed correctly. You can create a test that will obtain the image of the desired object and compare it against the baseline image using the following alternative approaches:

Use the Compare Pictures Operation and the Regions.Compare Scripting Method

In keyword tests, to compare two images and report results, use the Compare Pictures operation.

The operation is similar to the region checkpoint and uses the same image comparison algorithm (for information on how image comparison works in TestComplete, see How Image Comparison Works). The operation lets you work with images stored in the Stores > Regions collection and images of windows and onscreen objects.

If the compared images are not equal, the operation posts them to the Picture panel of the test log. You can switch the panel to the comparison mode to easily discover differences between images.

The operation’s MessageType parameter allows you to specify what kind of message (an error, warning, informative message or no message at all) will be posted to the test log if the comparison fails.

In scripts, to compare images, use the Regions.Compare method that is a scripting analog of the Compare Pictures operation.

The code below demonstrates how to add an image of the application’s MainForm window to the Stores > Regions collection and then use the Regions.Compare method to compare the stored image with an active window"

JavaScript, JScript

function Test()
{

  var w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption", 1);
  Regions.AddPicture(w1, "MyAppWnd");

  w2 = Sys.Desktop.ActiveWindow();

  if(! Regions.Compare("MyAppWnd", w2))
    Log.Error("The compared regions are not identical.", w2.Name);

}

Python

def Test():

  w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption", 1)
  Regions.AddPicture(w1, "MyAppWnd")

  w2 = Sys.Desktop.ActiveWindow()

  if not Regions.Compare("MyAppWnd", w2):
    Log.Error("The compared regions are not identical.", w2.Name)

VBScript

Sub Test

  Set w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption", 1)
  Call Regions.AddPicture(w1, "MyAppWnd")

  Set w2 = Sys.Desktop.ActiveWindow

  If Not Regions.Compare("MyAppWnd", w2) Then
    Log.Error "The compared regions are not identical.", w2.Name
  End If

End Sub

DelphiScript

procedure Test;
var
  w1, w2 : OleVariant;
begin
  w1 := Sys.Process('MyApp').Window('MyWndClass', 'MyWndCaption', 1);
  Regions.AddPicture(w1, 'MyAppWnd');

  w2 := Sys.Desktop.ActiveWindow;

  if not Regions.Compare('MyAppWnd', w2) then
    Log.Error('The compared regions are not identical.', w2.Name);

end;

C++Script, C#Script

function Test()
{

  var w1 = Sys["Process"]("MyApp")["Window"]("MyWndClass", "MyWndCaption", 1);
  Regions["AddPicture"](w1, "MyAppWnd");

  var w2 = Sys["Desktop"]["ActiveWindow"]();
  if (! Regions["Compare"]("MyAppWnd", w2))
    Log["Error"]("The compared regions are not identical.", w2.Name);

}

Use the Picture.Compare and Picture.Difference Scripting Methods

The Picture object provides scripting access to an arbitrary image in your tests. You can use the object to access images stored in the Stores > Regions collection, images returned by the OnscreenObject.Picture method or images loaded from external files.

To compare images in scripts, use the Picture.Compare and Picture.Difference methods.

The Picture.Compare method compares two images pixel by pixel and returns a Boolean value that indicates whether the images are equal or not. The Picture.Difference method compares two images and returns an image indicating differences between compared images.

The following code snippet demonstrates how to use these methods to compare images. One of the images is a fragment of an application window, the other one is an image loaded from an external image file. After the comparison we call Log.Picture to post the compared image to the log since the Picture.Compare method does not post these images automatically.

JavaScript, JScript

function Test()
{

  var w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption");
  var pict1 = w1.Picture(10, 10, 100, 100, false);

  var pict2 = Utils.Picture;
  pict2.LoadFromFile("C:\\Work Folder\\Image.png");

  // Compares the fragment of an application window with the pict2 image

  if (! pict1.Compare(pict2))
  {
    Log.Picture(pict1);
    Log.Picture(pict2);
    // Obtains the image indicating the difference between compared images
    var pictd = pict1.Difference(pict2);
    Log.Picture(pictd);
    Log.Error("The compared regions are not identical.");
  }

}

Python

def Test():

  w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption")
  pict1 = w1.Picture(10, 10, 100, 100, False)

  pict2 = Utils.Picture
  pict2.LoadFromFile("C:\\Work Folder\\Image.png")

  # Compares the fragment of an application window with the pict2 image

  if not pict1.Compare(pict2):
    Log.Picture(pict1)
    Log.Picture(pict2)
    # Obtains the image indicating the difference between compared images
    pictd = pict1.Difference(pict2)
    Log.Picture(pictd)
    Log.Error("The compared regions are not identical.")

VBScript

Sub Test

  Set w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption")
  Set pict1 = w1.Picture(10, 10, 100, 100, false)

  Set pict2 = Utils.Picture
  pict2.LoadFromFile("C:\Work Folder\Image.png")

  ' Compares the fragment of an application window with the pict2 image

  If Not pict1.Compare(pict2) Then
    Log.Picture(pict1)
    Log.Picture(pict2)
    ' Obtains the image indicating the difference between compared images
    Set pictd = pict1.Difference(pict2)
    Log.Picture(pictd)
    Log.Error("The compared regions are not identical.")
  End If

End Sub

DelphiScript

procedure Test();
var w1, pict1, pict2, pictd : OleVariant;
begin

  w1 := Sys.Process('MyApp').Window('MyWndClass', 'MyWndCaption');
  pict1 := w1.Picture(10, 10, 100, 100, false);

  pict2 := Utils.Picture;
  pict2.LoadFromFile('C:\Work Folder\Image.png');

  // Compares the fragment of an application window with the pict2 image

  if not pict1.Compare(pict2) then
  begin
    Log.Picture(pict1);
    Log.Picture(pict2);
    // Obtains the image indicating the difference between compared images
    pictd := pict1.Difference(pict2);
    Log.Picture(pictd);
    Log.Error('The compared regions are not identical.');
  end;

end;

C++Script, C#Script

function Test()
{

  var w1 = Sys["Process"]("MyApp")["Window"]("MyWndClass", "MyWndCaption");
  var pict1 = w1["Picture"](10, 10, 100, 100, false);

  var pict2 = Utils["Picture"];
  pict2["LoadFromFile"]("C:\\Work Folder\\Image.png");

  // Compares the fragment of an application window with the pict2 image

  if (! pict1["Compare"](pict2))
  {
    Log["Picture"](pict1);
    Log["Picture"](pict2);
    // Obtains the image indicating the difference between compared images
    var pictd = pict1["Difference"](pict2);
    Log["Picture"](pictd);
    Log["Error"]("The compared regions are not identical.");
  }

}

To call these methods from a keyword test, use the Call Object Method, Run Code Snippet or Run Script Routine operation.

Create a Custom Comparison Procedure

The Picture object provides a scripting interface to images in your tests. The Picture.Size property lets you obtain the width and height (in pixels) of the relevant image. The Picture object also provides access to individual pixels within the image. It includes the Pixels property that returns the color of the specified image pixel.

Using these properties, you can create a custom pixel-to-pixel comparison algorithm.

Note: Intel CPUs use the little endian convention for data. That is, in fact, the color is stored as BGR in memory.

See Also

Region Checkpoints
About Region Checkpoints
Creating Region Checkpoints
How Image Comparison Works
Comparing and Finding Images - Specific Tasks

Highlight search results