diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-02-12 14:57:13 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-02-19 15:19:46 +0200 |
commit | fd8078d691f6b6eec407882280730104f5027e3d (patch) | |
tree | 1e9e3dac572d9951a55d6d00e935167c6056eb27 /uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java | |
parent | f4e002e36be983b16c6324255780fd7e74710d68 (diff) | |
download | vaadin-framework-fd8078d691f6b6eec407882280730104f5027e3d.tar.gz vaadin-framework-fd8078d691f6b6eec407882280730104f5027e3d.zip |
Use TestBench-4.0.2
- Based on TB4 Parallel testing.
- Browser setup no longer uses static capabilities.
- Some code cleanup here and there.
Change-Id: I5c419316cd36f4f5041eaa8da8fda3d8b46596c4
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java')
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java | 115 |
1 files changed, 66 insertions, 49 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index 4a4354d67c..f401e0613b 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -16,32 +16,26 @@ package com.vaadin.tests.tb3; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileFilter; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.imageio.ImageIO; - import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestRule; import org.junit.rules.TestWatcher; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; +import org.junit.runner.Description; import org.openqa.selenium.remote.DesiredCapabilities; import com.vaadin.testbench.Parameters; -import com.vaadin.testbench.commands.TestBenchCommands; +import com.vaadin.testbench.ScreenshotOnFailureRule; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.testbench.screenshot.ImageFileUtil; /** * Base class which provides functionality for tests which use the automatic @@ -51,6 +45,29 @@ import com.vaadin.testbench.commands.TestBenchCommands; */ public abstract class ScreenshotTB3Test extends AbstractTB3Test { + @Rule + public ScreenshotOnFailureRule screenshotOnFailure = new ScreenshotOnFailureRule( + this, true) { + + @Override + protected void failed(Throwable throwable, Description description) { + super.failed(throwable, description); + closeApplication(); + } + + @Override + protected void succeeded(Description description) { + super.succeeded(description); + closeApplication(); + } + + @Override + protected File getErrorScreenshotFile(Description description) { + return ImageFileUtil + .getErrorScreenshotFile(getScreenshotFailureName()); + }; + }; + private String screenshotBaseName; @Rule @@ -331,48 +348,15 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.tests.tb3.AbstractTB3Test#onUncaughtException(java.lang.Throwable - * ) - */ - @Override - public void onUncaughtException(Throwable cause) { - super.onUncaughtException(cause); - // Grab a "failure" screenshot and store in the errors folder for later - // analysis - try { - TestBenchCommands testBench = testBench(); - if (testBench != null) { - testBench.disableWaitForVaadin(); - } - } catch (Throwable t) { - t.printStackTrace(); - } - try { - if (driver != null) { - BufferedImage screenshotImage = ImageIO - .read(new ByteArrayInputStream( - ((TakesScreenshot) driver) - .getScreenshotAs(OutputType.BYTES))); - ImageIO.write(screenshotImage, "png", new File( - getScreenshotFailureName())); - } - } catch (Throwable t) { - t.printStackTrace(); - } - - } - /** * @return the name of a "failure" image which is stored in the folder * defined by {@link #getScreenshotErrorDirectory()} when the test * fails */ private String getScreenshotFailureName() { - return getScreenshotErrorBaseName() + "-failure.png"; + return getScreenshotBaseName() + "_" + + getUniqueIdentifier(getDesiredCapabilities()) + + "-failure.png"; } /** @@ -409,10 +393,9 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { Integer versionOverride) { String uniqueBrowserIdentifier; if (versionOverride == null) { - uniqueBrowserIdentifier = BrowserUtil - .getUniqueIdentifier(getDesiredCapabilities()); + uniqueBrowserIdentifier = getUniqueIdentifier(getDesiredCapabilities()); } else { - uniqueBrowserIdentifier = BrowserUtil.getUniqueIdentifier( + uniqueBrowserIdentifier = getUniqueIdentifier( getDesiredCapabilities(), "" + versionOverride); } @@ -423,6 +406,40 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { } /** + * Returns a string which uniquely (enough) identifies this browser. Used + * mainly in screenshot names. + * + * @param capabilities + * @param versionOverride + * + * @return a unique string for each browser + */ + private String getUniqueIdentifier(DesiredCapabilities capabilities, + String versionOverride) { + return getUniqueIdentifier(BrowserUtil.getPlatform(capabilities), + BrowserUtil.getBrowserIdentifier(capabilities), versionOverride); + } + + /** + * Returns a string which uniquely (enough) identifies this browser. Used + * mainly in screenshot names. + * + * @param capabilities + * + * @return a unique string for each browser + */ + private String getUniqueIdentifier(DesiredCapabilities capabilities) { + return getUniqueIdentifier(BrowserUtil.getPlatform(capabilities), + BrowserUtil.getBrowserIdentifier(capabilities), + capabilities.getVersion()); + } + + private String getUniqueIdentifier(String platform, String browser, + String version) { + return platform + "_" + browser + "_" + version; + } + + /** * Returns the base name of the screenshot in the error directory. This is a * name so that all files matching {@link #getScreenshotErrorBaseName()}* * are owned by this test instance (taking into account |