Example usage for org.openqa.selenium By className

List of usage examples for org.openqa.selenium By className

Introduction

In this page you can find the example usage for org.openqa.selenium By className.

Prototype

public static By className(String className) 

Source Link

Document

Find elements based on the value of the "class" attribute.

Usage

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

License:Open Source License

/**
 * Gets the current thermostat name./*from   ww w  .  j a v  a  2 s. com*/
 * @return the current thermostat name
 */
@Override
public String getCurrentThermostatName() {

    String name = "";
    final WebElement locationName = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.className(LOCATION_NAME), TINY_TIMEOUT);

    final String tstDetails = locationName.getText();
    if (tstDetails.contains("-")) {
        final int tstaNameIndex = tstDetails.lastIndexOf("-");
        name = tstDetails.substring(0, tstaNameIndex);
        setLogString("Current Thermostat Name : " + name, true, CustomLogLevel.HIGH);
    }
    return name;
}

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

License:Open Source License

/**
 * Gets the current temperature.//w  w  w  . j  a v  a 2  s  .  co m
 * @return the current temperature
 * @see com.ecofactor.qa.automation.mobile.page.ThermostatPage#getCurrentTemperature()
 */
@Override
public String getCurrentTemperature() {

    setLogString("Get current temperature", true, CustomLogLevel.HIGH);
    isDisplayedBySubElement(getDriver(), getCurrentThermostatContainer(), By.className(CURRENT_TEMPERATURE),
            TINY_TIMEOUT);
    final WebElement currentTempElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.className(CURRENT_TEMPERATURE), TINY_TIMEOUT);
    Assert.assertNotNull(currentTempElement.getText(), "Current Temperature is not displayed");
    setLogString("Current Temperature: " + currentTempElement.getText(), true, CustomLogLevel.HIGH);
    final String currentTemperature = currentTempElement.getText().toString();
    return currentTemperature;
}

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

License:Open Source License

/**
 * Gets the temperature content by position.
 * @param position the position/*from ww w  .jav  a2  s  .c o  m*/
 * @return the temperature content by position
 * @see com.ecofactor.qa.automation.mobile.page.ThermostatPage#getTemperatureContentByPosition(java.lang.String)
 */
@Override
public String getTemperatureContentByPosition(String position) {

    final WebElement tempDifferenceContainer = getElement(getDriver(), By.className("temperatureDiffContainer"),
            TINY_TIMEOUT);
    final List<WebElement> divElements = getElementsBySubElement(getDriver(), tempDifferenceContainer,
            By.tagName("div"), TINY_TIMEOUT);

    WebElement requiredContainer = null;
    for (final WebElement element : divElements) {
        if (element.getAttribute("class").startsWith(position)) {
            requiredContainer = element;
            break;
        }
    }
    WebElement temperatureInfo = getElementBySubElementText(getDriver(), requiredContainer, By.tagName(TAG_DIV),
            "INSIDE", SHORT_TIMEOUT);
    temperatureInfo = (temperatureInfo != null) ? temperatureInfo
            : getElementBySubElementText(getDriver(), requiredContainer, By.tagName(TAG_DIV), "TARGET",
                    SHORT_TIMEOUT);
    return temperatureInfo.getText();
}

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

License:Open Source License

/**
 * Checks if is click learn more link redirects new window.
 * @return true, if is click learn more link redirects new window
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPage#isClickLearnMoreLinkRedirectsNewWindow()
 *///from   w ww . j a va  2  s  . c  o m
@Override
public boolean isClickLearnMoreLinkRedirectsNewWindow() {

    boolean pageRedirected = false;
    final String parentWindowHandle = getDriver().getWindowHandle();
    final WebElement errorModeInfoLink = getElement(getDriver(), By.className(ERROR_MODE_INFO), SHORT_TIMEOUT);
    setLogString("Click on error mode info.", true, CustomLogLevel.LOW);
    errorModeInfoLink.click();
    getAction().rejectAlert();
    // tinyWait();

    final Set<String> windowids = getDriver().getWindowHandles();
    final Iterator<String> iter = windowids.iterator();
    iter.next();
    setLogString("Check if new pop up window opens.", true, CustomLogLevel.LOW);
    setLogString("Switch to other window and verify the title", true, CustomLogLevel.HIGH);
    final WebDriver popup = getDriver().switchTo().window((String) iter.next());

    setLogString("Check URL is :http://ecofactor.uservoice.com/", true, CustomLogLevel.HIGH);
    setLogString("URL is :" + popup.getCurrentUrl(), true, CustomLogLevel.HIGH);

    pageRedirected = popup.getCurrentUrl().contains(mobileConfig.get(MobileConfig.LEARN_MORE_LINK)) ? true
            : false;
    popup.close();
    getDriver().switchTo().window(parentWindowHandle);
    return pageRedirected;
}

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

License:Open Source License

/**
 * Gets the tstat status message.//from  ww w.  j  a va2s.  com
 * @return the tstat status message
 */
private String getTstatStatusMessage() {

    String thStatusMsg = null;
    final WebElement errorElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.cssSelector(ERROR_MODEBOX), TINY_TIMEOUT);
    if (errorElement.isDisplayed()) {
        final WebElement modeLabelelement = getElementBySubElement(getDriver(), errorElement,
                By.className(MODEL_LABEL), ATOMIC_TIMEOUT);
        thStatusMsg = getElementBySubElement(getDriver(), modeLabelelement, By.tagName(TAG_P), ATOMIC_TIMEOUT)
                .getText();
        setLogString("Thermostat status message:" + thStatusMsg, true, CustomLogLevel.HIGH);
    }
    return thStatusMsg;
}

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

License:Open Source License

/**
 * Gets the hvac mode gradient.//from  w  w  w.  j  a v a 2s .  com
 * @param mode the mode
 * @return the hvac mode gradient
 */
private String getHvacModeGradient(final String mode) {

    final WebElement gradientElement = mode.equalsIgnoreCase("off") ? getCurrentThermostatContainer()
            : getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
                    By.className(GRADIENT_BACKGROUND), TINY_TIMEOUT);

    final Object value = executeScriptByClassName(gradientElement.getAttribute("class"),
            mode.equalsIgnoreCase("off") ? "color" : "background-image", getDriver());
    setLogString("Hvac Mode Gradient Value :" + value.toString(), true, CustomLogLevel.MEDIUM);
    return value != null ? value.toString() : null;
}

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

License:Open Source License

/**
 * Checks if is location switcher displayed.
 * @return true, if is location switcher displayed
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPageUI#isLocationSwitcherDisplayed()
 *//*from w w w  .  ja v  a  2  s  .  co  m*/
@Override
public boolean isLocationSwitcherDisplayed() {

    setLogString("Check Location Switcher Icon is displayed.", true, CustomLogLevel.MEDIUM);
    boolean isTstatSwitcher = isDisplayed(getDriver(), By.className(THERMOSTAT_SWITCHER_ICON), TINY_TIMEOUT);
    setLogString(
            isTstatSwitcher ? "Location Switcher Icon is displayed." : "Location Switcher is Not displayed.",
            true, CustomLogLevel.MEDIUM);
    return isTstatSwitcher;
}

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

License:Open Source License

/**
 * Get Savings Amount//  ww w .ja  va2s.  c om
 * @return savings amount
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPageUI#getSavingsAmount()
 */
@Override
public String getSavingsAmount() {

    setLogString("Get Savings Amount", true, CustomLogLevel.HIGH);
    final WebElement savingsElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.className(SAVINGS_AMOUNT), TINY_TIMEOUT);
    setLogString("Savings Amount " + savingsElement.getText(), true, CustomLogLevel.HIGH);
    return savingsElement.getText().substring(1).isEmpty() ? "0" : savingsElement.getText().substring(1);
}

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

License:Open Source License

/**
 * Checks if is page loaded./*from   w ww .j  a v a  2  s  .c o m*/
 * @return true, if is page loaded
 * @see com.ecofactor.qa.automation.mobile.page.BasePage#isPageLoaded()
 */
@Override
public boolean isPageLoaded() {

    LogUtil.setLogString("Verify the Thermostat Control Page is loaded", true, CustomLogLevel.LOW);
    final boolean isPopUpOpened = isPopUpOpened();
    getAction().rejectAlert();
    boolean isLoaded;
    if (!isPopUpOpened) {
        LogUtil.setLogString(Marker.START,
                "Control page not opened by click on target temp, So click current temp as an workaround",
                true);
        clickCurrentTemp();
        isLoaded = isDisplayed(getDriver(), By.className(TSTAT_CONTROLS_CLOSE_BTN), TINY_TIMEOUT);
        LogUtil.setLogString(Marker.END, "Control page loaded", true);
    } else {
        LogUtil.setLogString("Tstat Control page opened", true, CustomLogLevel.HIGH);
        isLoaded = true;
    }
    return isLoaded;
}

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

License:Open Source License

/**
 * Click Close Button.//from   ww  w  .java 2  s. co m
 */
@Override
public void closeThermostatControl() {

    LogUtil.setLogString("Click Close button", true, CustomLogLevel.LOW);
    /*
     * isDisplayedBySubElement(getDriver(), getCurrentThermostatContainer(),
     * By.className(TSTAT_CONTROLS_CLOSE_BTN), TINY_TIMEOUT);
     */
    final WebElement closeBtnElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.className(TSTAT_CONTROLS_CLOSE_BTN), TINY_TIMEOUT);
    // WaitUtil.fourSec();
    thPageOps.clickotherplace();
    closeBtnElement.click();
    // closeBtnElement.sendKeys(Keys.RETURN);
    // getAction().click(closeBtnElement);
    getAction().rejectAlert();
    thContainer = null;
}