Search in sources :

Example 1 with CompareCmd

use of org.im4java.core.CompareCmd in project selenium_java by sergueik.

the class VisualTest method compareImagesWithImageMagick.

// ImageMagick Compare Method
public void compareImagesWithImageMagick(String expected, String actual, String difference) throws Exception {
    ProcessStarter.setGlobalSearchPath(imageMagickPath);
    CompareCmd compare = new CompareCmd();
    compare.setSearchPath(imageMagickPath);
    // fix java.lang.NullPointerExceptionTests
    // compare.setErrorConsumer(StandardStream.STDERR);
    IMOperation imOperation = new IMOperation();
    imOperation.fuzz(5.0);
    // The special "-metric" setting of 'AE' (short for "Absolute Error" count),
    // will report (to standard error),
    // a count of the actual number of pixels that were masked, at the current
    // fuzz factor.
    imOperation.metric("AE");
    // Add the expected image
    imOperation.addImage(expected);
    // Add the actual image
    imOperation.addImage(actual);
    // This stores the difference
    imOperation.addImage(difference);
    String script = "myscript";
    try {
        System.out.println("Comparison Started");
        compare.createScript(script, imOperation);
        System.out.println("Comparison Script written to " + script);
        compare.run(imOperation);
    } catch (CommandException ex) {
        // ignore
        System.err.println("Exception (ignored):" + ex.getClass());
        System.err.print(ex);
    } catch (Exception ex) {
        System.err.println("Comparison Failed!");
        System.err.print(ex);
        throw ex;
    }
    // Put the difference image to the global differences folder
    Files.copy(differenceImageFile, differenceFileForParent);
}
Also used : IMOperation(org.im4java.core.IMOperation) CommandException(org.im4java.core.CommandException) CommandException(org.im4java.core.CommandException) IM4JavaException(org.im4java.core.IM4JavaException) IOException(java.io.IOException) CompareCmd(org.im4java.core.CompareCmd)

Aggregations

IOException (java.io.IOException)1 CommandException (org.im4java.core.CommandException)1 CompareCmd (org.im4java.core.CompareCmd)1 IM4JavaException (org.im4java.core.IM4JavaException)1 IMOperation (org.im4java.core.IMOperation)1