From e413646588fe45fe930116210da882b82151f3f3 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 29 Oct 2013 14:18:24 +0200 Subject: [PATCH] Ensure error screenshots are named according to the browser and not reference Change-Id: I3fe0a3f5e2906bde79d6d9fc3e84dab8102ffd60 --- .../vaadin/tests/tb3/ScreenshotTB3Test.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index cbdae1a6c1..367229eaaa 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -129,9 +129,28 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { // Matched one comparison but not all, remove all error images + // HTML files } else { - // All comparisons failed, keep the main error image + HTML - screenshotFailures.add(mainReference.getName()); - referenceToKeep = mainReference; + // Ensure we use the correct browser version (e.g. if running IE11 + // and only an IE 10 reference was available, then mainReference + // will be for IE 10, not 11) + String originalName = getScreenshotReferenceName(identifier); + File exactVersionFile = new File(originalName); + + if (!exactVersionFile.equals(mainReference)) { + // Rename png+html to have the correct version + File correctPng = getErrorFileFromReference(exactVersionFile); + File producedPng = getErrorFileFromReference(mainReference); + File correctHtml = htmlFromPng(correctPng); + File producedHtml = htmlFromPng(producedPng); + + producedPng.renameTo(correctPng); + producedHtml.renameTo(correctHtml); + referenceToKeep = exactVersionFile; + screenshotFailures.add(exactVersionFile.getName()); + } else { + // All comparisons failed, keep the main error image + HTML + screenshotFailures.add(mainReference.getName()); + referenceToKeep = mainReference; + } } // Remove all PNG/HTML files we no longer need (failed alternative @@ -140,10 +159,7 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { File failurePng = getErrorFileFromReference(failedAlternative); if (failedAlternative != referenceToKeep) { // Delete png + HTML - String htmlFileName = failurePng.getName().replace(".png", - ".html"); - File failureHtml = new File(failurePng.getParentFile(), - htmlFileName); + File failureHtml = htmlFromPng(failurePng); failurePng.delete(); failureHtml.delete(); @@ -151,6 +167,18 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { } } + /** + * Returns a new File which points to a .html file instead of the given .png + * file + * + * @param png + * @return + */ + private static File htmlFromPng(File png) { + return new File(png.getParentFile(), png.getName().replaceAll( + "\\.png$", ".png.html")); + } + /** * * @param referenceFile -- 2.39.5