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:org.eclipse.che.selenium.pageobject.TestWebElementRenderChecker.java

License:Open Source License

private FluentWait<WebDriver> getFluentWait(int seconds) {
    return new FluentWait<WebDriver>(seleniumWebDriver).withTimeout(seconds, TimeUnit.SECONDS)
            .pollingEvery(200, TimeUnit.MILLISECONDS).ignoring(StaleElementReferenceException.class);
}

From source file:org.jboss.pressgang.ccms.util.WebElementUtil.java

License:Open Source License

public static FluentWait<WebDriver> waitForSeconds(WebDriver webDriver, int durationInSec) {
    return new FluentWait<WebDriver>(webDriver).withTimeout(durationInSec, SECONDS).pollingEvery(1, SECONDS)
            .ignoring(NoSuchElementException.class, StaleElementReferenceException.class);
}

From source file:org.keycloak.quickstart.uma.page.PhotozPage.java

License:Apache License

public void waitForPageToLoad() {

    if (webDriver instanceof HtmlUnitDriver) {
        return; // not needed
    }//from w  w  w  . j ava 2 s . c  om

    // Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
    for (int maxRedirects = 2; maxRedirects > 0; maxRedirects--) {
        String currentUrl = webDriver.getCurrentUrl();
        FluentWait<WebDriver> wait = new FluentWait<>(webDriver)
                .withTimeout(Duration.of(250, ChronoUnit.MILLIS));
        try {
            wait.until(not(urlToBe(currentUrl)));
        } catch (TimeoutException e) {
            break; // URL has not changed recently - ok, the URL is stable and page is current
        }
        if (maxRedirects == 1) {
            log.warn("URL seems unstable! (Some redirect are probably still in progress)");
        }
    }

    WebDriverWait wait = new WebDriverWait(webDriver, PAGELOAD_TIMEOUT_MILLIS / 1000);

    try {
        // Checks if the document is ready and asks AngularJS, if present, whether there are any REST API requests
        // in progress
        wait.until(javaScriptThrowsNoExceptions("if (document.readyState !== 'complete' "
                + "|| (typeof angular !== 'undefined' && angular.element(document.body).injector().get('$http').pendingRequests.length !== 0)) {"
                + "throw \"Not ready\";" + "}"));
    } catch (TimeoutException e) {
        // Sometimes, for no obvious reason, the browser/JS doesn't set document.readyState to 'complete' correctly
        // but that's no reason to let the test fail; after the timeout the page is surely fully loaded
        log.warn("waitForPageToLoad time exceeded!");
    }
}

From source file:org.keycloak.testsuite.util.WaitUtils.java

License:Apache License

/**
 * Waits for page to finish any pending redirects, REST API requests etc.
 * Because Keycloak's Admin Console is a single-page application, we need to
 * take extra steps to ensure the page is fully loaded
 *///www  .ja va  2 s  . c o m
public static void waitForPageToLoad() {
    WebDriver driver = getCurrentDriver();

    if (driver instanceof HtmlUnitDriver) {
        return; // not needed
    }

    String currentUrl = null;

    // Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
    for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
        currentUrl = driver.getCurrentUrl();
        FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofMillis(250));
        try {
            wait.until(not(urlToBe(currentUrl)));
        } catch (TimeoutException e) {
            break; // URL has not changed recently - ok, the URL is stable and page is current
        }
        if (maxRedirects == 1) {
            log.warn("URL seems unstable! (Some redirect are probably still in progress)");
        }
    }

    WebDriverWait wait = new WebDriverWait(getCurrentDriver(), PAGELOAD_TIMEOUT_MILLIS / 1000);
    ExpectedCondition waitCondition = null;

    // Different wait strategies for Admin and Account Consoles
    if (currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/admin\\/.*$")) { // Admin Console
        // Checks if the document is ready and asks AngularJS, if present, whether there are any REST API requests in progress
        waitCondition = javaScriptThrowsNoExceptions("if (document.readyState !== 'complete' "
                + "|| (typeof angular !== 'undefined' && angular.element(document.body).injector().get('$http').pendingRequests.length !== 0)) {"
                + "throw \"Not ready\";" + "}");
    } else if (currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/realms\\/[^\\/]+\\/account\\/.*$") // check for Account Console URL
            && driver.getPageSource().contains("patternfly-ng") // check for new Account Console (don't use this strategy with the old one)
    ) {
        waitCondition = javaScriptThrowsNoExceptions(
                "if (!window.getAngularTestability(document.querySelector('app-root')).isStable()) {"
                        + "throw 'Not ready';" + "}");
    }

    if (waitCondition != null) {
        try {
            wait.until(waitCondition);
        } catch (TimeoutException e) {
            log.warn("waitForPageToLoad time exceeded!");
        }
    }
}

From source file:org.kie.page.objects.LoginPage.java

License:Apache License

public LoginPage(WebDriver driver) {
    this.driver = driver;

    driver.navigate().to(KIESeleniumTest.KIE_URL);

    wait = new FluentWait(driver).withTimeout(30, TimeUnit.SECONDS).pollingEvery(2, TimeUnit.SECONDS);
}

From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java

License:Apache License

private void checkSafeEditRestoreProvided() {
    // We must find the status message asking if we want to restore
    // previous unchanged data, and make sure it is visible
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);
    wait.until(new Function<WebDriver, WebElement>() {
        @Override/*from ww w .  j ava2  s.c  o  m*/
        public WebElement apply(WebDriver driver) {
            List<WebElement> elts = driver
                    .findElements(By.xpath("//div[contains(.,'A draft of this document has been saved')]"));
            if (!elts.isEmpty()) {
                return elts.get(0);
            }
            return null;
        }
    });
}

From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java

License:Apache License

private void waitForSavedNotification() {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);
    try {/*from ww w  . j  a v a2 s.c  om*/
        wait.until(new Function<WebDriver, WebElement>() {
            @Override
            public WebElement apply(WebDriver driver) {
                return driver
                        .findElement(By.xpath("//div[contains(.,'" + DRAFT_SAVE_TEXT_NOTIFICATION + "')]"));
            }
        });
    } catch (TimeoutException e) {
        log.warn("Could not see saved message, maybe I was too slow and it "
                + "has already disappeared. Let's see if I can restore.");
    }
}

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

License:Open Source License

public static List<WebElement> findElementsWithTimeout(final By by) throws NoSuchElementException {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    return wait.until(new Function<WebDriver, List<WebElement>>() {
        public List<WebElement> apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            return elements.isEmpty() ? null : elements;
        }/*from   ww w.  ja  va2s  .c o  m*/
    });
}

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

License:Open Source License

/**
 * Fluent wait for an element to be present, checking every 5 seconds
 *
 * @since 5.7.2/*from w w  w . j  a v  a  2  s .com*/
 */
public static WebElement waitUntilElementPresent(final By locator) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    WebElement elt = wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    });
    return elt;
}

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

License:Open Source License

/**
 * Fluent wait for an element not to be present, checking every 5 seconds.
 *
 * @since 5.7.2/*www. ja va2 s.com*/
 */
public static void waitUntilElementNotPresent(final By locator) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS);
    wait.until((new Function<WebDriver, By>() {
        public By apply(WebDriver driver) {
            try {
                driver.findElement(locator);
            } catch (NoSuchElementException ex) {
                // ok
                return locator;
            }
            return null;
        }
    }));
}