use of org.openqa.selenium.TimeoutException in project tuerauf-backend-java by dsteinkopf.
the class SeleniumHelper method waitForComponentWithClassName.
public static boolean waitForComponentWithClassName(final WebDriver webDriver, final String className) {
try {
final WebDriverWait wait = new WebDriverWait(webDriver, DEFAULT_PAGE_LOAD_WAIT);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
return true;
} catch (final TimeoutException te) {
logger.error(te);
return false;
}
}
use of org.openqa.selenium.TimeoutException in project tuerauf-backend-java by dsteinkopf.
the class SeleniumHelper method waitForComponentWithLocator.
public static boolean waitForComponentWithLocator(final WebDriver webDriver, final By locator) {
try {
final WebDriverWait wait = new WebDriverWait(webDriver, DEFAULT_PAGE_LOAD_WAIT);
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
return true;
} catch (final TimeoutException te) {
logger.error(te);
return false;
}
}
use of org.openqa.selenium.TimeoutException in project carina by zebrunner.
the class DriverHelper method waitUntil.
/**
* Wait until any condition happens.
*
* @param condition - ExpectedCondition.
* @param timeout - timeout.
* @return true if condition happen.
*/
public boolean waitUntil(ExpectedCondition<?> condition, long timeout) {
boolean result;
long startMillis = 0;
final WebDriver drv = getDriver();
Wait<WebDriver> wait = new WebDriverWait(drv, timeout, RETRY_TIME).ignoring(WebDriverException.class).ignoring(NoSuchSessionException.class);
try {
startMillis = System.currentTimeMillis();
wait.until(condition);
result = true;
LOGGER.debug("waitUntil: finished true...");
} catch (NoSuchElementException | TimeoutException e) {
// don't write exception even in debug mode
LOGGER.debug("waitUntil: NoSuchElementException | TimeoutException e..." + condition.toString());
result = false;
} catch (Exception e) {
LOGGER.error("waitUntil: " + condition.toString(), e);
result = false;
} finally {
long timePassed = System.currentTimeMillis() - startMillis;
// timePassed is time in ms timeout in sec so we have to adjust
if (timePassed > 2 * timeout * 1000) {
LOGGER.error("Your retry_interval is too low: " + RETRY_TIME + " ms! Increase it or upgrade your hardware");
}
}
return result;
}
use of org.openqa.selenium.TimeoutException in project carina by zebrunner.
the class DriverHelper method getPageSource.
/*
* Get and return the source of the last loaded page.
* @return String
*/
public String getPageSource() {
WebDriver drv = getDriver();
Messager.GET_PAGE_SOURCE.info();
Wait<WebDriver> wait = new FluentWait<WebDriver>(drv).pollingEvery(// there is no sense to refresh url address too often
Duration.ofMillis(5000)).withTimeout(Duration.ofSeconds(Configuration.getInt(Parameter.EXPLICIT_TIMEOUT))).ignoring(WebDriverException.class).ignoring(// org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'outerHTML' of null
JavascriptException.class);
String res = "";
try {
res = wait.until(new Function<WebDriver, String>() {
public String apply(WebDriver driver) {
return drv.getPageSource();
}
});
} catch (ScriptTimeoutException | TimeoutException e) {
Messager.FAIL_GET_PAGE_SOURCE.error();
}
Messager.GET_PAGE_SOURCE.info();
return res;
}
use of org.openqa.selenium.TimeoutException in project carina by zebrunner.
the class DriverHelper method getTitle.
/**
* Return page title.
*
* @param timeout long
* @return title String.
*/
public String getTitle(long timeout) {
WebDriver drv = getDriver();
Wait<WebDriver> wait = new FluentWait<WebDriver>(drv).pollingEvery(Duration.ofMillis(RETRY_TIME)).withTimeout(Duration.ofSeconds(timeout)).ignoring(WebDriverException.class).ignoring(// org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'outerHTML' of null
JavascriptException.class);
String res = "";
try {
res = wait.until(new Function<WebDriver, String>() {
public String apply(WebDriver driver) {
return drv.getTitle();
}
});
} catch (ScriptTimeoutException | TimeoutException e) {
Messager.FAIL_GET_TITLE.error();
}
return res;
}
Aggregations