This article walks you through recording an image-based validation in Ranorex Studio. You’ll learn how to switch the Recorder into image-based validation mode, select the UI element to validate, and configure the image comparison.
To follow along with this tutorial, download the sample solution file from the link below.
Theme: Build a test
Time: 15 minutes
Install the sample solution
- Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
ImagebasedValidation.rxsln
Test definition
Before you start recording, let’s define the test. It consists of five steps:
- Start the demo application.
- Click the Image-based automation tab.
- Select Show image to display the cat image.
- Verify that the image is displayed (image-based validation).
- Exit the Demo Application.
Recording preparation
- Create a desktop test solution using the Solution Wizard.
- In step 2 of the wizard, select the Demo Application as your AUT.
- When the wizard finishes, click the Recording1 tab.
- Demo App selected as AUT and is launched automatically when you start recording. When the Solution Wizard has finished, click the Recording1 tab in the Ranorex Studio working environment.
Record the test
- In Recording1, click RECORD.
Ranorex Studio minimizes automatically, and the Recorder control center appears. - In the AUT, click the Image-based automation tab.
- Select Show image to display the cat image.
Image-based validation
The goal is to verify that the cat image appears when Show image is selected. Because this validation checks image content, you’ll use an image-based validation.
Activate image-based validation
- In the Recorder controls, enable Image-based recording.
- Click Validate. The Recorder pauses recording and switches to image-based validation mode
- Select the UI element to validate:
- Mouse over the image of the cat. A purple frame follows your mouse movement.
- The purple frame indicates which element is currently selected for validation.
- Once your selection matches the image, click it.
- Click Next to confirm the selected UI element.
-
UI element location within GUI: The UI element tree represents the hierarchical GUI structure of the application.
You can click a different UI element to select it for validation if desired. - UI element states and attributes: All the attributes of the selected UI element appear in this area.
-
Screenshot of validation UI element: Use the screenshot to quickly check whether you’ve selected the correct UI element.Define the image that will be used for the validation. For our example, simply leave everything as it is and click OK to confirm.
- The Image tab is selected in the validation dialog instead of the Attributes tab.
- Draw a rectangle to select a part of the image when using the “Contains” validation mode.
- Different image validation modes are available:
None: deactivates image validation.
Contains: determines whether the validation image is contained in the actual image found during the test.
Compare: determines whether the validation image and the actual image found during the test are the same.
Finish recording
Once you’ve finished the validation action, Ranorex automatically continues recording. The next step is to end the test recording. In the Recorder control center, click Stop to end the recording.
Result
Back in Ranorex Studio, the actions table contains three actions. Action #3 is the validation action.
-
Validation type operator: This operator identifies the type of validation to perform. There are nine different validation type operators.
A detailed description of all validation match operators can be found in Action properties. - The validation screenshot is used as the expected image.
- The repository item linked to the action (the UI element the validation runs against).
Interpreting the validation
In plain language, the validation reads like this:
If Screenshot1 is contained (ContainsImage) in the UI-element referenced by the repository item TheCat, THEN the validation returns the value ‘True‘.