|
18 | 18 | package org.openqa.selenium;
|
19 | 19 |
|
20 | 20 | import static java.util.concurrent.TimeUnit.SECONDS;
|
21 |
| -import static org.hamcrest.Matchers.anyOf; |
22 | 21 | import static org.hamcrest.Matchers.equalTo;
|
23 | 22 | import static org.hamcrest.Matchers.greaterThan;
|
24 | 23 | import static org.hamcrest.Matchers.instanceOf;
|
|
56 | 55 | import org.junit.Test;
|
57 | 56 | import org.openqa.selenium.remote.CapabilityType;
|
58 | 57 | import org.openqa.selenium.remote.DesiredCapabilities;
|
| 58 | +import org.openqa.selenium.support.ui.ExpectedCondition; |
59 | 59 | import org.openqa.selenium.support.ui.WebDriverWait;
|
60 | 60 | import org.openqa.selenium.testing.Ignore;
|
61 | 61 | import org.openqa.selenium.testing.JUnit4TestBase;
|
@@ -267,7 +267,32 @@ public void testShouldDoNothingIfThereIsNothingToGoBackTo() {
|
267 | 267 |
|
268 | 268 | driver.navigate().back();
|
269 | 269 | // We may have returned to the browser's home page
|
270 |
| - assertThat(driver.getTitle(), anyOf(equalTo(originalTitle), equalTo("We Leave From Here"))); |
| 270 | + wait.until(either(titleIs(originalTitle), titleIs("We Leave From Here"))); |
| 271 | + } |
| 272 | + |
| 273 | + /** |
| 274 | + * A logical OR of the two given conditions. |
| 275 | + * TODO: Move to ExpectedConditions: generalize to N conditions, unit test. |
| 276 | + */ |
| 277 | + public static ExpectedCondition<Object> either( |
| 278 | + final ExpectedCondition<?> one, |
| 279 | + final ExpectedCondition<?> two) { |
| 280 | + return new ExpectedCondition<Object>() { |
| 281 | + @Override |
| 282 | + public Object apply(WebDriver driver) { |
| 283 | + Object result = one.apply(driver); |
| 284 | + if (result != null && !Boolean.FALSE.equals(result)) { |
| 285 | + return result; |
| 286 | + } else { |
| 287 | + return two.apply(driver); |
| 288 | + } |
| 289 | + } |
| 290 | + |
| 291 | + @Override |
| 292 | + public String toString() { |
| 293 | + return "either of the conditions to be valid: " + one + ", " + two; |
| 294 | + } |
| 295 | + }; |
271 | 296 | }
|
272 | 297 |
|
273 | 298 | @Ignore(value = {ANDROID, SAFARI, MARIONETTE}, issues = {3771})
|
@@ -436,7 +461,7 @@ public void testShouldTimeoutIfAPageTakesTooLongToLoadAfterClick() {
|
436 | 461 |
|
437 | 462 | start = System.currentTimeMillis();
|
438 | 463 | driver.get(pages.xhtmlTestPage);
|
439 |
| - assertThat(driver.getTitle(), equalTo("XHTML Test Page")); |
| 464 | + wait.until(titleIs("XHTML Test Page")); |
440 | 465 | end = System.currentTimeMillis();
|
441 | 466 | duration = (int) (end - start);
|
442 | 467 | assertThat(duration, lessThan(2000));
|
@@ -510,7 +535,9 @@ public void testShouldNotStopLoadingPageAfterTimeout() {
|
510 | 535 | assertThat(duration, greaterThan(2000));
|
511 | 536 | assertThat(duration, lessThan(5000));
|
512 | 537 |
|
513 |
| - wait.until(elementTextToEqual(By.tagName("body"), "Slept for 5s")); |
| 538 | + new WebDriverWait(driver, 30) |
| 539 | + .ignoring(StaleElementReferenceException.class) |
| 540 | + .until(elementTextToEqual(By.tagName("body"), "Slept for 5s")); |
514 | 541 | end = System.currentTimeMillis();
|
515 | 542 | duration = (int) (end - start);
|
516 | 543 | assertThat(duration, greaterThan(5000));
|
|
0 commit comments