3
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 を使用して予想されるスクリーンショットと比較しようとしていますが、実際の画像と予想される画像が類似していても false がスローされ、差分画像も生成されません。

予想されるスクリーンショットを一時フォルダーに追加しました。

誰かが私が間違っていることを提案してください。前もって感謝します

4

1 に答える 1