Skip to content

Commit

Permalink
retry a test failure if there was a 'sauce' issue, like we exceeded t…
Browse files Browse the repository at this point in the history
…he total time a test session is allowed to take.

the stored driver can also be in a 'quit' state if the sessionId is null
  • Loading branch information
lukeis committed Apr 30, 2014
1 parent 7720dd8 commit 58c194a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openqa.selenium.environment.TestEnvironment;
import org.openqa.selenium.environment.webserver.AppServer;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
Expand Down Expand Up @@ -101,7 +102,8 @@ public WebDriver getWrappedDriver() {
public static WebDriver actuallyCreateDriver() {
WebDriver driver = storedDriver.get();

if (driver == null) {
if (driver == null ||
(driver instanceof RemoteWebDriver && ((RemoteWebDriver)driver).getSessionId() == null)) {
driver = new WebDriverBuilder().get();
storedDriver.set(driver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ private Statement coveringUpSauceErrors(final Statement statement) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
// TODO(dawagner): Maybe retry the method which failed
try {
statement.evaluate();
} catch (Throwable t) {
dealWithSauceFailureIfNecessary(t);
throw Throwables.propagate(t);
// retry if we got a 'sauce' failure
statement.evaluate();
}
}
};
Expand All @@ -122,6 +122,8 @@ private void dealWithSauceFailureIfNecessary(Throwable t) {
} catch (Exception e) {
throw new RuntimeException("Exception creating driver, after Sauce-detected exception", e);
}
} else {
throw Throwables.propagate(t);
}
}

Expand Down

0 comments on commit 58c194a

Please sign in to comment.