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 all windows not empty./*from ww w .java  2 s  .c om*/
 *
 * @param numberOfWindows - number of existing windows
 */
public static void waitAllWindowsFullLoaded(final int numberOfWindows) {
    ReporterNGExt.logTechnical("Wait for All Windows Full Loaded");
    new WebDriverWait(getDriver(), TIMEOUT) {
    }.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver wDriver) {
            return (wDriver.getWindowHandles().size() == numberOfWindows);
        }
    });

    new WebDriverWait(getDriver(), TIMEOUT) {
    }.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver wDriver) {
            boolean fullLoaded = true;
            for (String window : wDriver.getWindowHandles()) {
                if (window.isEmpty()) {
                    fullLoaded = false;
                    break;
                }
            }
            return (fullLoaded);
        }
    });
    Sleeper.sleepTight(1000);
}

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

License:Open Source License

/**
 * Wait until windows has title.//from   w  w w .j  a v  a 2s .  c  om
 *
 * @param timeoutSec     to wait until windows has title.
 * @param title          - Expected window title.
 * @param checkCondition log assert for expected conditions.
 */
public static void waitForTitle(String title, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTitle: %s", title));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.titleIs(title));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTitle: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
    }
    if (checkCondition) {
        ReporterNGExt.logAssertEquals(ReporterNGExt.BUSINESS_LEVEL, getDriver().getTitle(), title,
                "waitForTitle", TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until windows title contains text.
 *
 * @param timeoutSec     to wait until windows title contains text.
 * @param title          - Expected window title contains text.
 * @param checkCondition - log assert for expected conditions.
 *//*  w  ww. j a  va  2s  .c  o  m*/
public static void waitForTitleContains(String title, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTitleContains: %s", title));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.titleContains(title));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTitleContains: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
    }
    if (checkCondition) {
        ReporterNGExt.logAssertContains(ReporterNGExt.BUSINESS_LEVEL, getDriver().getTitle(), title,
                "waitForTitleContains", TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until windows title not contains text.
 *
 * @param timeoutSec     to wait until windows title not contains text.
 * @param title          - Expected window title not contains text.
 * @param checkCondition log assert for expected conditions.
 *//* ww  w .ja  v  a 2  s. c  o m*/
public static void waitForTitleNotContains(String title, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTitleNotContains: %s", title));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.titleContains(title)));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTitleNotContains: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
    }
    if (checkCondition) {
        ReporterNGExt.logAssertNotContains(ReporterNGExt.BUSINESS_LEVEL, getDriver().getTitle(), title,
                "waitForTitleNotContains", TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until element is changed text/* w  w  w  .  j a  v  a 2 s  . c om*/
 *
 * @param title          before change
 * @param timeoutSec     seconds to wait until element is changed text
 * @param checkCondition - log assert for expected conditions.
 */
public static void waitForTitleChanged(final String title, int timeoutSec, boolean checkCondition) {
    boolean isChanged;
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTitleChanged: %s", title));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isChanged = wait.until(ExpectedConditions.not(ExpectedConditions.titleIs(title)));
    } catch (TimeoutException e) {
        ReporterNGExt.logTechnical(String.format("waitForTitleChanged: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
        isChanged = false;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isChanged,
                String.format("waitForTitleChanged: title '%s' should be changed", title),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until any element with text presents at web page.
 *
 * @param text           - element text to be presents.
 * @param timeoutSec     to wait until presents.
 * @param checkCondition log assert for expected conditions.
 *//*from   w  w w .  j a  v  a 2s  . c om*/
public static void waitForTextToBePresent(String text, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTextToBePresent: %s", text));
    boolean isPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        isPresent = wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*"), text));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTextToBePresent: [ %s ] during: [ %d ] sec ", text,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isPresent,
                String.format("waitForTextToBePresent: element with text '%s' should be exists", text),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until any element with text not presents at web page.
 *
 * @param text           - element text to not be presents.
 * @param timeoutSec     to wait until not presents.
 * @param checkCondition log assert for expected conditions.
 *//*from   w  w  w  .j a  va 2s . c  o m*/
public static void waitForTextToNotBePresent(String text, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTextToNotBePresent: %s", text));
    boolean isNotPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        isNotPresent = wait.until(ExpectedConditions
                .not(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*"), text)));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTextToNotBePresent: [ %s ] during: [ %d ] sec ", text,
                System.currentTimeMillis() / 1000 - start));
        isNotPresent = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotPresent,
                String.format("waitForTextToNotBePresent: element with text '%s' should not be exists", text),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until link presents at web page.
 *
 * @param linkText       - linkText to be presents.
 * @param timeoutSec     to wait until presents.
 * @param checkCondition log assert for expected conditions.
 *///from  w w  w.  ja  v a 2  s .c o m
public static void waitForLinkToBePresent(String linkText, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForLinkToBePresent: %s", linkText));
    boolean isPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText(linkText)));
        isPresent = true;
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForLinkToBePresent: [ %s ] during: [ %d ] sec ", linkText,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isPresent,
                String.format("waitForLinkToBePresent: link with text '%s' should be exists", linkText),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until link not presents at web page.
 *
 * @param linkText       - linkText to not be presents.
 * @param timeoutSec     to wait until not presents.
 * @param checkCondition log assert for expected conditions.
 *//*from  w w w .j  a v a 2s  . co  m*/
public static void waitForLinkToNotBePresent(String linkText, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForLinkToNotBePresent: %s", linkText));
    boolean isNotPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        isNotPresent = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.linkText(linkText)));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForLinkToNotBePresent: [ %s ] during: [ %d ] sec ",
                linkText, System.currentTimeMillis() / 1000 - start));
        isNotPresent = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotPresent,
                String.format("waitForLinkToNotBePresent: link with text '%s' should not be exists", linkText),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

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

License:Open Source License

/**
 * Wait until native window is not exists.
 *
 * @param title          of native window
 * @param timeoutSec     to wait until native window is not exists.
 * @param checkCondition log assert for expected conditions.
 *//* ww  w .  j a  v a2s . c  om*/
public static void waitForNativeWindow(final String title, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForNativeWindow: %s", title));
    boolean isPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = new WebDriverWait(getDriver(), timeoutSec);
    try {
        isPresent = wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                UAutoItX UIMethods = new UAutoItX();
                return UIMethods.WinExists(title, "") > 0;
            }
        });
    } catch (TimeoutException e) {
        ReporterNGExt.logTechnical(String.format("waitForNativeWindow: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isPresent,
                String.format("waitForNativeWindow: native window '%s' should be exists", title),
                TestBaseWebDriver.takePassedScreenshot);
    }
}