From 6c1e5f3ec0843828ab40acea995d6b808995394a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Mon, 12 Aug 2013 15:58:31 +0300 Subject: [PATCH] Avoid NPEs if test is aborted before it has been initialized --- .../com/vaadin/tests/tb3/AbstractTB3Test.java | 4 +++- .../vaadin/tests/tb3/ScreenshotTB3Test.java | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 31af6e04ac..ca9ecd0d3e 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -60,7 +60,9 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { @After public void tearDown() throws Exception { - driver.quit(); + if (driver != null) { + driver.quit(); + } driver = null; } diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index 0a0c7eef66..175c1cef5d 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -38,6 +38,7 @@ import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.DesiredCapabilities; import com.vaadin.testbench.Parameters; +import com.vaadin.testbench.commands.TestBenchCommands; public abstract class ScreenshotTB3Test extends AbstractTB3Test { @@ -247,16 +248,22 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { public void onUncaughtException(Throwable cause) { super.onUncaughtException(cause); try { - testBench().disableWaitForVaadin(); + TestBenchCommands testBench = testBench(); + if (testBench != null) { + testBench.disableWaitForVaadin(); + } } catch (Throwable t) { t.printStackTrace(); } try { - BufferedImage screenshotImage = ImageIO - .read(new ByteArrayInputStream(((TakesScreenshot) driver) - .getScreenshotAs(OutputType.BYTES))); - ImageIO.write(screenshotImage, "png", new File( - getScreenshotFailureName())); + 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(); } -- 2.39.5