Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

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

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until Expected Condition./* w  ww .j  a  v  a2s . c  o  m*/
 *
 * @param condition      - Expected Condition
 * @param timeoutSec     - the maximum time to wait in seconds
 * @param checkCondition log assert for expected conditions.
 */
public static void waitForExpectedCondition(final ExpectedCondition<Boolean> condition, final int timeoutSec,
        final boolean checkCondition) {
    boolean isTrue;
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForExpectedCondition: %s", condition));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        wait.until(condition);
        isTrue = false;
    } catch (TimeoutException e) {
        ReporterNGExt.logTechnical(String.format("waitForExpectedCondition: [ %s ] during: [ %d ] sec ",
                condition, System.currentTimeMillis() / 1000 - start));
        isTrue = true;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertFalse(ReporterNGExt.BUSINESS_LEVEL, isTrue,
                String.format("waitForExpectedCondition - '%s'", condition),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until JavaScript Condition./*from ww w.ja  v  a 2 s  .co  m*/
 *
 * @param javaScript     - JavaScript Condition e.g. return (xmlhttp.readyState==4) or (xmlhttp.status==200)
 * @param timeoutSec     - the maximum time to wait in seconds
 * @param checkCondition log assert for expected conditions.
 */
public static void waitForJavaScriptCondition(final String javaScript, final int timeoutSec,
        final boolean checkCondition) {
    boolean isTrue;
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForJavaScriptCondition: %s", javaScript));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = new WebDriverWait(getDriver(), timeoutSec);
    try {
        wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
                return (Boolean) ((JavascriptExecutor) getDriver()).executeScript(javaScript);
            }
        });
        isTrue = false;
    } catch (TimeoutException e) {
        ReporterNGExt.logTechnical(String.format("waitForJavaScriptCondition: [ %s ] during: [ %d ] sec ",
                javaScript, System.currentTimeMillis() / 1000 - start));
        isTrue = true;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertFalse(ReporterNGExt.BUSINESS_LEVEL, isTrue,
                String.format("waitForJavaScriptCondition - '%s'", javaScript),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until Ajax JQuery Process finished.
 *
 * @param timeoutSec     - the maximum time to wait in seconds
 * @param checkCondition log assert for expected conditions.
 *//*ww w  .j a v  a2 s. c o m*/
public static void waitForAjaxJQueryProcess(final int timeoutSec, final boolean checkCondition) {
    boolean isTrue;
    ReporterNGExt.logAction(getDriver(), "", "waitForAjaxJQueryProcess: return jQuery.active == 0");
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = new WebDriverWait(getDriver(), timeoutSec);
    try {
        wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
                return (Boolean) ((JavascriptExecutor) getDriver()).executeScript("return jQuery.active == 0");
            }
        });
        isTrue = false;
    } catch (TimeoutException e) {
        ReporterNGExt.logTechnical(
                String.format("waitForAjaxJQueryProcess: [ return jQuery.active == 0 ] during: [ %d ] sec ",
                        System.currentTimeMillis() / 1000 - start));
        isTrue = true;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertFalse(ReporterNGExt.BUSINESS_LEVEL, isTrue,
                "waitForAjaxJQueryProcess - 'return jQuery.active == 0'",
                TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.github.psorobka.appium.pages.AbstractPage.java

License:Apache License

public void waitUntilElementIsPresent(String elementId) {
    (new WebDriverWait(driver, 10)).until(presenceOfElementLocated(By.id(elementId)));
}

From source file:com.github.psorobka.appium.pages.AbstractPage.java

License:Apache License

public void waitUntilElementIsPresent(String elementId, int timeOutInSeconds) {
    (new WebDriverWait(driver, timeOutInSeconds)).until(presenceOfElementLocated(By.id(elementId)));
}

From source file:com.github.psorobka.appium.pages.AbstractPage.java

License:Apache License

public void waitUntilElementIsNotPresent(String elementId, int timeOutInSeconds) {
    (new WebDriverWait(driver, timeOutInSeconds)).until(not(presenceOfElementLocated(By.id(elementId))));
}

From source file:com.github.seleniumpm.pagemodel.WebPage.java

License:Apache License

public WebPage waitForTitle(String title) {
    WebDriver driver = sel.getDriver();//  w  w w  . j  a v a2  s  . co m
    final String ftitle = title.toLowerCase();
    (new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(elementWaitTime)))
            .until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver d) {
                    return d.getTitle().toLowerCase().startsWith(ftitle);
                }
            });
    return this;
}

From source file:com.github.seleniumpm.SeleniumWebdriver.java

License:Apache License

public Selenium waitForPresent(Object by, long waitTime) {
    WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(waitTime));
    wait.until(ExpectedConditions.presenceOfElementLocated((By) by));
    return this;
}

From source file:com.github.seleniumpm.SeleniumWebdriver.java

License:Apache License

public Selenium waitForVisible(Object by, long waitTime) {
    WebDriverWait wait = new WebDriverWait(driver, waitTime);
    wait.until(ExpectedConditions.visibilityOfElementLocated((By) by));
    return this;
}

From source file:com.github.seleniumpm.webelements.Element.java

License:Apache License

public Element waitForPresent(long waitTime) {
    WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(waitTime));
    wait.until(ExpectedConditions.presenceOfElementLocated(locator));
    return this;
}