Adding Images to the Regions Collection

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

The Regions collection of the Stores project item contains a list of BMP, JPEG, PNG, TIFF, GIF or ICO images (if an ICO file contains several images, TestComplete uploads only one of them - the largest one with the highest color depth) that can be used during application testing. For instance, your test can compare bitmaps with any onscreen object (the screen, window or a window area).

You can add images to the Regions collection in several ways:

Adding images from the Project Explorer

  1. Right-click the Stores > Regions node in the Project Explorer and then select Add > New Item from the context menu.

  2. In the ensuing Add Image wizard, you can capture the desired image, or add the image file to your project.

Adding images from the Regions editor

  1. Right-click the Stores > Regions node in the Project Explorer panel and select Edit from the context menu. TestComplete will open the Regions editor in the Workspace panel.

  2. Right-click somewhere within the editor and choose New Item from the context menu.

  3. In the ensuing Add Image wizard, you can capture the desired image, or add the image file to your project.

Adding images when creating checkpoints

  1. During test recording, click Add Check on the Recording toolbar and then select Image in the resulting wizard.

    – or–

    In a keyword test, add the Region Checkpoint operation to the test at design time.

    – or –

    In a script test, click Add Checkpoint on the Code Editor toolbar and then select Image in the resulting wizard.

  2. In the Checkpoint wizard, select the object, whose image you want to store, specify the checkpoint options.

  3. TestComplete will add the appropriate image of the selected object to the Regions collection automatically.

Adding images during test recording

You can add an image of a window, screen or an arbitrary rectangles to the Regions collection during test recording. To do this, create a region checkpoint that will verify the desired window, rectangle or entire screen. Using the checkpoint creation wizard, you can append the current image of the window, screen or rectangle to the Regions collection. See the previous section for more information on this.

Adding images from keyword tests and scripts

To add an image to the Regions collection from your keyword test or script, use the SaveToFile method of the Picture object. This function saves an onscreen object to an image file in one of the supported formats (the format is specified by the file extension. See the method description).

To add an existing image file from your disk, call Regions.Add. An even simpler way is to use the Regions.AddPicture method to save an image to a file and then add this file to the Regions collection.

For instance, the following code saves a region of an active window to a .bmp file in the project’s folder and adds the file to the project’s Regions collection (note that if the Regions collection already has an element with the specified name, the element’s file will be overwritten).

JavaScript, JScript

var w;
w = Sys.Desktop.ActiveWindow().Picture(20, 20, 50, 50);
// To save the entire window, use
// w = Sys.Desktop.ActiveWindow();
Regions.AddPicture(w, "MyFile.bmp");

Python

w = Sys.Desktop.ActiveWindow().Picture(20, 20, 50, 50)
# To save the entire window, use
# w = Sys.Desktop.ActiveWindow()
Regions.AddPicture(w, "MyFile.bmp")

VBScript

Set w = Sys.Desktop.ActiveWindow.Picture(20, 20, 50, 50)
' To save the entire window, use
' Set w = Sys.Desktop.ActiveWindow
Regions.AddPicture w, "MyFile.bmp"

DelphiScript

var w : OleVariant;

w := Sys.Desktop.ActiveWindow.Picture(20, 20, 50, 50);
// To save the entire window, use
// w := Sys.Desktop.ActiveWindow;
Regions.AddPicture(w, 'MyFile.bmp');

C++Script, C#Script

var w;
w = Sys["Desktop"]["ActiveWindow"]()["Picture"](20, 20, 50, 50);
// To save the entire window, use
// w = Sys["Desktop"][ActiveWindow"]();
Regions["AddPicture"](w, "MyFile.bmp");

Note that the above code does not depend on the window type. It can save popup windows as well as top-level ones. For more information on operations with images, see Regions Object and Picture Object.

To execute the code above and perform other operations with the Regions and Picture objects from keyword tests, use the Call Object Method, Run Code Snippet or Run Script Routine operation.

Adding images from the Image Viewer

TestComplete includes a built-in image viewer that is used to display images in various situations. For instance, the Image Viewer is used to view images posted to the test log.

To add an image to the Regions collection from the Image Viewer:

  • Click Add Image to Stores on the toolbar of the Image Viewer and then specify the image name in the ensuing dialog.


After you have added a window to the Regions collection, you can compare it with other images, find it in another image or search for an image in it and so on. For more information, please see About Region Checkpoints.

See Also

About Regions Collection
About Regions Editor
Regions Object
Picture Object

Highlight search results