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;
}
}}
大家好,
在上面的代码中,我试图获取一个页面的屏幕截图,并使用im4java将其与预期的屏幕快照进行比较,但是,即使实际的和预期的图像相似,它仍然抛出错误,并且也没有生成不同的图像。
我在临时文件夹中添加了预期的屏幕截图。
有人能告诉我我做错了什么吗。提前感谢
发布于 2016-08-14 02:46:09
我花了太多时间来解决这个问题。解决办法是:
我用这些步骤解决了我的问题。
https://stackoverflow.com/questions/35201396
复制相似问题