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:gov.nih.nci.firebird.selenium2.tests.account.InvestigatorRefreshFromNesTest.java

License:Open Source License

private void checkInvestigatorUpdatedFromNes() {
    Predicate<Person> noUpdatePending = new Predicate<Person>() {
        @Override// ww  w  .  j  a  v a  2 s .co m
        public boolean apply(Person investigator) {
            dataSet.reload();
            investigator = dataSet.getInvestigator().getPerson();
            return !investigator.isUpdatePending();
        }
    };
    new FluentWait<Person>(investigator).withTimeout(10, TimeUnit.SECONDS).until(noUpdatePending);
}

From source file:io.appium.java_client.pagefactory.bys.builder.ByChained.java

License:Apache License

@Override
public WebElement findElement(SearchContext context) {
    AppiumFunction<SearchContext, WebElement> searchingFunction = null;

    for (By by : bys) {
        searchingFunction = Optional
                .ofNullable(/*from w  w w . ja  va  2 s  .co m*/
                        searchingFunction != null ? searchingFunction.andThen(getSearchingFunction(by)) : null)
                .orElse(getSearchingFunction(by));
    }

    FluentWait<SearchContext> waiting = new FluentWait<>(context);

    try {
        checkNotNull(searchingFunction);
        return waiting.until(searchingFunction);
    } catch (TimeoutException e) {
        throw new NoSuchElementException("Cannot locate an element using " + toString());
    }
}

From source file:io.devcon5.pageobjects.WebElementLocator.java

License:Apache License

/**
 * Waits for the presence of a specific web element until a timeout is reached. The method will succeed in any case.
 * If the element is not present, the method waits until the timeout, otherwise it returns as soon as the element is
 * present//  w w  w  .ja  v  a 2  s . c o  m
 *
 * @param context
 *         the search context in which the element should be located
 * @param by
 *         the locate for the element
 * @param waitSec
 *         the timeout in seconds
 *
 * @return the located element
 */
public static WebElement waitForElement(final SearchContext context, final By by, final int waitSec) {

    new FluentWait<>(context).ignoring(NoSuchElementException.class).withTimeout(waitSec, TimeUnit.SECONDS)
            .until((Predicate<SearchContext>) d -> context.findElement(by).isDisplayed());
    return context.findElement(by);

}

From source file:io.github.seleniumquery.internal.fluentfunctions.waituntil.FluentWaitUntil.java

License:Apache License

@Override
public <EVALUATORARG, GETTERTYPE> SeleniumQueryObject apply(Evaluator<EVALUATORARG, GETTERTYPE> evaluator,
        EVALUATORARG value, SeleniumQueryObject seleniumQueryObject,
        FluentBehaviorModifier fluentBehaviorModifier) {

    // this is an array so we can modify from the lambda, but, ideally, it would be a regular variable
    @SuppressWarnings("unchecked")
    EvaluationReport<GETTERTYPE>[] lastEvaluationReport = new EvaluationReport[1];

    Function<Object, Object> waitFunction = unused -> {
        // refresh sqo
        seleniumQueryObject.refresh();/*  w  ww.  ja  v  a 2 s .c o m*/
        // check if it now passes the required evaluation
        lastEvaluationReport[0] = evaluator.evaluate(seleniumQueryObject, value);

        if (fluentBehaviorModifier.isExpectedBehavior(lastEvaluationReport[0])) {
            return NO_MORE_WAITING;
        } else {
            return CONTINUE_WAITING;
        }
    };

    try {
        new FluentWait<>(ANY_NON_NULL_VALUE).withTimeout(waitUntilTimeout, TimeUnit.MILLISECONDS)
                .pollingEvery(waitUntilPollingInterval, TimeUnit.MILLISECONDS)
                .ignoring(StaleElementReferenceException.class).ignoring(NoSuchElementException.class)
                .until(waitFunction);
    } catch (TimeoutException sourceException) {
        throw InternalExceptionFactory.newTimeoutException(sourceException, seleniumQueryObject, value,
                fluentBehaviorModifier, evaluator, lastEvaluationReport[0].getLastValue());
    }

    return seleniumQueryObject;
}

From source file:io.github.seleniumquery.wait.SeleniumQueryFluentWait.java

License:Apache License

/**
 * @since 0.9.0/*  ww w. j  a va  2 s  .  c  om*/
 */
private <T> T fluentWait(SeleniumQueryObject seleniumQueryObject, Function<By, T> function, String reason) {
    try {
        return new FluentWait<>(seleniumQueryObject.getBy())
                .withTimeout(waitUntilTimeout, TimeUnit.MILLISECONDS)
                .pollingEvery(waitUntilPollingInterval, TimeUnit.MILLISECONDS)
                .ignoring(StaleElementReferenceException.class).ignoring(NoSuchElementException.class)
                .until(function);
    } catch (TimeoutException sourceException) {
        throw new SeleniumQueryTimeoutException(sourceException, seleniumQueryObject, reason);
    }
}

From source file:io.tourniquet.pageobjects.ActiveWaits.java

License:Apache License

/**
 * Creates a fluent wait instance that waits for the presence of an element in the search context. The timeout for
 * the wait uses a milli-second precision with a polling interval of 1/10 of the timeout.
 * @param context/*from  w  ww  .  j  a  va2s . c  om*/
 *  the search context to find the element to wait for
 * @param timeout
 *  the timeout to wait before timing out
 * @return
 *  a fluent wait instance
 */
private static FluentWait<SearchContext> fluentWaitForElement(final SearchContext context,
        final Duration timeout) {

    return new FluentWait<>(context).ignoring(NoSuchElementException.class)
            .pollingEvery(timeout.toMillis() / 10, TimeUnit.MILLISECONDS)
            .withTimeout(timeout.toMillis(), TimeUnit.MILLISECONDS);
}

From source file:org.alfresco.demoamp.po.DemoPage.java

License:Open Source License

/**
 * Mechanism to keep looking for an element on the page.
 * @param by selector/* ww  w  .  ja v a  2s.c  om*/
 * @param limit max time to wait in ms
 * @param interval time to wait between calls in ms
 * @return
 */
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);
    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);
}

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 {/*from   w  ww  .ja v  a2 s  .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

/**
 * Verify if loading of the page is complete using java script to validate state of the HTML DOM.
 * /*ww  w.  j  av a2s  .com*/
 * @param waitTime max time to look for an element
 * @return true if page has been loaded
 */
public boolean isRenderComplete(final long waitTime) {
    FluentWait<String> fluentWait = new FluentWait<String>("complete");
    fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS);
    fluentWait.withTimeout(waitTime, TimeUnit.MILLISECONDS);
    try {
        fluentWait.until(new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                String response = (String) executeJavaScript("return document.readyState;");
                return response.equals(input);
            }
        });
        return true;
    } catch (TimeoutException te) {
    }
    return false;
}

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.
 * //  ww w  . j av a 2  s .co  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);
    }

}