Use the Compare Pictures operation to compare two images.
The operation compares images pixel by pixel. If the images are identical, the operation returns True and posts an informative message to the test log. Otherwise, it returns False and posts a message, whose type is specified by the MessageType parameter. It also posts the baseline image and the image compared with the baseline one to the Picture panel. Switching to the Comparison mode in the Picture panel allows you to view the difference between the images.
You can also use the operation to update images stored in the Stores | Regions collection with the actual application data. The operation’s functioning mode is specified by the Update regions setting (you can modify it in the Stores Options dialog). By default, the setting is disabled and the operation performs comparison only. To use the operation for updating a stored image, enable the setting and check the Update box for the image in the Regions editor. If the setting is enabled, but the Update check box is clear, the operation works in comparison mode.
The operation can compare or update images of the following formats:
In the comparison mode, if the comparison procedure reports that the images are identical, the operation returns True and posts an informative message to the test log. Otherwise, the operation returns False, posts the corresponding message to the test log (the type of the message is specified by the MessageType parameter) and posts both images to the Picture panel of the test log.
In the update mode, the operation always returns True and posts a successful message to the test log.
The operation is an analogue of the
Regions.Compare scripting method.
The operation cannot have child operations.
The Compare Pictures operation uses the following parameters:
Picture1 and Picture2
The name of the Regions collection’s item (if the image is stored in this collection of your project).
An expression that returns the
RegionInfoobject or a value that holds a reference to this object.
An expression that returns the
Pictureobject or the value that holds a reference to this object.
The fully-qualified name of the image file on the hard drive.
If the operation works in update mode, then one of the parameters must specify an item of the Regions collection and the other can be a
False by default. If it is True, then the top left pixel of the Picture1 image is treated as the “transparent” (background) color in this image, so, any transparent pixels in the first image are excluded from comparison.
The Mouse parameter specifies whether the mouse pointer is included in the image you want to compare. By default, this parameter is False. If it is True, and the Picture parameters specify an object (for example, a
RegionInfo object) with the mouse pointer over this object, then the mouse pointer is included in the image. The operation returns True only if the other image contains the image of the mouse pointer in the same position.
After the comparison is over, TestComplete posts two images to the test log: the expected and the actual one. You can also obtain the difference between these images. For this purpose, click the Comparison Mode button in the Actual Image section of the Picture panel. This picture shows the difference between the images.The following color highlighting is used:
- Identical pixels are filled with white color.
- The pixels that differ from one image to another are highlighted with red.
- The excess areas (when the images have different height or width) are highlighted with fuchsia.
- Dissimilar pixels that were skipped due to the PixelTolerance parameter are highlighted with blue.
- The pixels that were skipped due to the Transparent parameters are filled with grey color.
If ReportDifference is True (this is the default value), the difference image contains all the colors described above. In other words all the parameters (including PixelTolerance and Transparent) are considered. If the ReportDifference is False, the difference image contains white, red and fuchsia pixels only. This means that the PixelTolerance and Transparent parameters are not considered in this case.
Lets you ignore a slight difference between the images. If the number of different pixels is less than or equal to PixelTolerance, then TestComplete considers the images to be identical. 0 is the default value. It means that no difference between the bitmaps, except for that set by the Transparent parameter, is ignored.
|Note:||Using the PixelTolerance parameter with non-zero values may slow down the comparison process.|
||Do not post any message.|
||Post an informative message.|
||Post a warning message.|
||Post an error message.|
For information on specifying the MessageType parameter value, see Specifying Enumeration Values in Parameters.
When you add the operation to your test, TestComplete displays the Compare Pictures wizard that helps you set up the operation.
After adding the operation to your keyword test, you can invoke the wizard and modify the operation’s parameters in it. To do this, double-click the operation in the Keyword Test editor.
An alternative to modifying the parameters is to use the Operation Parameters dialog. In this dialog, you can specify the parameters by using various value types and modes (Constant, Code Expression, Last Operation Result and so on). For more information on working with the dialog and assigning parameter values in it, see Specifying Operation Parameters.
To invoke this dialog:
Select the operation in the Keyword Test editor.
Click the Value cell twice (not a double-click), or select the Value cell and press F2. This will activate the in-place editor.
Click the ellipsis button in the in-place editor.
After you specify the desired values in the Operation Parameters dialog, click OK to close the dialog and to apply the changes. To save the changes, press Enter. Pressing Esc will close the editor and discard any changes.
For information on region checkpoints and image comparison, see the topics of the About Region Checkpoints section.
Region Checkpoint Operation
About Region Checkpoints
How Image Comparison Works
Specifying Operation Parameters
Checking Operation Result