Let's suppose you need to compare windows images or those of controls elements with some dynamic contents (that is, if part of the image is being changed every time). This could be the case when a given controls element displays current date or time. In this situation, the image would be different every time; nonetheless, there is a way to resolve this holdup.
First we will do some preparations:
var wCalc = Sys.Process("CalcPlus").Window("SciCalc"); Regions.AddPicture(wCalc.Picture(), "Calculator");
var wCalc = Sys.Process("CalcPlus").Window("SciCalc"); Regions.Compare("Calculator", wCalc.Picture());
Now we are going to prepare the image so that we can compare it by performing the following steps:
Regions.AddPicture
(it is located in the folder with the project, subfolder to Regions
).var wCalc = Sys.Process("CalcPlus").Window("SciCalc"); Regions.Compare("Calculator", wCalc.Picture(), true);
If the Transparent
parameter (the third parameter of the Regions.Compare
method) would be set to true
, TestComplete reads the color of the upper-left pixel of the image and interprets the same as transparent
, that is, does not include the areas of the color in the check.
As a result, the images are considered the same, although a part of them is different.
Sometimes, it is not sufficient to add transparent areas, for example, if the dynamically changing data appears in different parts of the screen.
To resolve the task, the Regions.Compare
method has another parameter, namely that of Tolerance
. This should be an integer number, which is the maximal number of the different pixels. In this case, TestComplete will assume that images are the same, unless the number of the differing pixels exceeds the value of the Tolerance
parameter.
3.145.11.227