We can design a framework that not only limit our automation usage to regression rather we may use it for functional and UI verification as well.
The most common things we test using our automation suites are Text, Presence of objects or attributes of objects. These do not ensure about UI of the application. We can create a repository of images (like objects) and ensure that images on test build are exactly matching with stable build.
- Full page screenshot comparison ensures quick UI and smoke testing.
- Object level image comparison allows UI verification for specific objects.
- It can capture issue at pixel level which are sometimes hard to locate through naked eyes.
- Can be used for web as well as native applications on iOS or android.
Selenium Page Object Model based wrapper
ant / Maven
STEPS - How to Implement
1. Capture driver screenshot.
2. Get width & height of the element.
3. Crop element screenshot from the complete screenshot using subImage function of bufferedImage
4. Keep copy of correct image in Image repository before running test.
5. Compare actual image with the one present in repository and calculate the % difference by reading & comparing pixels of both images.
6. If difference is greater than 2-5% then mark test case as failure.