Image Comparison — Below code not working

package compare;

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.apache.commons.io.FileUtils;
import org.im4java.core.CompareCmd;
import org.im4java.process.StandardStream;
import org.im4java.core.IMOperation;
import org.openqa.selenium.TakesScreenshot;

public class compare extends test{

public static void main(String[] args) throws IOException {
WebDriver driver;
System.setProperty(“webdriver.chrome.driver”, “D:/selenium jar files/chromedriver_win32/chromedriver.exe”);
driver=new ChromeDriver();

driver.get(“http://habiletechnologies.com/”);

File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

String current;
current=”D:/screenshot/image.png”;
FileUtils.copyFile(scrFile, new File(current));

boolean compareSuccess = compareImages(“D:/screenshot/expected.png”, current, “D:/screenshot/difference.png”);

System.out.println(“run ok ? :”+compareSuccess);

driver.close();

}}class test{

static boolean compareImages (String exp, String cur, String diff) {
// This instance wraps the compare command
CompareCmd compare = new CompareCmd();
String [] expected={“a”} ;
expected[0]=exp;
String [] current={“b”};
current[0]=cur;
String [] difference={“c”};
difference[0]=diff;
// For metric-output
compare.setErrorConsumer(StandardStream.STDERR);
IMOperation cmpOp = new IMOperation();
// Set the compare metric
cmpOp.metric(“mae”);

// Add the expected image
cmpOp.addImage(expected);

// Add the current image
cmpOp.addImage(current);

// This stores the difference
cmpOp.addImage(difference);

try {
// Do the compare
compare.run(cmpOp, expected);
return true;
}
catch (Exception ex) {
return false;
}
}
}

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.