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:com.worldline.easycukes.selenium.utils.SeleniumHelper.java

License:Open Source License

/**
 * @param driver//from   w  ww  .  j ava  2 s . com
 * @param by
 * @return
 */
public static WebElement waitForElementToBePresent(@NonNull final WebDriver driver, @NonNull final By by) {
    final FluentWait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);
    return wait.until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver webDriver) {
            try {
                if (webDriver.findElement(by).isDisplayed())
                    return webDriver.findElement(by);
                return null;
            } catch (final ElementNotVisibleException e) {
                return null;
            }
        }
    });
}

From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java

License:Open Source License

/**
 * @return/*from   w ww.j  av a2  s  .  co m*/
 */
public static void waitUntilElementIsHidden(@NonNull final WebDriver driver, @NonNull final By by) {
    // Waiting for an element to be present on the page, checking for its
    // presence once every second.
    final FluentWait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS).ignoring(TimeoutException.class);

    wait.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver webDriver) {
            try {
                log.debug("waiting for hidden " + by);
                final List<WebElement> list = webDriver.findElements(by);
                for (final WebElement webElement : list)
                    if (webElement.isDisplayed()) {
                        log.debug("Still displayed !");// TODO
                        return false;
                    }
                return true;
            } catch (final StaleElementReferenceException e) {
                return true;
            } catch (final NoSuchElementException e) {
                return true;
            }
        }
    });
}

From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java

License:Open Source License

/**
 * @param by/*w  w  w . j  a v a 2 s .c  o  m*/
 * @param text
 * @return
 */
public static void waitUntilElementContainsText(@NonNull final WebDriver driver, @NonNull final By by,
        @NonNull final String text, int timeout) {
    // Waiting for an element to be present on the page, checking for its
    // presence once every second.
    final FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(timeout, TimeUnit.SECONDS)
            .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS).ignoring(TimeoutException.class);

    wait.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver webDriver) {
            try {
                return webDriver.findElement(by).getText().contains(text);
            } catch (final StaleElementReferenceException e) {
                return false;
            } catch (final NoSuchElementException e) {
                return false;
            }
        }
    });
}

From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java

License:Open Source License

/**
 * @param by// ww w  . ja v  a 2s  .co m
 * @return
 */
public static void waitUntilElementContainsAttribute(@NonNull final WebDriver driver, @NonNull final By by,
        @NonNull final String attribute) {
    // Waiting for an element to be present on the page, checking for its
    // presence once every second.
    final FluentWait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS).ignoring(TimeoutException.class);

    wait.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver webDriver) {
            try {
                return StringUtils.isNotEmpty(webDriver.findElement(by).getAttribute(attribute));
            } catch (final StaleElementReferenceException e) {
                return false;
            } catch (final NoSuchElementException e) {
                return false;
            }
        }
    });
}

From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java

License:Open Source License

/**
 * @param text//from w  ww . j av  a 2 s.co m
 */
public static void waitUntilTextIsSelected(@NonNull final WebDriver driver, @NonNull final By by,
        @NonNull final String text) {
    final FluentWait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);

    wait.until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver webDriver) {
            final WebElement webElement = webDriver.findElement(by);
            new Select(webElement).selectByVisibleText(text);
            return webElement;
        }
    });
}

From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java

License:Open Source License

/**
 * @param by/*from w w w.j a  v  a2 s  .com*/
 * @return
 */
public static void waitUntilValueIsSelected(@NonNull final WebDriver driver, @NonNull final By by,
        @NonNull final String value) {
    final FluentWait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver webDriver) {
            try {
                final WebElement webElement = webDriver.findElement(by);
                new Select(webElement).selectByValue(value);
                return webElement.getAttribute("value").equals(value);
            } catch (final StaleElementReferenceException e) {
                return false;
            }
        }
    });
}

From source file:daveayan.gherkinsalad.components.core.BaseBrowserElement.java

License:Open Source License

public Element findElement(final By by) {
    if (by == null) {
        error("Cannot find element on the page with a null element locator");
        return NullElement.newInstance(element_locator);
    }/*from ww w.  j  av a2 s . c om*/
    if (browser.driver() instanceof NullWebDriver) {
        throw new AssertionError("Cannot find any element '" + by + "' on a NullWebDriver");
    }
    Wait<WebDriver> wait = new FluentWait<WebDriver>(browser.driver())
            .withTimeout(Config.seconds_timeout, TimeUnit.SECONDS)
            .pollingEvery(Config.seconds_poll_interval, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    WebElement _webElement;
    try {
        _webElement = wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                return driver.findElement(by);
            }
        });
    } catch (TimeoutException toe) {
        return NullElement.newInstance(element_locator);
    }
    return Element.newInstance(_webElement, name(), by);
}

From source file:daveayan.gherkinsalad.components.core.BaseBrowserElement.java

License:Open Source License

public Elements findElements(final By by) {
    if (by == null) {
        error("Cannot find element on the page with a null element locator");
        return Elements.nullInstance();
    }/*from  w ww .  ja v a2s .  co  m*/
    if (browser.driver() instanceof NullWebDriver) {
        throw new AssertionError("Cannot find any element '" + by + "' on a NullWebDriver");
    }
    Wait<WebDriver> wait = new FluentWait<WebDriver>(browser.driver())
            .withTimeout(Config.seconds_timeout, TimeUnit.SECONDS)
            .pollingEvery(Config.seconds_poll_interval, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    List<WebElement> _webElements;
    try {
        _webElements = wait.until(new Function<WebDriver, List<WebElement>>() {
            public List<WebElement> apply(WebDriver driver) {
                return driver.findElements(by);
            }
        });
    } catch (TimeoutException toe) {
        return Elements.nullInstance();
    }
    Elements elements = convertToElements(_webElements, by);
    return elements;
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processCheaperthandirt(WebDriver driver) {
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
    wait.until(new Predicate<WebDriver>() {
        public boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }/*from w ww  . j ava2 s.com*/
    });
    int size = driver
            .findElements(
                    By.id("ctl00_ctl00_ContentPlaceHolderTopLevel_ContentPlaceHolderItemList_displayTopDDL"))
            .size();
    if (size > 0) {
        Select dropdown = new Select(driver.findElement(
                By.id("ctl00_ctl00_ContentPlaceHolderTopLevel_ContentPlaceHolderItemList_displayTopDDL")));
        dropdown.selectByVisibleText("Show All");
    }

}

From source file:gov.nih.nci.firebird.commons.test.SentEmailChecker.java

License:Open Source License

/**
 * Will assert that the correct number of emails are received, providing a wait of
 * up to a default timeout (10 seconds) for those messages to be processed and received.
 *
 * @param expectedCount count of emails expected
 *///from  ww  w.ja  va 2s  .  c om
public void assertEmailCount(final int expectedCount) {
    Predicate<Integer> expectedNumberOfEmailsReceived = getExpectedEmailCountReceivedPredicate();
    try {
        new FluentWait<Integer>(expectedCount).withTimeout(61, TimeUnit.SECONDS)
                .until(expectedNumberOfEmailsReceived);
    } catch (TimeoutException e) {
        fail(getEmailCountFailureMessage(expectedCount));
    }
}