Search in sources :

Example 31 with TimeoutException

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;
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException)

Example 32 with TimeoutException

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;
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException)

Example 33 with TimeoutException

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Example 34 with TimeoutException

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Function(java.util.function.Function) FluentWait(org.openqa.selenium.support.ui.FluentWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Example 35 with TimeoutException

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Function(java.util.function.Function) FluentWait(org.openqa.selenium.support.ui.FluentWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Aggregations

TimeoutException (org.openqa.selenium.TimeoutException)240 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)102 WebElement (org.openqa.selenium.WebElement)84 NoSuchElementException (org.openqa.selenium.NoSuchElementException)50 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)40 WebDriver (org.openqa.selenium.WebDriver)39 WebDriverException (org.openqa.selenium.WebDriverException)39 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)31 MessageEvent (org.cerberus.engine.entity.MessageEvent)27 ExpectedConditions (org.openqa.selenium.support.ui.ExpectedConditions)27 Reporter (com.coveros.selenified.utilities.Reporter)26 Test (org.junit.Test)24 By (org.openqa.selenium.By)22 Test (org.testng.annotations.Test)20 Element (com.coveros.selenified.element.Element)17 AnswerItem (org.cerberus.util.answer.AnswerItem)17 IOException (java.io.IOException)16 Dimension (org.openqa.selenium.Dimension)14 Point (org.openqa.selenium.Point)14 Constants (com.coveros.selenified.utilities.Constants)13