diff --git a/core/src/main/java/de/otto/jlineup/JLineupRunner.java b/core/src/main/java/de/otto/jlineup/JLineupRunner.java index a73f74bd..9bfe95b2 100644 --- a/core/src/main/java/de/otto/jlineup/JLineupRunner.java +++ b/core/src/main/java/de/otto/jlineup/JLineupRunner.java @@ -84,23 +84,21 @@ public boolean run() { jsonReportWriter.writeComparisonReportAsJson(report); htmlReportWriter.writeReport(report); - final Set> entries = report.screenshotComparisonsForUrl.entrySet(); - for (Map.Entry entry : entries) { - LOG.info("Sum of screenshot differences for {}: {} ({} %)", entry.getKey(), entry.getValue().summary.differenceSum, Math.round(entry.getValue().summary.differenceSum * 100d)); - LOG.info("Max difference of a single screenshot for {}: {} ({} %)", entry.getKey(), entry.getValue().summary.differenceMax, Math.round(entry.getValue().summary.differenceMax * 100d)); - LOG.info("Accepted different pixels for {}: {}", entry.getKey(), entry.getValue().summary.acceptedDifferentPixels); + final Set> urlReports = report.screenshotComparisonsForUrl.entrySet(); + for (Map.Entry urlReport : urlReports) { + LOG.info("Sum of screenshot differences for {}: {} ({} %)", urlReport.getKey(), urlReport.getValue().summary.differenceSum, Math.round(urlReport.getValue().summary.differenceSum * 100d)); + LOG.info("Max difference of a single screenshot for {}: {} ({} %)", urlReport.getKey(), urlReport.getValue().summary.differenceMax, Math.round(urlReport.getValue().summary.differenceMax * 100d)); + LOG.info("Accepted different pixels for {}: {}", urlReport.getKey(), urlReport.getValue().summary.acceptedDifferentPixels); } LOG.info("Sum of overall screenshot differences: {} ({} %)", report.summary.differenceSum, Math.round(report.summary.differenceSum * 100d)); LOG.info("Max difference of a single screenshot: {} ({} %)", report.summary.differenceMax, Math.round(report.summary.differenceMax * 100d)); if (!Utils.shouldUseLegacyReportFormat(jobConfig)) { - for (Map.Entry entry : entries) { - //Exit with exit code 1 if at least one url report has a bigger difference than configured - if (jobConfig.urls != null && entry.getValue().summary.differenceMax > jobConfig.urls.get(entry.getKey()).maxDiff) { - LOG.info("JLineup finished. There was a difference between before and after. Return code is 1."); - return false; - } + //Exit with exit code 1 if at least one url report has a bigger difference than configured + if (isDetectedDifferenceGreaterThanMaxDifference(urlReports, jobConfig)) { + LOG.info("JLineup finished. There was a difference between before and after. Return code is 1."); + return false; } } } @@ -113,6 +111,15 @@ public boolean run() { return true; } + static boolean isDetectedDifferenceGreaterThanMaxDifference(Set> urlReports, JobConfig jobConfig) { + for (Map.Entry urlReport : urlReports) { + if (jobConfig.urls != null && urlReport.getValue().summary.differenceMax > jobConfig.urls.get(urlReport.getKey()).maxDiff) { + return true; + } + } + return false; + } + private void validateConfig() throws ValidationError { JobConfigValidator.validateJobConfig(jobConfig); } diff --git a/core/src/main/java/de/otto/jlineup/config/UrlConfig.java b/core/src/main/java/de/otto/jlineup/config/UrlConfig.java index 95dc9de8..e3bf5fac 100644 --- a/core/src/main/java/de/otto/jlineup/config/UrlConfig.java +++ b/core/src/main/java/de/otto/jlineup/config/UrlConfig.java @@ -19,7 +19,7 @@ public class UrlConfig { public final List paths; public final List setupPaths; public final List cleanupPaths; - public final float maxDiff; + public final double maxDiff; public final List cookies; public final Map envMapping; public final Map localStorage; @@ -99,7 +99,7 @@ public List getPaths() { return paths; } - public float getMaxDiff() { + public double getMaxDiff() { return maxDiff; } @@ -242,7 +242,7 @@ public static final class Builder { private List paths = ImmutableList.of(DEFAULT_PATH); private List setupPaths = Collections.emptyList(); private List cleanupPaths = Collections.emptyList(); - private float maxDiff = DEFAULT_MAX_DIFF; + private double maxDiff = DEFAULT_MAX_DIFF; private List cookies; private Map envMapping; private Map localStorage; @@ -284,7 +284,7 @@ public Builder withCleanupPaths(List val) { return this; } - public Builder withMaxDiff(float val) { + public Builder withMaxDiff(double val) { maxDiff = val; return this; } @@ -433,7 +433,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; UrlConfig urlConfig = (UrlConfig) o; - return Float.compare(urlConfig.maxDiff, maxDiff) == 0 && + return Double.compare(urlConfig.maxDiff, maxDiff) == 0 && maxScrollHeight == urlConfig.maxScrollHeight && Float.compare(urlConfig.waitAfterPageLoad, waitAfterPageLoad) == 0 && Float.compare(urlConfig.waitAfterScroll, waitAfterScroll) == 0 && diff --git a/core/src/test/java/de/otto/jlineup/JLineupRunnerTest.java b/core/src/test/java/de/otto/jlineup/JLineupRunnerTest.java new file mode 100644 index 00000000..9339b4d8 --- /dev/null +++ b/core/src/test/java/de/otto/jlineup/JLineupRunnerTest.java @@ -0,0 +1,27 @@ +package de.otto.jlineup; + +import de.otto.jlineup.config.JobConfig; +import de.otto.jlineup.config.UrlConfig; +import de.otto.jlineup.report.Summary; +import de.otto.jlineup.report.UrlReport; +import org.assertj.core.data.MapEntry; +import org.junit.Test; + +import java.util.Collections; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.jupiter.api.Assertions.*; + +public class JLineupRunnerTest { + + @Test + public void shouldNotFailIfMaxDiffIsSameAsDetectedDiff() { + + UrlReport urlReport = new UrlReport(null, new Summary(false, 0, 15.1234567890123456, 0)); + boolean detectedDifferenceGreaterThanMaxDifference = JLineupRunner.isDetectedDifferenceGreaterThanMaxDifference(Collections.singleton(MapEntry.entry("abc", urlReport)), JobConfig.exampleConfigBuilder().withUrls(Collections.singletonMap("abc", UrlConfig.urlConfigBuilder().withMaxDiff(15.1234567890123456).build())).build()); + + assertThat(detectedDifferenceGreaterThanMaxDifference, is(false)); + } + +} \ No newline at end of file diff --git a/core/src/test/java/de/otto/jlineup/browser/BrowserUtilsTest.java b/core/src/test/java/de/otto/jlineup/browser/BrowserUtilsTest.java index 1f3b9582..1bea79c0 100644 --- a/core/src/test/java/de/otto/jlineup/browser/BrowserUtilsTest.java +++ b/core/src/test/java/de/otto/jlineup/browser/BrowserUtilsTest.java @@ -107,7 +107,7 @@ public static UrlConfig getExpectedUrlConfigForOttoDe() { return UrlConfig.urlConfigBuilder() .withPaths(ImmutableList.of("/", "multimedia")) - .withMaxDiff(0.05f) + .withMaxDiff(0.05d) .withCookies(ImmutableList.of(new Cookie("testcookie1", "true"), new Cookie("testcookie2", "1"))) .withEnvMapping(ImmutableMap.of("live", "www")) .withLocalStorage(ImmutableMap.of("teststorage", "{'testkey':{'value':true,'timestamp':9467812242358}}")) @@ -125,7 +125,7 @@ public static UrlConfig getExpectedUrlConfigForGoogleDe() { return UrlConfig.urlConfigBuilder() .withPath("/") - .withMaxDiff(0.05f) + .withMaxDiff(0.05d) .withWindowWidths(ImmutableList.of(1200)) .withMaxScrollHeight(100000) .build(); diff --git a/core/src/test/java/de/otto/jlineup/report/ScreenshotsComparatorTest.java b/core/src/test/java/de/otto/jlineup/report/ScreenshotsComparatorTest.java index 86345662..32bd009e 100644 --- a/core/src/test/java/de/otto/jlineup/report/ScreenshotsComparatorTest.java +++ b/core/src/test/java/de/otto/jlineup/report/ScreenshotsComparatorTest.java @@ -38,7 +38,7 @@ public class ScreenshotsComparatorTest { private final UrlConfig urlConfig = UrlConfig.urlConfigBuilder() .withPath("/") - .withMaxDiff(0.05f) + .withMaxDiff(0.05d) .withWindowWidths(singletonList(100)) .withMaxScrollHeight(10000) .withWaitAfterPageLoad(2)