This chapter contains a simple tutorial for image-based validation. Before working with this example, make sure you are familiar with the basic concept of test validation.
The screencast Basic image-based validation walks you through the information found in this chapter.:
Download the sample solution
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
The sample solution is available for Ranorex versions 8.0 or higher. You must agree to the automatic solution upgrade for versions 8.2 and higher
Test definition
Before you start recording, let’s define the test. It consists of five steps:
1. Start the demo application.
2. Click the Image-based automation tab.
3. Make the image visible.
4. Verify that the image is displayed.
5. Exit the Demo Application.
Recording preparation
-
Create a desktop-test solution using the Solution Wizard and in step 2 of the setup, select the Demo Application as your AUT.
-
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: part one
Remember, if you are not using whitelisting, all user interactions are captured once recording has started, even if they are not performed on the AUT.
- Click Pause to pause the recording. Click Continue to resume recording.
- Click Stop to end recording.
Learn more about the Recorder control center in Ranorex Studio fundamentals > Ranorex Recorder > ⇢ Recorder control center & hotkeys.
Read about whitelisting in Ranorex Studio fundamentals > ⇢ Whitelisting.
-
In the recording module view of Recording1, click RECORD. Ranorex Studio is minimized to the taskbar automatically.
The Recorder control center shows that the recording is active.
-
The application under test comes into focus. Click the tab Image-based automation.
-
To make the image appear, click the checkbox Show image.
Image-based validation
The goal of the example validation is to verify whether the image of the cat appears when the checkbox is selected. Since this requires us to validate an image, it’s an image-based validation.
Follow the steps below:
Activate image-based validation
-
In the Recorder controls, activate the switch Image-based recording.
-
Click Validate. The Recorder pauses recording and switches to image-based validation mode.
Select validation element
-
Selectthe 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.
Confirm validation element
-
To confirm the UI element,click Next.
-
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 validation attributes
-
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
After recording stops, you are returned to Ranorex Studio. You’ll see the actions table with three recorded 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 Ranorex Studio fundamentals > Actions > Action properties.
-
The validation screenshot to which the actual image found during testing will be matched.
-
The repository item linked to the action, i.e. the UI element on which the validation is performed.
Interpreting the validation
If written as a statement, the validation would read as follows:
If Screenshot1
is contained (ContainsImage
) in the UI-element referenced by the repository item TheCat
, THEN the validation returns the value ‘True
‘.