]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensure error screenshots are named according to the browser and not reference
authorArtur Signell <artur@vaadin.com>
Tue, 29 Oct 2013 12:18:24 +0000 (14:18 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 29 Oct 2013 13:32:45 +0000 (13:32 +0000)
Change-Id: I3fe0a3f5e2906bde79d6d9fc3e84dab8102ffd60

uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java

index cbdae1a6c1d3833dad0c77c235846542d2d5fc6c..367229eaaa177753fec8b073c39785b828cbdd6e 100644 (file)
@@ -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