|
34 | 34 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
|
35 | 35 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElements;
|
36 | 36 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElementsLocatedBy;
|
| 37 | +import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfwindowsToBe; |
37 | 38 |
|
38 | 39 | import com.google.common.collect.Lists;
|
| 40 | +import com.google.common.collect.Sets; |
39 | 41 |
|
40 | 42 | import org.junit.Before;
|
41 | 43 | import org.junit.Test;
|
|
48 | 50 | import org.openqa.selenium.StaleElementReferenceException;
|
49 | 51 | import org.openqa.selenium.TimeoutException;
|
50 | 52 | import org.openqa.selenium.WebDriver;
|
| 53 | +import org.openqa.selenium.WebDriverException; |
51 | 54 | import org.openqa.selenium.WebElement;
|
52 | 55 |
|
53 | 56 | import java.util.List;
|
| 57 | +import java.util.Set; |
54 | 58 | import java.util.concurrent.TimeUnit;
|
55 | 59 |
|
56 | 60 | /**
|
@@ -432,14 +436,41 @@ public void waitingElementSelectionStateToBeFalseReturnsTrue() {
|
432 | 436 | public void waitingElementSelectionStateToBeThrowsTimeoutExceptionWhenStateDontMatch() {
|
433 | 437 | when(mockElement.isSelected()).thenReturn(true);
|
434 | 438 |
|
435 |
| - assertTrue(wait.until(elementSelectionStateToBe(mockElement, false))); |
| 439 | + wait.until(elementSelectionStateToBe(mockElement, false)); |
436 | 440 | }
|
437 | 441 |
|
438 | 442 | @Test(expected = StaleElementReferenceException.class)
|
439 | 443 | public void waitingElementSelectionStateToBeThrowsStaleExceptionWhenElementIsStale() {
|
440 | 444 | when(mockElement.isSelected()).thenThrow(new StaleElementReferenceException("Stale element"));
|
441 | 445 |
|
442 |
| - assertTrue(wait.until(elementSelectionStateToBe(mockElement, false))); |
| 446 | + wait.until(elementSelectionStateToBe(mockElement, false)); |
| 447 | + } |
| 448 | + |
| 449 | + @Test |
| 450 | + public void waitingNumberOfWindowsToBeTwoWhenThereAreTwoWindowsOpen() { |
| 451 | + Set<String> twoWindowHandles = Sets.newHashSet("w1", "w2"); |
| 452 | + when(mockDriver.getWindowHandles()).thenReturn(twoWindowHandles); |
| 453 | + |
| 454 | + assertTrue(wait.until(numberOfwindowsToBe(2))); |
| 455 | + } |
| 456 | + |
| 457 | + @Test(expected = TimeoutException.class) |
| 458 | + public void waitingNumberOfWindowsToBeTwoThrowsTimeoutExceptionWhenThereAreThreeWindowsOpen() { |
| 459 | + Set<String> threeWindowHandles = Sets.newHashSet("w1", "w2", "w3"); |
| 460 | + when(mockDriver.getWindowHandles()).thenReturn(threeWindowHandles); |
| 461 | + |
| 462 | + wait.until(numberOfwindowsToBe(2)); |
| 463 | + |
| 464 | + // then TimeoutException is thrown |
| 465 | + } |
| 466 | + |
| 467 | + @Test(expected = TimeoutException.class) |
| 468 | + public void waitingNumberOfWindowsToBeThrowsTimeoutExceptionWhenGetWindowHandlesThrowsWebDriverException() { |
| 469 | + when(mockDriver.getWindowHandles()).thenThrow(WebDriverException.class); |
| 470 | + |
| 471 | + wait.until(numberOfwindowsToBe(2)); |
| 472 | + |
| 473 | + // then TimeoutException is thrown |
443 | 474 | }
|
444 | 475 |
|
445 | 476 | interface GenericCondition extends ExpectedCondition<Object> {}
|
|
0 commit comments