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.control.Elements.java

License:Open Source License

/**
 * Wait until first element is visible.//from w  ww  .  j  av  a2  s .  c om
 *
 * @param timeoutSec     seconds to wait until element become visible
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForFirstVisibleElement(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForFirstVisibleElement: %s", locator));
    boolean isVisible;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.visibilityOfElementLocated(bylocator));
        isVisible = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForFirstVisibleElement: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isVisible = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isVisible,
                format("waitForFirstVisibleElement - first element of '%s' should be visible", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until all elements exist./* ww  w. j a va 2  s .c o  m*/
 *
 * @param timeoutSec     seconds to wait until all elements exist
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForAllElementsExist(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForAllElementsExist: %s", locator));
    boolean exist;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(bylocator));
        exist = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForAllElementsExist: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        exist = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, exist,
                format("waitForAllElementsExist - all elements of '%s' should exist", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until all elements is invisible//from  w  w w. j a  v  a  2 s . co  m
 *
 * @param timeoutSec     seconds to wait until all elements become Not Visible
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForAllElementsNotVisible(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForAllElementsNotVisible: %s", locator));
    boolean isNotVisible;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElements(getWebElements())));
        isNotVisible = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForAllElementsNotVisible: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isNotVisible = false;
    } catch (NoSuchElementException elementException) {
        isNotVisible = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotVisible,
                format("waitForAllElementsNotVisible - all element of '%s' should be not visible", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until all elements is visible//from  w ww.j  a  v  a  2s. c o m
 *
 * @param timeoutSec     seconds to wait until all elements become Visible
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForAllElementsVisible(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForAllElementsVisible: %s", locator));
    boolean isVisible;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.visibilityOfAllElements(getWebElements()));
        isVisible = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForAllElementsVisible: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isVisible = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isVisible,
                format("waitForAllElementsVisible - all elements of '%s' should be visible", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until elements is changed list of text
 *
 * @param list           expected list of text
 * @param timeoutSec     seconds to wait until elements is changed list of text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance//from w  ww .j a  v  a  2  s.com
 */
public ParentPanel waitForElementsTextChanged(final List<String> list, final int timeoutSec,
        final boolean checkCondition) {
    boolean isChanged;
    logAction(this, getParentClassName(), format("waitForElementsTextChanged: %s", locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isChanged = wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                return !getTextList().containsAll(list);
            }
        });
    } catch (TimeoutException e) {
        logTechnical(format("waitForElementsTextChanged: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isChanged = false;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isChanged,
                format("waitForElementsTextChanged - '%s' should be changed", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until number of elements is changed
 *
 * @param count          - source number of element
 * @param timeoutSec     seconds to wait until elements count is changed
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance/* w w  w. j av a2 s  .c o  m*/
 */
public ParentPanel waitForNumberOfElementsChanged(final int count, final int timeoutSec,
        final boolean checkCondition) {
    boolean isChanged;
    logAction(this, getParentClassName(), format("waitNumberOfElementsChanged[%d]: %s", count, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        getWebElementsCount();
        isChanged = wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                return getDriver().findElements(bylocator).size() != count;
            }
        });
    } catch (TimeoutException e) {
        logTechnical(format("waitNumberOfElementsChanged: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isChanged = false;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isChanged,
                format("waitNumberOfElementsChanged - '%s' elements count '%d' should be changed", name, count),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

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

License:Open Source License

/**
 * Get alert.//from   w  w  w  . j  a  va  2s  . com
 *
 * @param timeoutSec to wait until alert is exists.
 * @return Alert
 */
public static Alert getAlert(int timeoutSec) {
    WebDriverWait wait = new WebDriverWait(WebDriverWrapper.getDriver(), timeoutSec);
    wait.until(ExpectedConditions.alertIsPresent());
    return WebDriverWrapper.getDriver().switchTo().alert();
}

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

License:Open Source License

/**
 * Find alert from web page./*  w  w  w  . j  a v  a 2  s . c om*/
 *
 * @param timeoutSec to wait until alert is exists.
 * @return true if alert is presents at web page, otherwise false
 */
public static boolean findAlert(int timeoutSec) {
    WebDriverWait wait = new WebDriverWait(WebDriverWrapper.getDriver(), timeoutSec);
    try {
        wait.until(ExpectedConditions.alertIsPresent());
        return true;
    } catch (TimeoutException e) {
        return false;
    }
}

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

License:Open Source License

/**
 * Close active and switch to the next window.
 *///from w w w.ja  v a 2 s .  co m
public static void switchCloseWindow() {
    ReporterNGExt.logTechnical("Switch And Close Window");
    new WebDriverWait(getDriver(), TIMEOUT) {
    }.until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver wDriver) {
            return (wDriver.getWindowHandles().size() > 1);
        }
    });
    Set<String> handles = getDriver().getWindowHandles();
    if (handles.size() == 1) {
        ReporterNGExt.logTechnical("switchCloseWindow: only one windows is available");
        return;
    }
    getDriver().close();
    Sleeper.sleepTight(500);
    handles = getDriver().getWindowHandles();
    getDriver().switchTo().window(handles.iterator().next());
}

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

License:Open Source License

public static boolean waitWindowsCount(final int numberOfWindows) {
    ReporterNGExt.logTechnical("Wait for Open Windows Count");
    new WebDriverWait(getDriver(), TIMEOUT) {
    }.until(new ExpectedCondition<Boolean>() {
        @Override//from ww  w.j  a  va  2s .  c o  m
        public Boolean apply(WebDriver wDriver) {
            return (wDriver.getWindowHandles().size() == numberOfWindows);
        }
    });
    return false;
}