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

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

Introduction

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

Prototype

<T> T until(Function<? super F, T> isTrue);

Source Link

Document

Implementations should wait until the condition evaluates to a value that is neither null nor false.

Usage

From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java

License:Open Source License

/**
 * Wait for page loaded.//from ww  w .j  a v a2  s.c o  m
 * @param driver the driver
 */
public static void waitForPageLoaded(final WebDriver driver) {

    final ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(final WebDriver driver) {

            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };
    final Wait<WebDriver> wait = new WebDriverWait(driver, 120);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        LogUtil.setLogString("Page load takes more time", true);
    }
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Wait for page loaded./* w ww  .  j a  v  a2  s .  c  o  m*/
 * @param driver the driver
 */
public static void waitForPageLoaded(WebDriver driver) {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {

            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };

    Wait<WebDriver> wait = new WebDriverWait(driver, 120);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        DriverConfig.setLogString("Page load takes more time", true);
    }
}

From source file:com.elastica.webelements.HtmlElement.java

License:Apache License

/**
 * Wait element to present using Explicit Waits with timeout in seconds. This method is used for special element
 * which needs long time to present./*from  w  w  w.  j a va2 s  . c om*/
 */
public void waitForPresent(final int timeout) {
    TestLogging.logWebStep(null, "wait for " + this.toString() + " to present.", false);

    Wait<WebDriver> wait = new WebDriverWait(driver, timeout);
    wait.until(new ExpectedCondition<WebElement>() {
        public WebElement apply(final WebDriver driver) {
            return driver.findElement(by);
        }
    });
}

From source file:com.gargoylesoftware.htmlunit.HttpWebConnection3Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*w ww .ja  v  a2  s .co  m*/
 */
@Test
@Alerts(CHROME = { "Host", "Connection", "Accept", "User-Agent", "Referer", "Accept-Encoding",
        "Accept-Language", "Cookie" }, FF = { "Host", "User-Agent", "Accept", "Accept-Language",
                "Accept-Encoding", "Referer", "Cookie", "Connection" }, IE = { "Accept", "Referer",
                        "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection",
                        "Cookie" })
@NotYetImplemented(IE)
public void headers_cookie_referer() throws Exception {
    final String htmlResponse = "<a href='2.html'>Click me</a>";
    final String response = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + htmlResponse.length() + "\r\n"
            + "Content-Type: text/html\r\n" + "Set-Cookie: name=value\r\n" + "\r\n" + htmlResponse;

    primitiveWebServer_ = new PrimitiveWebServer(PORT, response.getBytes());
    primitiveWebServer_.start();
    final WebDriver driver = getWebDriver();

    driver.get("http://localhost:" + PORT + "");
    driver.findElement(By.linkText("Click me")).click();

    final Wait<WebDriver> wait = new WebDriverWait(driver, 5);
    wait.until(currentUrlContains("2.html"));

    int index = 1;
    String request;
    do {
        request = primitiveWebServer_.getRequests().get(index++);
    } while (request.contains("/favicon.ico"));

    final String[] headers = request.split("\\r\\n");
    final String[] result = new String[headers.length - 1];
    for (int i = 0; i < result.length; i++) {
        final String header = headers[i + 1];
        result[i] = header.substring(0, header.indexOf(':'));
    }
    assertEquals(Arrays.asList(getExpectedAlerts()).toString(), Arrays.asList(result).toString());
}

From source file:com.github.licanhua.test.framework.util.PageHelper.java

License:Apache License

private static <T> void waitForElement(String message, ElementContext context, final T element,
        final Predicate<T> predicate) {
    WebDriver webDriver = context.getWebDriver();
    int waitDuration = context.getWaitDurationInSeconds();

    try {/*from  w w  w  . j a  va  2  s  . c o m*/
        Wait<WebDriver> wait = new WebDriverWait(webDriver, waitDuration, 100);
        wait.until(new ExpectedCondition<Boolean>() {
            public Boolean apply(final WebDriver webDriver) {
                try {
                    return predicate.apply(element);
                } catch (final NoSuchElementException e) {
                    return false;
                } catch (final StaleElementReferenceException e) {
                    return false;
                }
            }
        });
    } catch (TimeoutException e) {
        TimeoutException te = new TimeoutException(message + " timeout!", e);
        throw te;
    }
}

From source file:com.github.licanhua.test.framework.util.PageHelper.java

License:Apache License

public static void waitForDocumentReadyState(WebDriverContext webDriverContext) {
    logger.info("Wait for document.readyState is complete");
    Wait<WebDriver> wait = new WebDriverWait(webDriverContext.getWebDriver(),
            webDriverContext.getWaitDurationInSeconds(), 100);
    wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            try {
                return ((JavascriptExecutor) driver).executeScript("return document.readyState")
                        .equals("complete");
            } catch (TimeoutException e) {
                throw new TimeoutException("Load document timeout\n" + e.getMessage());
            }//from w  ww. jav a 2s.c om
        }
    });

}

From source file:com.htmlhifive.pitalium.sample.PtlSampleTest.java

License:Apache License

@Test
public void testCaptureTop() throws Exception {
    driver.get("");

    ScreenshotArgument arg = ScreenshotArgument.builder("sampleCapture")
            // //from   w w  w .  j  av  a2  s . com
            .addNewTarget().addExclude(SelectorType.CLASS_NAME, "fb-like-box")
            .addNewTarget(SelectorType.ID, "about").build();

    driver.executeScript("document.getElementById('about').style.marginTop='20px';");

    // ??hifive??facebook?
    Wait<WebDriver> wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions
            .presenceOfElementLocated(By.cssSelector("iframe[title=\"fb:like_box Facebook Social Plugin\"]")));

    // ??
    assertionView.assertView(arg);
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitPresent -//  www . j  av a  2s .co  m
 * @param locator
 * @see fluentWaitPresent(final WebElement element)
 * @return
 */
public boolean fluentWaitPresent(final String locator) {

    logger.info("INFO: Fluentwait for element: " + locator);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            return isPresent(locator);
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitWebElementNotPresent -/*w w  w  . j a  va2 s  .co m*/
 * @param locator
 * @return
 */
public boolean fluentWaitNotPresent(final String locator) {

    logger.info("INFO: Fluentwait for element to not be present: " + locator);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            return !isPresent(locator);
        }
    });
    return found;
}

From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java

License:Open Source License

/**
 * fluentWaitTextPresent -/*ww w  .  j  a va 2s.c o  m*/
 * @param text
 * @return
 */
public boolean fluentWaitTextPresent(final String text) {

    logger.info("INFO: FluentWait for text: " + text);
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    boolean found = wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            return isTextPresent(text);
        }
    });
    return found;
}