Skip to content

Commit

Permalink
Emphasize predicate failure over timeout details.
Browse files Browse the repository at this point in the history
Rewording the FluentWait error message to emphasize
the predicate failure over timeout details reduces
the eagerness of engineers to immediately jump to
the conclusion that they just need to wait *longer*
(must be some random WebDriver flakiness/timeout
issue) which is not usually the appropriate fix -
rather than think about the actual cause of the
predicate failure and conceptually group similar
failures appropriately.

Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
  • Loading branch information
joshbruning authored and lukeis committed Apr 13, 2016
1 parent f426cde commit 1e39027
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,10 @@ public <V> V until(Function<? super T, V> isTrue) {
String message = messageSupplier != null ?
messageSupplier.get() : null;

String toAppend = message == null ?
" waiting for " + isTrue.toString() : ": " + message;

String timeoutMessage = String.format("Timed out after %d seconds%s",
timeout.in(SECONDS), toAppend);
String timeoutMessage = String.format(
"Expected condition failed: %s (tried for %d second(s) with %s interval)",
message == null ? "waiting for " + isTrue : message,
timeout.in(SECONDS), interval);
throw timeoutException(timeoutMessage, lastException);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public void timeoutMessageIncludesLastIgnoredException() {
@Test
public void timeoutMessageIncludesCustomMessage() {
TimeoutException expected = new TimeoutException(
"Timed out after 0 seconds: Expected custom timeout message");
"Expected condition failed: Expected custom timeout message "
+ "(tried for 0 second(s) with 500 MILLISECONDS interval)");

when(mockClock.laterBy(0L)).thenReturn(2L);
when(mockCondition.apply(mockDriver)).thenReturn(null);
Expand All @@ -195,7 +196,8 @@ public void timeoutMessageIncludesCustomMessage() {
@Test
public void timeoutMessageIncludesCustomMessageEvaluatedOnFailure() {
TimeoutException expected = new TimeoutException(
"Timed out after 0 seconds: external state");
"Expected condition failed: external state "
+ "(tried for 0 second(s) with 500 MILLISECONDS interval)");

when(mockClock.laterBy(0L)).thenReturn(2L);
when(mockCondition.apply(mockDriver)).thenReturn(null);
Expand Down Expand Up @@ -223,7 +225,8 @@ public String get() {
@Test
public void timeoutMessageIncludesToStringOfCondition() {
TimeoutException expected = new TimeoutException(
"Timed out after 0 seconds waiting for toString called");
"Expected condition failed: waiting for toString called "
+ "(tried for 0 second(s) with 500 MILLISECONDS interval)");

Function<Object, Boolean> condition = new Function<Object, Boolean>() {
public Boolean apply(Object ignored) {
Expand Down

0 comments on commit 1e39027

Please sign in to comment.