Example usage for org.openqa.selenium TimeoutException TimeoutException

List of usage examples for org.openqa.selenium TimeoutException TimeoutException

Introduction

In this page you can find the example usage for org.openqa.selenium TimeoutException TimeoutException.

Prototype

public TimeoutException(Throwable cause) 

Source Link

Usage

From source file:io.openvidu.test.OpenViduClientBrowserTest.java

License:Apache License

public void waitWhileElement(String label, Browser browser, String id) throws TimeoutException {
    int originalTimeout = 60;
    try {//from  w  w w  . j av  a  2 s  . c  o m
        originalTimeout = browser.getTimeout();
        log.debug("Original browser timeout (s): {}, set to 1", originalTimeout);
        browser.setTimeout(1);
        browser.changeTimeout(1);
        new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY)
                .until(ExpectedConditions.invisibilityOfElementLocated(By.id(id)));
    } catch (org.openqa.selenium.TimeoutException e) {
        log.warn("Timeout when waiting for element {} to disappear in browser {}", id, label, e);
        throw new TimeoutException(
                "Element with id='" + id + "' is present in page after " + testTimeout + " seconds");
    } finally {
        browser.setTimeout(originalTimeout);
        browser.changeTimeout(originalTimeout);
    }
}

From source file:org.alfresco.FetchTest.java

License:Open Source License

public WebElement findAndWait(final By by) {
    FluentWait<By> fluentWait = new FluentWait<By>(by);
    fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS);
    fluentWait.withTimeout(5000, TimeUnit.MILLISECONDS);
    try {//  w w w .  j av a  2s. co m
        fluentWait.until(new Predicate<By>() {
            public boolean apply(By by) {
                try {
                    return driver.findElement(by).isDisplayed();
                } catch (NoSuchElementException ex) {
                    return false;
                }
            }
        });
        return driver.findElement(by);
    } catch (RuntimeException re) {
        throw new TimeoutException("Unable to locate element " + by);
    }
}

From source file:org.alfresco.po.PageElement.java

License:Open Source License

/**
 * Helper method to find a {@link WebElement} with a time limit in milliseconds. During the wait period it will check for the element every 100 millisecond.
 * //from  w  ww  .j a  va  2s .  c o m
 * @param by {@link By} criteria to search by
 * @param limit time limit
 * @param interval polling frequency
 * @return {@link WebElement} HTML element
 */
public WebElement findAndWait(final By by, final long limit, final long interval) {
    FluentWait<By> fluentWait = new FluentWait<By>(by);
    fluentWait.pollingEvery(interval, TimeUnit.MILLISECONDS);
    fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS);
    try {
        fluentWait.until(new Predicate<By>() {
            public boolean apply(By by) {
                try {
                    return driver.findElement(by).isDisplayed();
                } catch (NoSuchElementException ex) {
                    return false;
                }
            }
        });
        return driver.findElement(by);
    } catch (RuntimeException re) {
        throw new TimeoutException("Unable to locate element " + by);
    }

}

From source file:org.apache.falcon.regression.ui.pages.Page.java

License:Apache License

/**
 * Wait until WebElement became visible.
 * @param xpath xpath of expected WebElement
 * @param timeoutSeconds how many seconds we should wait for visibility
 * @param errMessage message for TimeoutException
 *///w  w w . j a  va2  s .c  o  m
public void waitForDisplayed(String xpath, long timeoutSeconds, String errMessage) {
    waitForElement(xpath, timeoutSeconds, errMessage);
    WebElement element = driver.findElement(By.xpath(xpath));
    for (int i = 0; i < timeoutSeconds * 10; i++) {
        if (element.isDisplayed()) {
            return;
        }
        TimeUtil.sleepSeconds(0.1);
    }
    throw new TimeoutException(errMessage);
}

From source file:org.apache.falcon.regression.ui.pages.Page.java

License:Apache License

private void waitForElementAction(WebElement webElement, String xpath, long timeoutSeconds, String errMessage,
        boolean expected) {
    try {//from w w w .  j  av  a  2  s  . co m
        new WebDriverWait(driver, timeoutSeconds).until(new Condition(webElement, xpath, expected));
    } catch (TimeoutException e) {
        TimeoutException ex = new TimeoutException(errMessage);
        ex.initCause(e);
        throw ex;
    }
}

From source file:org.kitodo.selenium.testframework.pages.Page.java

License:Open Source License

/**
 * Clicks a button which could be be stale, e.g. because of disabling and
 * enabling via Ajax. After click was performed, the browser waits for
 * redirecting to given url.//  w w  w.java2 s .com
 *
 * @param button
 *            the button to be clicked
 * @param url
 *            the url to which is redirected after click
 */
protected void clickButtonAndWaitForRedirect(WebElement button, String url) {
    WebDriverWait webDriverWait = new WebDriverWait(Browser.getDriver(), 60);
    for (int attempt = 1; attempt < 4; attempt++) {
        try {
            await("Wait for button clicked").pollDelay(700, TimeUnit.MILLISECONDS).atMost(30, TimeUnit.SECONDS)
                    .ignoreExceptions().until(() -> isButtonClicked.matches(button));
            webDriverWait.until(ExpectedConditions.urlContains(url));
            return;
        } catch (TimeoutException e) {
            logger.error("Clicking on button with id " + button.getAttribute("id")
                    + " was not successful. Retrying now.");
        }
    }
    throw new TimeoutException("Could not access button: " + button.getAttribute("id") + "!");
}

From source file:org.neo4j.server.webdriver.Condition.java

License:Open Source License

public void waitUntilFulfilled(long timeout, String errorMessage) {
    timeout = new Date().getTime() + timeout;
    while ((new Date().getTime()) < timeout) {
        try {/*from   w  ww.  j  av a  2  s.  co m*/
            Thread.sleep(50);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        if (matcher.matches(state)) {
            return;
        }
    }

    throw new TimeoutException(errorMessage);
}

From source file:org.openmrs.reference.page.AddEditUserPage.java

License:Mozilla Public License

public void unassignRole(String roleToUnassign) {
    waitForElement(By.id(roleToUnassign));
    WebElement roleElement;//from w w w  . j a v a2 s .co  m
    Long startTime = System.currentTimeMillis();
    while (true) {
        if ((System.currentTimeMillis() - startTime) > 30000) {
            throw new TimeoutException("Couldn't uncheck a role in 30 seconds");
        }
        roleElement = findElement(By.id(roleToUnassign));
        if (roleElement.getAttribute("checked") != null && roleElement.getAttribute("checked").equals("true")) {
            roleElement.click();
        } else {
            break;
        }
    }
}

From source file:org.polimi.zarathustra.webdriver.LocalWebdriverWorker.java

License:Open Source License

/**
 * Returns a Document representation of the DOM at the provided url. Before navigating to the url,
 * all cookies are deleted.// w  w  w .j  a  v  a2 s  .  c o  m
 * 
 * @param url The full, absolute URL to fetch the DOM from.
 * @return A well formatted Document.
 */
public Document getDocument(final String url) {
    MonitorThread monitor = new MonitorThread(hardLimitTimeoutSeconds, new Runnable() {
        @Override
        public void run() {
            driver.quit();
            throw new TimeoutException("Timedout while retrieving DOM for " + url);
        }
    });
    monitor.setDaemon(true);
    driver.manage().deleteAllCookies();
    driver.get(url);
    String page = driver.getPageSource();
    monitor.done();
    Preconditions.checkNotNull(url);
    return WebdriverHelper.getDom(page);
}

From source file:org.polimi.zarathustra.webdriver.LocalWebdriverWorker.java

License:Open Source License

public Document getDocumentAndStoreSource(final String url, File outputDir, String fileName) {
    MonitorThread monitor = new MonitorThread(hardLimitTimeoutSeconds, new Runnable() {
        @Override//from w  w  w  . j  a v  a  2  s . co m
        public void run() {
            driver.quit();
            throw new TimeoutException("Timedout while retrieving DOM for " + url);
        }
    });
    monitor.setDaemon(true);
    driver.manage().deleteAllCookies();
    driver.get(url);
    // TODO(claudio): handle download errors, truncated pages, weird redirects (e.g. opendns)
    String page = driver.getPageSource();
    storeHtmlSource(outputDir, fileName, page);
    monitor.done();
    Preconditions.checkNotNull(url);
    return WebdriverHelper.getDom(page);
}