]> source.dussan.org Git - vaadin-framework.git/commitdiff
Avoid NPEs if test is aborted before it has been initialized
authorLeif Åstrand <leif@vaadin.com>
Mon, 12 Aug 2013 12:58:31 +0000 (15:58 +0300)
committerLeif Åstrand <leif@vaadin.com>
Mon, 12 Aug 2013 12:58:31 +0000 (15:58 +0300)
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java

index 31af6e04ace7c228aff9ac1ac04c8ed254d19b68..ca9ecd0d3eb60d2579a09c23f97e37e42996872b 100644 (file)
@@ -60,7 +60,9 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
 \r
     @After\r
     public void tearDown() throws Exception {\r
-        driver.quit();\r
+        if (driver != null) {\r
+            driver.quit();\r
+        }\r
         driver = null;\r
     }\r
 \r
index 0a0c7eef66f7af1aa6d1520e61aa14b03d8f4304..175c1cef5d0f79d8f50dd96b4d384c88e32a8778 100644 (file)
@@ -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();
         }