Search in sources :

Example 1 with NoSuchSessionException

use of org.openqa.selenium.NoSuchSessionException in project carina by qaprosoft.

the class ExtendedWebElement method waitUntil.

/**
 * Wait until any condition happens.
 *
 * @param condition - ExpectedCondition.
 * @param timeout - timeout.
 * @return true if condition happen.
 */
private boolean waitUntil(ExpectedCondition<?> condition, long timeout) {
    if (timeout <= 0) {
        LOGGER.error("Fluent wait with 0 and less timeout might hangs! Updating to 1 sec.");
        timeout = 1;
    }
    boolean result;
    originalException = null;
    final WebDriver drv = getDriver();
    Wait<WebDriver> wait = new WebDriverWait(drv, timeout, RETRY_TIME);
    // [VD] Notes:
    // StaleElementReferenceException is handled by selenium ExpectedConditions in many methods
    // do not ignore TimeoutException or NoSuchSessionException otherwise you can wait for minutes instead of timeout!
    LOGGER.debug("waitUntil: starting... timeout: " + timeout);
    try {
        wait.until(condition);
        result = true;
    } catch (NoSuchElementException e) {
        // don't write exception even in debug mode
        // [VD] don't operate with condition.toString() etc as it might generate org.openqa.selenium.json.JsonException xpected to read a START_MAP but instead have: END. Last 0 characters read
        LOGGER.debug("waitUntil: NoSuchElementException: " + e.getMessage());
        result = false;
        originalException = e;
    } catch (NoSuchSessionException e) {
        LOGGER.debug("waitUntil: NoSuchSessionException: " + e.getMessage());
        result = false;
        originalException = e.getCause();
    } catch (TimeoutException e) {
        LOGGER.debug("waitUntil: TimeoutException: " + e.getMessage());
        result = false;
        originalException = e.getCause();
    } catch (WebDriverException e) {
        LOGGER.debug("waitUntil: WebDriverException: " + e.getMessage());
        result = false;
        originalException = e.getCause();
    } catch (Exception e) {
        LOGGER.error("waitUntil: undefined exception.", e);
        result = false;
        // TODO: e or e.getCause()?
        originalException = e;
    }
    return result;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NoSuchElementException(org.openqa.selenium.NoSuchElementException) DriverPoolException(com.qaprosoft.carina.core.foundation.exception.DriverPoolException) InvalidElementStateException(org.openqa.selenium.InvalidElementStateException) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) TimeoutException(org.openqa.selenium.TimeoutException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) WebDriverException(org.openqa.selenium.WebDriverException) JsonException(org.openqa.selenium.json.JsonException) IOException(java.io.IOException) ElementNotInteractableException(org.openqa.selenium.ElementNotInteractableException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

DriverPoolException (com.qaprosoft.carina.core.foundation.exception.DriverPoolException)1 IOException (java.io.IOException)1 ElementNotInteractableException (org.openqa.selenium.ElementNotInteractableException)1 InvalidElementStateException (org.openqa.selenium.InvalidElementStateException)1 NoSuchElementException (org.openqa.selenium.NoSuchElementException)1 NoSuchSessionException (org.openqa.selenium.NoSuchSessionException)1 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)1 TimeoutException (org.openqa.selenium.TimeoutException)1 WebDriver (org.openqa.selenium.WebDriver)1 WebDriverException (org.openqa.selenium.WebDriverException)1 JsonException (org.openqa.selenium.json.JsonException)1 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)1 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)1 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)1