Getting Access to Stored Images

Applies to TestComplete 15.40, last modified on July 05, 2022

The images stored to the Regions collection of the Stores project item are typically used for comparison or finding purposes, for instance, a stored image can be a baseline image with which you compare your application’s window, or it can be a small image, which you search for in an application’s window.

Accessing Regions Collection Elements

To obtain a stored image for comparison or finding purposes, use the name of the image in the Regions collection.

For instance, the following code compares a stored image with an active window:

JavaScript, JScript

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

Python

w = Sys.Desktop.ActiveWindow()
if not Regions.Compare("MyStoredImage", w):
  Log.Error("The compared regions are not identical.", w.Name)

VBScript

Set w = Sys.Desktop.ActiveWindow
If Not Regions.Compare("MyStoredImage", w) Then
  Log.Error "The compared regions are not identical.", w.Name
End If

DelphiScript

var w;
begin
  w := Sys.Desktop.ActiveWindow;
  if not Regions.Compare('MyStoredImage', w) then
    Log.Error('The compared regions are not identical.', w.Name);
end;

C++Script, C#Script

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

TestComplete treats images from the Regions collection as instances of the Region object, so you can refer to the images using their names as script identifiers.

Note: The names of images in the Regions collection must be valid script identifiers for all scripting languages supported by TestComplete. To specify a name that matches any language, start the name with a letter and use only letters, digits and underscore characters.

For instance, the following code obtains a stored image using its name as an identifier and compares the image with an active window:

JavaScript, JScript

var w = Sys.Desktop.ActiveWindow();
if(! Regions.MyStoredImage.Check(w))
  Log.Error("The compared regions are not identical.", w.Name);

Python

w = Sys.Desktop.ActiveWindow()
if not Regions.MyStoredImage.Check(w):
  Log.Error("The compared regions are not identical.", w.Name)

VBScript

Set w = Sys.Desktop.ActiveWindow
If Not Regions.MyStoredImage.Check(w) Then
  Log.Error "The compared regions are not identical.", w.Name
End If

DelphiScript

var w;
begin
  w := Sys.Desktop.ActiveWindow;
  if not Regions.MyStoredImage.Check(w) then
    Log.Error('The compared regions are not identical.', w.Name);
end;

C++Script, C#Script

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

To simplify the creation of comparison code, you can use the Checkpoint wizard. See also About Region Checkpoints.

Obtaining Pictures Corresponding to Regions Collection Elements

In some cases, you may need to obtain a Picture object that corresponds to a stored image. For instance, this object is necessary:

  • To compare two stored images.

  • To search a stored image within another stored image.

  • To search the image for a text by using optical character recognition.

To obtain the Picture object for a stored image, use the GetPicture method of the Regions object. This method returns a Picture object for a stored image that is specified by the image’s name:

JavaScript, JScript

var PictureObject = Regions.GetPicture("MyImage");

Python

PictureObject = Regions.GetPicture("MyImage")

VBScript

Set PictureObject = Regions.GetPicture("MyImage")

DelphiScript

var PictureObject;
begin
  …
  PictureObject := Regions.GetPicture('MyImage');
  …
end;

C++Script, C#Script

var PictureObject = Regions["GetPicture"]("MyImage");

After you have obtained an image, you can use it for comparison and search operations. See the following topics for more information:

See Also

About Regions Collection
About Region Checkpoints

Highlight search results