Example usage for org.openqa.selenium.support.ui FluentWait FluentWait

List of usage examples for org.openqa.selenium.support.ui FluentWait FluentWait

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui FluentWait FluentWait.

Prototype

public FluentWait(T input) 

Source Link

Usage

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static boolean waitForJQuery(WebDriver driver, final By by, int timeOutInMiliSeconds,
        int pollingInMiliSeconds) {
    try {/*  w  w w . j av a  2s.  com*/
        new FluentWait<>(driver).withTimeout(timeOutInMiliSeconds, TimeUnit.MILLISECONDS)
                .pollingEvery(pollingInMiliSeconds, TimeUnit.MILLISECONDS)
                .until(new ExpectedCondition<Boolean>() {
                    @Override
                    public Boolean apply(WebDriver driver) {
                        return ((Boolean) ((JavascriptExecutor) driver).executeScript(
                                "return (typeof jQuery === 'undefined') || (jQuery.active == 0 && $(\":animated\").length == 0)"))
                                && exists(driver, by);
                    }
                });

        return true;
    } catch (TimeoutException ex) {
        return false;
    }
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static boolean waitForJQuery(WebDriver driver, int timeOutInMiliSeconds, int pollingInMiliSeconds) {
    try {/*from  ww  w. j a va2 s.com*/
        new FluentWait<>(driver).withTimeout(timeOutInMiliSeconds, TimeUnit.MILLISECONDS)
                .pollingEvery(pollingInMiliSeconds, TimeUnit.MILLISECONDS)
                .until(new ExpectedCondition<Boolean>() {
                    @Override
                    public Boolean apply(WebDriver driver) {
                        return ((Boolean) ((JavascriptExecutor) driver).executeScript(
                                "return (typeof jQuery === 'undefined') || (jQuery.active == 0 && $(\":animated\").length == 0)"));
                    }
                });

        return true;
    } catch (TimeoutException ex) {
        return false;
    }
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java

License:Apache License

private FluentWait<WebDriver> getWait(long duration) {
    try {/*from   w w w.java2s.  c  om*/
        return new FluentWait<>((((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver()))
                .withTimeout(duration, SECONDS).pollingEvery(5, SECONDS).ignoring(NoSuchElementException.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 * Wait for./*from w ww  .j a v a 2  s .  com*/
 * @param predicate {@link Predicate}
 */
protected void waitUntil(final Predicate<WebDriver> predicate) {
    new FluentWait<>(getDriver()).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(TIMEOUT, TimeUnit.MILLISECONDS).until(predicate);
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitPresent -//w  w  w .  j av a2 s  .c o m
 * @param locator
 * @see fluentWaitPresent(final WebElement element)
 * @return
 */
public boolean fluentWaitPresent(final String locator) {

    logger.info("INFO: Fluentwait for element: " + locator);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            return isPresent(locator);
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitWebElementNotPresent -/*from   w  w w .j  av a2s.c om*/
 * @param locator
 * @return
 */
public boolean fluentWaitNotPresent(final String locator) {

    logger.info("INFO: Fluentwait for element to not be present: " + locator);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            return !isPresent(locator);
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitTextPresent -/*from  w w  w. ja  v  a  2 s  . c o  m*/
 * @param text
 * @return
 */
public boolean fluentWaitTextPresent(final String text) {

    logger.info("INFO: FluentWait for text: " + text);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            return isTextPresent(text);
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitVisible -//  w  w w  .j av a 2 s  .c  om
 * @param locator
 * @return
 */
public boolean fluentWaitVisible(final String locator) {

    logger.info("INFO: Fluentwait for visibility of element: " + locator);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            boolean elementPresent = false;
            if (!elementPresent) {
                elementPresent = findElement(locator).isDisplayed();
            }
            return elementPresent;
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitVisibleRefresh -//from   w  w  w.  j a  va2s  .  co  m
 * @param locator
 * @return
 */
public boolean fluentWaitVisibleRefresh(final String locator) {

    logger.info("INFO: Fluentwait for visibility of element: " + locator);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            boolean elementPresent = false;
            if (!elementPresent) {
                elementPresent = findElement(locator).isDisplayed();
                driver.navigate().refresh();
            }
            return elementPresent;
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitAttrChange - Method to wait for attribute change
 * @param locator - Use .attribute()//from  w w  w  .ja v  a  2  s .c o m
 * @see fluentWaitPresent(final WebElement element)
 * @return
 */
public boolean fluentWaitAttrChange(final String locator, final String attrib, final String value) {

    logger.info("INFO: Fluentwait for " + locator + " " + attrib + " to change to " + value);

    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean foo = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            WebElement element = findElement(locator);
            String attribValue = element.getAttribute(attrib);
            logger.info("INFO: Current Attribute value: " + attribValue);
            return attribValue.contains(value);
        }
    });
    return foo;
}