Comparing images in Selenium

Many a time, our tests need image-based comparison. For example, verifying whether correct icons are displayed, whether correct images are displayed in web pages, or comparing baseline screen layout with the actual layout.

Selenium WebDriver does have features to capture screenshots or images from the application under test, however, it does not have the feature to compare the images.

In this recipe, we will create an extension class for comparing images and use it in our Selenium tests.

Getting ready

Set up a new Java project for the CompareUtil class. This class will be used by Selenium tests as an extension for comparing images.

How to do it...

Let's implement the CompareUtil class with a method to compare two image ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.