package com.specmate.uitests.pagemodel;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class UITestUtil {
	public static void waitForModalToDisappear(WebDriver driver) {
		By modalLocator = By.id("loading-modal");
		try {
			driver.findElement(modalLocator).isDisplayed();
		} catch (TimeoutException te) {
			// Modal did not appear
			return;
		} catch (NoSuchElementException ne) {
			// Modal did not appear
			return; 
		}
		new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(modalLocator));
	}
}

@@ -47,129 +47,40 @@
 ort 
-org.openqa.selenium.By;%0D%0Aimport org.openqa.selenium.NoSuchElementException;%0D%0Aimport org.openqa.selenium.TimeoutException;
+java.util.concurrent.TimeUnit;%0D%0A
 %0D%0Aim
@@ -104,25 +104,18 @@
 elenium.
-WebDriver
+By
 ;%0D%0Aimpor
@@ -140,37 +140,30 @@
 ium.
-support.ui.ExpectedCondi
+NoSuchElementExcep
 tion
-s
 ;%0D%0Ai
@@ -192,19 +192,8 @@
 ium.
-support.ui.
 WebD
@@ -197,20 +197,16 @@
 ebDriver
-Wait
 ;%0D%0A%0D%0Apub
@@ -345,142 +345,380 @@
 %0D%0A%09%09
-try %7B%0D%0A%09%09%09driver.findElement(modalLocator).isDisplayed();%0D%0A%09%09%7D catch (TimeoutException te) %7B%0D%0A%09%09%09// Modal did not appear%0D%0A%09%09%09return;%0D%0A
+/*%0D%0A%09%09 * %09If modal is present, wait till it vanishes%0D%0A%09%09 * %09If it modal is not present resume%0D%0A%09%09 * */%0D%0A%09%09%0D%0A%09%09boolean modalDisplayed = true;%0D%0A    %09int counter = 6;%0D%0A    %09driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);%0D%0A    %09do %7B%0D%0A    %09%09try %7B%0D%0A    %09%09%09counter--;%0D%0A    %09%09%09modalDisplayed = ((counter%3E0) && driver.findElement(modalLocator).isDisplayed());%0D%0A    
 %09%09%7D 
@@ -751,167 +751,215 @@
 ion 
-n
 e) %7B%0D%0A
-%09%09%09// Modal did not appear%0D%0A%09%09%09return; %0D%0A%09%09%7D%0D%0A%09%09new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(modalLocator));
+    %09%09%09modalDisplayed = false;%0D%0A    %09%09%7D%0D%0A    %09%7D while(modalDisplayed);%0D%0A    %09// Change timeout back to the defined value%0D%0A        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);%0D%0A%09%09
 %0D%0A%09%7D%0D%0A%7D
-%0D%0A

Change modal method