Book Image

Selenium Testing Tools Cookbook

By : UNMESH GUNDECHA
5 (1)
Book Image

Selenium Testing Tools Cookbook

5 (1)
By: UNMESH GUNDECHA

Overview of this book

This book is an incremental guide that will help you learn and use the advanced features of the Selenium toolset including the WebDriver API in various situations to build a reliable test automation. You start off by setting up the test development environment and gain tips on the advanced locater strategy and the effective use of the Selenium WebDriver API. After that, the use of design patterns such as data - driven tests and PageFactory are demonstrated. You will then be familiarised with extending Selenium WebDriver API by implementing custom tasks and setting up your own distributed environment to run tests in parallel for cross-browser testing. Finally, we give you some tips on integrating Selenium WebDriver with other popular tools and testing mobile applications. By the end of this book, you will have learned enough to solve complex testing issues on your own.
Table of Contents (21 chapters)
Selenium Testing Tools Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 image files, as shown in the following code:

package com.secookbook.examples.chapter09;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.PixelGrabber;

public class CompareUtil {

  public enum Result {
    Matched, SizeMismatch...