O'Reilly logo

Selenium Testing Tools Cookbook - Second Edition by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparing images in Selenium

Many a time, our tests need image-based comparison. For example, verifying whether correct icons are displayed, verifying whether correct images are displayed in web pages, or comparing the 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 to compare 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 to compare images.

How to do it...

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required