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:selenium_tumblr_test.BasePage.java

License:Open Source License

public void clickThenWaitForPageReload(By elementBy, int seconds) {

    try {/*from   www . java 2 s.c  om*/

        // first get page source timestamp
        long timeStampValue1 = getPageSourceTimestamp();

        // find element & click it
        WebElement element = driver.findElement(elementBy);
        element.click();

        // now wait until element is no longer present or timeout
        try {
            (new FluentWait(driver)).withTimeout(seconds, TimeUnit.SECONDS)
                    .pollingEvery(pollInterval, TimeUnit.SECONDS)
                    .ignoring(java.util.NoSuchElementException.class).until(new Predicate<WebDriver>() {
                        @Override
                        public boolean apply(WebDriver driver) {
                            long timeStampValue2 = getPageSourceTimestamp();
                            return timeStampValue1 != timeStampValue2;
                        }
                    });
        } catch (TimeoutException timeoutException) {

        }

        // handle any alerts if they pop up
    } catch (org.openqa.selenium.UnhandledAlertException unhandledAlertException) {
        try {
            // try to switch to the alert dialog and accept it
            Alert alert = driver.switchTo().alert();
            alert.accept();
        } catch (org.openqa.selenium.NoAlertPresentException noAlertPresentException) {
            // alert may have gone away. if so, then ignore
        }
    }

}

From source file:test.nov21.configuration.AbstractPage.java

License:Open Source License

public WebElement findChildElement(WebElement element, final By by) {
    Wait<WebElement> wait = new FluentWait<WebElement>(element).withTimeout(DRIVER_WAIT_TIME, TimeUnit.SECONDS)
            .ignoring(ElementNotVisibleException.class).ignoring(NoSuchElementException.class);

    return wait.until(new Function<WebElement, WebElement>() {
        @Override//www  .j a  v a  2s . c  o m
        public WebElement apply(WebElement webElement) {
            return webElement.findElement(by);
        }
    });
}

From source file:test.nov21.configuration.AbstractPage.java

License:Open Source License

public WebElement waitFluentForElement(final By by) {
    WebElement element = null;//from w  ww .  ja  v  a  2  s . c o  m
    Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriver()).withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(2, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    element = wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return getDriver().findElement(by);
        }
    });
    return element;
}

From source file:test.nov21.configuration.AbstractPage.java

License:Open Source License

/**
 * For waiting without WebDriver: Wait for function will be true or return some except false.
 *
 * @param condition        Function for waiting {@link Function}
 * @param waitWith         Object who will helping to wait (which will be passed to {@link Function#apply(Object)})
 * @param timeOutInSeconds Time-out in seconds
 * @param <F>              Type of waitWith param
 * @param <T>              Type of object which is waiting
 * @return Object which waiting for or null - is exceptions occured
 *//* w  ww. ja va 2s . c o  m*/
public static <F, T> T waitFor(Function<F, T> condition, F waitWith, long timeOutInSeconds) {
    Wait<F> wait = new FluentWait<>(waitWith).withTimeout(timeOutInSeconds, TimeUnit.SECONDS).pollingEvery(300,
            TimeUnit.MILLISECONDS);
    try {
        return wait.until(condition);
    } catch (Exception | AssertionError e) {
        LOG.warn("Waiting was not successfull", e);
    }
    return null;
}

From source file:test.seleniumbugmvn.Main.java

public static void waitFor(final long milliseconds) {
    final long start = System.currentTimeMillis();
    FluentWait<By> fluentWait = new FluentWait<>(By.tagName("body"));
    final long timeout = milliseconds;
    fluentWait.pollingEvery(10, TimeUnit.MILLISECONDS).withTimeout(30, TimeUnit.SECONDS)
            .until(new Predicate<By>() {

                @Override//from  w w  w  . j  a  v a  2 s.co m
                public boolean apply(By by) {
                    return System.currentTimeMillis() - start >= timeout;
                }
            });
}

From source file:uk.ac.ebi.atlas.acceptance.selenium.pages.BioEntityPage.java

License:Apache License

public void clickDiffResultsDisplayLevelsButton() {
    new FluentWait<>(driver).withTimeout(15, TimeUnit.SECONDS).pollingEvery(250, TimeUnit.MILLISECONDS)
            .until(ExpectedConditions.visibilityOf(diffResultsDisplayLevelsButton));

    diffResultsDisplayLevelsButton.click();
}

From source file:uk.ac.ebi.atlas.acceptance.selenium.pages.ExperimentsTablePage.java

License:Apache License

private void waitForExperimentTableToLoad() {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    wait.until(ExpectedConditions.invisibilityOfElementWithText(
            By.xpath("//*[@id=\"experiments-table\"]/tbody/tr/td"), "Loading..."));
}

From source file:uk.ac.ebi.atlas.acceptance.selenium.pages.HeatmapTablePage.java

License:Apache License

public void clickDisplayLevelsButton() {
    WebElement displayLevelsButton = getDisplayLevelsButton();

    new FluentWait<>(driver).withTimeout(15, TimeUnit.SECONDS).pollingEvery(250, TimeUnit.MILLISECONDS)
            .until(ExpectedConditions.visibilityOf(displayLevelsButton));

    displayLevelsButton.click();//  ww  w  . j a  v a 2  s  .c  om
}

From source file:utils.WebDriverUtils.java

public static void waitForFileDownload(String prepaidcardCvsPath) {
    FluentWait<File> waiter = new FluentWait<File>(new File(prepaidcardCvsPath));
    waiter.withTimeout(30, TimeUnit.SECONDS);
    waiter.pollingEvery(1000, TimeUnit.MILLISECONDS);
    waiter.until(new Predicate<File>() {
        @Override/*from   w w  w . ja  v a2  s  .co m*/
        public boolean apply(File input) {
            return input.exists() && input.length() > 0;
        }
    });
}