Integrating Image Comparison with Shutterbug
Kushan Shalindra Amarasiri
Director Quality Engineering at Social Catfish
In our previous article we looked at how we can integrate Shutterbug screen capture to our Selenium Java Framework.
In this article I will show how we can have image comarison integrated with Shutterbug.
First of all we need to have the Shutterbug integrated to our framework with the maven dependency.
<dependency>
<groupId>com.assertthat</groupId>
<artifactId>selenium-shutterbug</artifactId>
<version>0.9</version>
</dependency>
Next lets have the image comparison coding added to our test scenario.
@Test
public void test() throws IOException
{
System.setProperty("webdriver.chrome.driver","D:\\chrdrv\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "https://www.google.lk";
driver.get(baseUrl);
File image = new File(".\\screenshots\\Expected.png");
BufferedImage expectedImage = ImageIO.read(image);
boolean status = Shutterbug.shootPage(driver).withName("Actual").equals(expectedImage,0.1);
Assert.assertTrue(status);
driver.close();
}
Please also do remember to have the baseline image in your screenshots folder.
After running it will compare the actual image captured with the baseline and validates whether they are similar.