Regions Object

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

Description

The Regions object allows you to manage and process images (more precisely, regions of images) that are stored in the Regions section of the Stores collection from your scripts. For example, compare two images, find one image within another, add an image to the collection, update the image stored in the collection and so on.

The Regions object can work with:

  • Image regions that are represented by Picture objects.
  • Objects that have the Picture method which returns a Picture object.

The Regions object contains properties that correspond to the images added to the Stores | Regions collection. The property names coincide with the names of the child images. Each property returns a Region object that corresponds to an appropriate child image. For instance, the following code provides access to the element named Pic1:

JavaScript, JScript

var RegionObj1 = Regions.Pic1;

Python

RegionObj1 = Regions.Pic1

VBScript

Set RegionObj1 = Regions.Pic1

DelphiScript

var
  RegionObj1 : OleVariant;
begin
  RegionObj1 := Regions.Pic1;
end;

C++Script, C#Script

var RegionObj1 = Regions["Pic1"];

Requirements

The Regions object is available only if your project contains the Stores | Regions collection.

Members

Example

The following code saves an image of the application’s MainForm object to the Regions collection and then compares the stored image to the active window:

JavaScript, JScript

function Test()
{
  var w1, w2;
  
  w1 = Sys.Process("MyApp").Window("MyWndClass", "MyWndCaption", 1);
  Regions.AddPicture(w1, "MyAppWnd");
  w2 = Sys.Desktop.ActiveWindow();
  if(! Regions.Compare("MyAppWnd", w2))
  // -- or --
  // if (! Regions.MyAppWnd.Check(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):
  # -- or -- 
  # if not Regions.MyAppWnd.Check(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
  ' -- or --
  ' If Not Regions.MyAppWnd.Check(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
  // -- or --
  // if not Regions.MyAppWnd.Check(w2) then
    Log.Error('The compared regions are not identical.', w2.Name);
end;

C++Script, C#Script

function Test()
{
  var w1, w2;
  
  w1 = Sys["Process"]("MyApp")["Window"]("MyWndClass", "MyWndCaption", 1);
  Regions["AddPicture"](w1, "MyAppWnd");
  w2 = Sys["Desktop"]["ActiveWindow"]();
  if(! Regions["Compare"]("MyAppWnd", w2))
  // -- or --
  // if (! Regions["MyAppWnd"]["Check"](w2))
    Log["Error"]("The compared regions are not identical.", w2.Name);
}

See Also

Files Object
Objects Object
Stores
About Regions Collection
Picture Object
Region Object

Highlight search results