public static boolean compareScreen( BufferedImage reference, String referenceName, ImageComparison imageComparison, TakesScreenshot takesScreenshot, HasCapabilities driver) throws IOException { for (int times = 0; times < Parameters.getMaxScreenshotRetries(); times++) { BufferedImage screenshotImage = ImageIO.read(new ByteArrayInputStream(takesScreenshot.getScreenshotAs(OutputType.BYTES))); if (reference == null) { // Store the screenshot in the errors directory and fail the // test ImageFileUtil.createScreenshotDirectoriesIfNeeded(); ImageIO.write(screenshotImage, "png", ImageFileUtil.getErrorScreenshotFile(referenceName)); getLogger() .severe( "No reference found for " + referenceName + " in " + ImageFileUtil.getScreenshotReferenceDirectory()); return false; } if (imageComparison.imageEqualToReference( screenshotImage, reference, referenceName, Parameters.getScreenshotComparisonTolerance())) { return true; } pause(Parameters.getScreenshotRetryDelay()); } return false; }
public static boolean compareScreen( String referenceId, ReferenceNameGenerator referenceNameGenerator, ImageComparison imageComparison, TakesScreenshot takesScreenshot, HasCapabilities driver) throws IOException { Capabilities capabilities = driver.getCapabilities(); String referenceName = referenceNameGenerator.generateName(referenceId, capabilities); for (int times = 0; times < Parameters.getMaxScreenshotRetries(); times++) { boolean equal = imageComparison.imageEqualToReference( getScreenshot((TakesScreenshot) driver, takesScreenshot, capabilities), referenceName, Parameters.getScreenshotComparisonTolerance(), capabilities); if (equal) { return true; } pause(Parameters.getScreenshotRetryDelay()); } return false; }