[英]Image comparison using im4java
public class im4jav extends test{
public static void main(String[] args) throws IOException {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/?gfe_rd=cr&ei=fkKzVqasB8yl8wefrraoCg&gws_rd=ssl");
File scrFile = ((TakesScreenshot)driver).
getScreenshotAs(OutputType.FILE);
String current = "c:/temp/image.png";
FileUtils.copyFile(scrFile, new File(current));
boolean compareSuccess = compareImages("c:/temp/expected.png", current, "c:/temp/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();
// For metric-output
compare.setErrorConsumer(StandardStream.STDERR);
IMOperation cmpOp = new IMOperation();
// Set the compare metric
cmpOp.metric("mae");
// Add the expected image
cmpOp.addImage(exp);
// Add the current image
cmpOp.addImage(cur);
// This stores the difference
cmpOp.addImage(diff);
try {
// Do the compare
compare.run(cmpOp);
return true;
}
catch (Exception ex) {
return false;
}
}
} }
Hi Team, 嗨团队,
In the above code I am trying to take a screenshot of a page and compare it with expected screenshot using im4java however even if the actual and expected images are similar it still throws false and the difference image is also not getting generated 在上面的代码中,我试图截取一个页面,并使用im4java将其与预期的屏幕截图进行比较,但即使实际和预期的图像相似,它仍然会抛出错误,差异图像也不会生成
I have added expected screenshot in temp folder. 我在temp文件夹中添加了预期的屏幕截图。
Can someone please suggest what i am doing wrong. 有人可以建议我做错了什么。 Thanks in advance
提前致谢
I spent too much time to fix the problem. 我花了太多时间来解决这个问题。 Solution is:
解决方案是:
With these steps I solved my problems. 通过这些步骤,我解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.