From 18143dddcec64f6ba2a610f51abdb25272a8d129 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 25 Mar 2014 13:45:37 +0200 Subject: Retry browser startup multiple times for more stability Change-Id: Ia46ee4b30809a978e95b67a4f5dfe74bd0125eb3 --- .../src/com/vaadin/tests/tb3/AbstractTB3Test.java | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 6f934011f5..ecba419472 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -89,6 +89,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { */ private static final int BROWSER_TIMEOUT_IN_MS = 30 * 1000; + private static final int BROWSER_INIT_ATTEMPTS = 5; + private DesiredCapabilities desiredCapabilities; private boolean debug = false; @@ -138,9 +140,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { if (localWebDriverIsUsed()) { setupLocalDriver(capabilities); } else { - WebDriver dr = TestBench.createDriver(new RemoteWebDriver( - new URL(getHubURL()), capabilities)); - setDriver(dr); + setupRemoteDriver(capabilities); } } @@ -222,6 +222,32 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { protected abstract void setupLocalDriver( DesiredCapabilities desiredCapabilities); + /** + * Creates a {@link WebDriver} instance used for running the test remotely. + * + * @since + * @param capabilities + * the type of browser needed + * @throws Exception + */ + private void setupRemoteDriver(DesiredCapabilities capabilities) + throws Exception { + for (int i = 1; i <= BROWSER_INIT_ATTEMPTS; i++) { + try { + WebDriver dr = TestBench.createDriver(new RemoteWebDriver( + new URL(getHubURL()), capabilities)); + setDriver(dr); + } catch (Exception e) { + System.err.println("Browser startup for " + capabilities + + " failed on attempt " + i + ": " + e.getMessage()); + if (i == BROWSER_INIT_ATTEMPTS) { + throw e; + } + } + } + + } + /** * Opens the given test (defined by {@link #getTestUrl()}, optionally with * debug window and/or push (depending on {@link #isDebug()} and -- cgit v1.2.3