Skip to content

Commit

Permalink
fix: prevent NullPointerException when webdriver.timeouts.implicitlyw…
Browse files Browse the repository at this point in the history
…ait=0
  • Loading branch information
leonsabr authored and eroshenkoam committed Mar 12, 2018
1 parent f4e5cf5 commit 64d5857
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public Object invoke(Object o, Method method, Object[] objects) throws Throwable
return name;
}

long end = this.clock.laterBy(TimeUnit.SECONDS.toMillis(this.timeOutInSeconds));
final long end = this.clock.laterBy(TimeUnit.SECONDS.toMillis(this.timeOutInSeconds));

StaleElementReferenceException lasException = null;
while (this.clock.isNowBefore(end)) {
StaleElementReferenceException lastException;
do {
try {
return super.invoke(o, method, objects);
} catch (StaleElementReferenceException e) {
lasException = e;
lastException = e;
this.waitFor();
}
}
throw lasException;
} while (this.clock.isNowBefore(end));
throw lastException;
}

protected long sleepFor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ public void classFieldsTimeout() throws NoSuchFieldException {

@Test
public void timeoutWithSystemProperty() {
System.setProperty("webdriver.timeouts.implicitlywait", "1");
Assert.assertEquals(1, factory.getTimeOut(HtmlElement.class));
final String propertyName = "webdriver.timeouts.implicitlywait";
final String previousTimeout = System.getProperty(propertyName);
System.setProperty(propertyName, "1");
try {
Assert.assertEquals(1, factory.getTimeOut(HtmlElement.class));
} finally {
if (previousTimeout == null) {
System.getProperties().remove(propertyName);
} else {
System.setProperty(propertyName, previousTimeout);
}
}
}
}

0 comments on commit 64d5857

Please sign in to comment.