Select Page
Automation Testing

Automation Testing – Comparing Screenshots

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

Automation Testing - Comparing Screenshots - Blog
Listen to this blog

Suppose if you want to compare the screenshot (source) which was captured in your last automated test execution with the current execution screenshot (target), then you can go with imagemagick tool. It provides the difference in a file after a comparison and is very helpful for automation testing.

You can also use ImageMagick to compare two different images through command line if you have any test cases for manual testing. Let’s see how to compare source and target images and get the difference using ImageMagick with an example code.

Installation

Step-1: Download ImageMagick-6.8.9-8-Q16-x86-windows.zip from the following link http://ftp.icm.edu.pl/packages/ImageMagick/binaries/ and extract it wherever you want.

Step-2: Set E:SoftwaresImageMagick-6.8.9-8 in path environment variable

Maven Dependency
 <dependency>
    <groupId>org.im4java</groupId>
    <artifactId>im4java</artifactId>
    <version>1.4.0</version>
   </dependency>  
Code
import org.im4java.core.CompareCmd;
import org.im4java.core.IM4JavaException;
import org.im4java.core.IMOperation;
import org.im4java.process.StandardStream;

import java.io.IOException;

/**
 * Created by Codoid Testing Services Company
 */
public class ImageComparisonExample {
    public static void main(String args[]) throws InterruptedException, IOException, IM4JavaException {
        CompareCmd compare = new CompareCmd();

        compare.setErrorConsumer(StandardStream.STDERR);
        IMOperation cmpOp = new IMOperation();

        cmpOp.metric("mae");

        cmpOp.addImage("image/image-1.png");

        cmpOp.addImage("image/image-2.png");

        cmpOp.addImage("image/image-diff.png");

        compare.run(cmpOp);
    }
}  

You can also explore AppliTools Automated Visual Web & Mobile Testing to take your image comparsions to the next level.

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility