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

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

Introduction

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

Prototype

@Override
public <V> V until(Function<? super T, V> isTrue) 

Source Link

Document

Repeatedly applies this instance's input value to the given function until one of the following occurs:
  1. the function returns neither null nor false
  2. the function throws an unignored exception
  3. the timeout expires
  4. the current thread is interrupted

Usage

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Fluent wait for an element to be present, checking every 100 ms.
 *
 * @since 5.7.2//from  w  w  w  .j a v  a 2s.  c o  m
 */
public static void waitUntilElementPresent(final By locator) {
    FluentWait<WebDriver> wait = getFluentWait();
    wait.ignoring(NoSuchElementException.class);
    wait.until(new Function<WebDriver, WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    });
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Waits until an element is enabled, with a timeout.
 *
 * @param element the element/*from ww  w .  ja va 2  s .  co  m*/
 * @param timeout the timeout in milliseconds
 */
public static void waitUntilEnabled(final WebElement element, int timeout) throws NotFoundException {
    FluentWait<WebDriver> wait = getFluentWait();
    wait.withTimeout(timeout, TimeUnit.MILLISECONDS);
    Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            return element.isEnabled();
        }
    };
    try {
        wait.until(function);
    } catch (TimeoutException e) {
        throw new NotFoundException("Element not enabled after timeout: " + element);
    }
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Fluent wait on a the given function, checking every 100 ms.
 *
 * @param function/*from  w  w  w .  j a  va 2  s  . c o  m*/
 * @param ignoredExceptions the types of exceptions to ignore.
 * @since 5.9.2
 */
@SafeVarargs
public static <K extends java.lang.Throwable> void waitUntilGivenFunctionIgnoreAll(
        Function<WebDriver, Boolean> function, java.lang.Class<? extends K>... ignoredExceptions) {
    FluentWait<WebDriver> wait = getFluentWait();
    if (ignoredExceptions != null) {
        if (ignoredExceptions.length == 1) {
            wait.ignoring(ignoredExceptions[0]);
        } else {
            wait.ignoreAll(Arrays.asList(ignoredExceptions));
        }

    }
    wait.until(function);
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Fluent wait on a the given function, checking every 100 ms.
 *
 * @param function/*w  w  w .  j  a v a 2s .  com*/
 * @param ignoredException the type of exception to ignore.
 * @since 5.9.2
 */
public static <K extends java.lang.Throwable> void waitUntilGivenFunctionIgnoring(
        Function<WebDriver, Boolean> function, java.lang.Class<? extends K> ignoredException) {
    FluentWait<WebDriver> wait = getFluentWait();
    if (ignoredException != null) {
        wait.ignoring(ignoredException);
    }
    wait.until(function);
}

From source file:org.owasp.webgoat.plugins.TestUtils.java

License:Open Source License

public static void assertTitlePresent(WebDriver webDriver, String title) {
    FluentWait<WebDriver> wait = new WebDriverWait(webDriver, 15); // wait for a maximum of 15 seconds
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("lesson-title"), title));
}

From source file:Pages.ATT_HomePage.java

License:Open Source License

/**
 * check whether is at current page - fluent wait check
 *//*from  www . j  a va  2s . c  om*/
public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear

    // new UiObject().waitUntilGone               

    FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    try {
        Object interval = pwait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver d) {
                WebElement rateButton_obj = d.findElement(By.id("android:id/home"));
                System.out.println("home icon found");
                return rateButton_obj;
            }
        });
        return true;
    } catch (TimeoutException t) {
        System.out.println("Did not find the home icon within fluent wait time");
        return false;
    }
}

From source file:Pages.ATT_LikeDislikePage.java

License:Open Source License

public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear
    FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    try {//from   w  w  w.  ja v a 2 s  .  co  m
        Object interval = pwait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver d) {
                WebElement likeButton_obj = d.findElement(By.name("Like"));
                System.out.println("likeButton found");
                return likeButton_obj;
            }
        });
        return true;
    } catch (TimeoutException t) {
        System.out.println("Did not find the Like Button within fluent wait time");
        return false;
    }
}

From source file:Pages.ATT_LikeDislikePage_likesubpage.java

License:Open Source License

/**
 * check whether is at current page/*from   ww  w  . ja  v a2  s  . c  om*/
 */
public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear
    FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    try {
        Object interval = pwait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver d) {
                WebElement rateButton_obj = d.findElement(By.name("Rate"));
                System.out.println("rateButton found");
                return rateButton_obj;
            }
        });
        return true;
    } catch (TimeoutException t) {
        System.out.println("Did not find the rateButton within fluent wait time");
        return false;
    }
}

From source file:Pages.ATT_LikeDislikePage_subpages.ATT_dislikesubpage.java

License:Open Source License

/**
 * check whether is at current page/*from   w  ww. j ava2s  .  c om*/
 */
public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear
    FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    try {
        Object interval = pwait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver d) {
                WebElement rateButton_obj = d.findElement(By.name("No, thanks"));
                System.out.println("nothanksButton found");
                return rateButton_obj;
            }
        });
        return true;
    } catch (TimeoutException t) {
        System.out.println("Did not find the nothanksButton within fluent wait time");
        return false;
    }
}

From source file:pawl.jbehave.step.MailSteps.java

License:Apache License

/**
 * Wait until received message with parameters.
 *
 * @param recipient of email/*from  w  w  w .  j a  v  a2 s  . c  o m*/
 * @param subject   of email
 */
private void waitUntilReceivedMessageWithParameters(final String recipient, final String subject) {
    final FluentWait<String> wait = new FluentWait<>(recipient)
            .withTimeout(Resources.base().explicitWait(), TimeUnit.SECONDS)
            .pollingEvery(Resources.base().pollingInterval(), TimeUnit.MILLISECONDS);
    try {
        wait.until(new Predicate<String>() {
            @Override
            public boolean apply(final String recipient) {
                try {
                    openInboxAs(recipient);
                } catch (AuthenticationFailedException e) {
                    return false;
                }
                return findMessageWithParams(recipient, subject) != null;
            }
        });
    } catch (TimeoutException e) {
        throw new AssertionError("Could not find message with parameters: " + "recipient - " + recipient
                + ", subject - " + subject + "\nin mailbox with : " + recipientsAndSubjects.toString());
    }
}