In GUI test automation, there are different approaches to identifying UI elements. Ranorex Studio’s main approach is based on object-oriented testing. This means it can directly identify and interact with individual UI elements based on the technology they were implemented with.
However, in some cases, this approach may not work that well. For this reason, Ranorex Studio also supports image-based testing. This approach identifies and interacts with UI elements based on the recognition of pixels in an image.
In this chapter, find out when and how to use image-based testing in Ranorex Studio and how to overcome the challenges of this testing approach.
Enable image-based recording
The best way to use image-based testing in Ranorex Studio is through the Recorder. There, you can enable and disable image-based testing while you’re recording. This way, you can combine object-oriented and image-based approaches in a single recording if required.
To enable image-based recording:
-
While recording, click the Image-based recording switch.
-
Image-based recording is now active.
Alternatively, you can also use hotkeys:
-
While recording, enable hotkeys.
-
Press I to enable image-based recording.
Why image-based testing?
Image-based testing is useful when the object-oriented approach can’t produce satisfactory results. Check the examples below:
Example preparation
Use the Ranorex Studio Demo Application for this example and record the actions in the Recorder.
-
Start the demo application and click the Image-based automation tab.
-
In Ranorex Studio, create a new desktop solution with the solution wizard and open Recording1 in this solution.
-
In the recording module view of Recording1, click RECORD.
Object-oriented recording
We’ll now record mouse clicks on three consecutive dates in the calendar view of the demo application using the default object-oriented approach.
-
Ensure image-based recording is disabled.
-
Click the three dates 24, 25, and 26 in the calendar and stop the recording.
-
The action table displays the three corresponding actions.
Run the test
When you run the test, you can see the following:
- The recorded calendar dates are identified correctly.
- Each click action in the report corresponds to the correct date in the calendar.
Change of test conditions
So far, the object-oriented approach has worked flawlessly. Now, assume that you run the test a couple of months from its creation. This means that the calendar view will have changed to a different month. Let’s see how our test performs in this case.
-
In the calendar in the demo application, switch to any month where the recorded dates 24, 25, and 26 are at a different position in the calendar.
Run the test again and see what happens.
- The test runs without failure and reports a success.
- However, this is a false positive. The test identifies the wrong dates (21, 22, and 23 in our case instead of 24, 25, and 26).
Conclusion
The next page shows you how you can overcome this challenge with image-based testing.
Download the sample solution
You can download the completed solution with all the above steps carried out below.
Theme: Image-based testing
Time: < 30 minutes
Install the sample solution:
-
Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
ImagebasedAutomation.rxsln