|
13 | 13 |
|
14 | 14 | public class UITestUtil {
|
15 | 15 | /**
|
16 |
| - * If the modal is displayed, we wait 1 second and then check again if the modal is still there |
17 |
| - * The method checks for 10 seconds at intervals of 1 second (driver.findElement TimeOut |
18 |
| - * (defined by implictlyWait) (1 seconds) * counter (10)) if the modal disappeared |
| 16 | + * If modal is visible we wait for a maximum of 10 seconds for the modal to become invisible again. |
| 17 | + * If modal is not visible in the first place, we simply return |
19 | 18 | * */
|
20 | 19 | public static void waitForModalToDisappear(WebDriver driver) {
|
21 | 20 | By modalLocator = By.id("loading-modal");
|
22 |
| - /*boolean modalDisplayed = true; |
23 |
| - int counter = 11; |
24 |
| - |
25 |
| - driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); |
26 |
| - do { |
27 |
| - try { |
28 |
| - counter--; |
29 |
| - // If modal is not displayed, exception is thrown |
30 |
| - driver.findElement(modalLocator).isDisplayed(); |
31 |
| - modalDisplayed = counter>0; |
32 |
| - } catch (NoSuchElementException | StaleElementReferenceException e) { |
33 |
| - modalDisplayed = false; |
34 |
| - } |
35 |
| - } while(modalDisplayed); |
36 |
| - // Change timeout back to the defined value |
37 |
| - driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);*/ |
38 | 21 | driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
|
39 | 22 | try {
|
40 | 23 | new WebDriverWait(driver, 2).until(
|
41 | 24 | ExpectedConditions.visibilityOfElementLocated(modalLocator));
|
42 |
| - } catch (TimeoutException | NoSuchElementException e) { |
| 25 | + } catch (TimeoutException te) { |
| 26 | + // no modal displayed |
43 | 27 | return;
|
44 | 28 | }
|
45 | 29 | new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(modalLocator));
|
46 | 30 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
47 | 31 | }
|
48 | 32 |
|
49 |
| - |
50 | 33 | /**
|
51 | 34 | * Checks if the element is present or absent
|
52 | 35 | *
|
|
0 commit comments