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.ecofactor.qa.automation.newapp.page.impl.SettingsPageImpl.java

License:Open Source License

/**
 * Gets the URL from phone browser.//from  w  w w .j a  v a 2s .c  om
 * @param element the element
 * @return the URL from phone browser
 */
private String getURLFromPhoneBrowser(final String element) {

    setLogString("Get URL from phone browser", true, CustomLogLevel.LOW);
    final boolean elementDisplayed = isDisplayed(getDriver(), By.cssSelector(element), TINY_TIMEOUT);
    String currentURL = "";
    WebDriverWait wait = new WebDriverWait(getDriver(), 10);
    final WebElement faqElement = getElement(getDriver(), By.cssSelector(element), TINY_TIMEOUT);
    if (elementDisplayed == true) {
        final String previousUrl = getDriver().getCurrentUrl();
        faqElement.click();
        getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        ExpectedCondition<Boolean> e = new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {

                return (d.getCurrentUrl() != previousUrl);
            }
        };
        wait.until(e);
        currentURL = getDriver().getCurrentUrl();

    }
    return currentURL;
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.ThermostatPageUIImpl.java

License:Open Source License

/**
 * @param expectedTemp/*from w w  w . ja v  a 2s  .  c  o m*/
 * @return
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPageUI#isTargetTemperatureChanged(java.lang.String)
 */
public boolean isTargetTemperatureChanged(final String expectedTemp) {

    setLogString("Check target temperature is changed to : " + expectedTemp, true, CustomLogLevel.HIGH);
    final boolean targetReflected = new WebDriverWait(getDriver(), CustomTimeout.VERY_LONG_TIMEOUT.getValue())
            .until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(final WebDriver driver) {

                    final WebElement targetElement = getElementBySubElement(getDriver(),
                            getCurrentThermostatContainer(), By.cssSelector(SETPOINT), TINY_TIMEOUT);
                    if (targetElement.getText().equalsIgnoreCase(expectedTemp)) {
                        return true;
                    }
                    return false;
                }
            });
    return targetReflected;
}

From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java

License:Open Source License

/**
 * Accept alert./*from  w w w .  ja  va2s . co  m*/
 * @see com.ecofactor.qa.automation.mobile.action.UIAction#acceptAlert()
 */
@Override
public void acceptAlert() {

    try {
        final WebDriverWait wait = new WebDriverWait(driverOps.getDeviceDriver(), SHORT_TIMEOUT);
        if (wait.until(ExpectedConditions.alertIsPresent()) != null) {
            driverOps.getDeviceDriver().switchTo().alert().accept();
        }
    } catch (final Exception e) {
        LOGGER.error("Error in acceptAlert(). Cause ::: " + e);
    }
}

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

License:Open Source License

/**
 * Checks if the given element is displayed.
 * @param driver the driver//from  w  w  w  .j  av a2  s. c  o m
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is displayed
 */
public static boolean isDisplayed(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    boolean displayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    } catch (TimeoutException te) {
        displayed = false;
    }
    return displayed;
}

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

License:Open Source License

/**
 * Checks if the given element is clickable.
 * @param driver the driver//w w w . j a  va  2s .c  o  m
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is clickable
 */
public static boolean isClickable(final WebDriver driver, final WebElement element,
        final CustomTimeout timeout) {

    boolean displayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.elementToBeClickable(element));
    } catch (TimeoutException te) {
        displayed = false;
    }
    return displayed;
}

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

License:Open Source License

/**
 * Checks if the given element is not displayed.
 * @param driver the driver//from   w ww . j  av  a 2s .com
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is not displayed
 */
public static boolean isNotDisplayed(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    boolean notDisplayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(locator)));
    } catch (final WebDriverException te) {
        notDisplayed = false;
    }
    return notDisplayed;
}

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

License:Open Source License

/**
 * Checks if the sub element displayed./*from  ww  w . j  av  a2s . co m*/
 * @param driver the driver
 * @param subElement the sub element
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is displayed
 */
public static boolean isDisplayedBySubElement(final WebDriver driver, final WebElement subElement,
        final By locator, final CustomTimeout timeout) {

    boolean displayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.visibilityOf(subElement.findElement(locator)));
    } catch (Exception te) {
        displayed = false;
    }
    return displayed;
}

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

License:Open Source License

/**
 * Checks if is displayed by list.//from w  w  w .j a va  2  s.c  o m
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is displayed by list
 */
public static boolean isDisplayedByList(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    boolean isLoaded = false;
    try {
        isLoaded = new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(final WebDriver driver) {

                final List<WebElement> elements = driver.findElements(locator);
                boolean displayed = false;
                for (final WebElement element : elements) {
                    displayed = element.isDisplayed();
                    if (displayed) {
                        break;
                    }
                }
                return displayed;
            }
        });
    } catch (TimeoutException te) {
        isLoaded = false;
    }
    return isLoaded;
}

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

License:Open Source License

/**
 * Gets the element.//www . j  av  a  2 s.  com
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return the element
 */
public static WebElement getElement(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<WebElement>() {
            public WebElement apply(final WebDriver driver) {

                return driver.findElement(locator);
            }
        });
    } catch (TimeoutException timeOutException) {
        return null;
    }
}

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

License:Open Source License

/**
 * Get the list of elements./*from  www.  ja  v a2  s. c  o m*/
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return the elements
 */
public static List<WebElement> getElements(final WebDriver driver, final By locator,
        final CustomTimeout timeout) {

    return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<List<WebElement>>() {
        public List<WebElement> apply(final WebDriver driver) {

            return driver.findElements(locator);
        }
    });
}