Example usage for org.openqa.selenium WebElement getAttribute

List of usage examples for org.openqa.selenium WebElement getAttribute

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getAttribute.

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

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  .  ja  v  a 2  s .co  m*/
 * @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 off mode dialog displayed.
 * @return true, if is off mode dialog displayed
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPageUI#isOffModeDialogDisplayed()
 *//*from  www . j av a  2 s  .  c om*/
@Override
public boolean isOffModeDialogDisplayed() {

    setLogString("Verify the off mode dialog displayed", true, CustomLogLevel.MEDIUM);
    final WebElement dialogElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.cssSelector(".modeDialog.offModeBox"), SHORT_TIMEOUT);
    final String style = dialogElement.getAttribute("style");
    if (style.contains("visibility: hidden")) {
        return false;
    }
    return true;
}

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

License:Open Source License

/**
 * @return/*from w w  w .  jav  a2 s .c  om*/
 * @see com.ecofactor.qa.automation.newapp.page.ThermostatPageUI#isNotInstalledDialogDisplayed()
 */
@Override
public boolean isNotInstalledDialogDisplayed() {

    setLogString("Verify the \"Not Installed\" dialog displayed", true, CustomLogLevel.MEDIUM);

    final WebElement dialogElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.cssSelector(".modeDialog.errorModeBox"), SHORT_TIMEOUT);
    final String style = dialogElement.getAttribute("style");
    if (style.contains("visibility: hidden")) {
        return false;
    }
    return true;
}

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

License:Open Source License

/**
 * Click mode heat./*from w  w w .  j a v a  2s .c om*/
 */
public void clickModeHeat() {

    LogUtil.setLogString("Click mode heat", true, CustomLogLevel.MEDIUM);
    isDisplayedBySubElement(getDriver(), getCurrentThermostatContainer(), By.className(HVAC_MODE_BTN),
            TINY_TIMEOUT);
    WebElement heatModeElement = getCurrentThermostatContainer();
    List<WebElement> thermostatElementList = getElementsBySubElement(getDriver(), heatModeElement,
            By.className(HVAC_MODE_BTN), TINY_TIMEOUT);
    for (WebElement webElement : thermostatElementList) {
        if (webElement.getAttribute(ATTR_VALUE).equalsIgnoreCase(HEAT)) {
            getAction().click(webElement);
            break;
        }
    }
    getAction().rejectAlert();
    verifyIdleState();
    LogUtil.setLogString("Check color changed to Red", true, CustomLogLevel.MEDIUM);
    Assert.assertTrue(verifyColorChanges(HEAT_CONTAINER), "color is not changed");
}

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

License:Open Source License

/**
 * Click mode cool./*from www.ja  v  a 2  s  .c om*/
 */
public void clickModeCool() {

    LogUtil.setLogString("Click mode Cool", true, CustomLogLevel.MEDIUM);
    WebElement heatModeElement = getCurrentThermostatContainer();
    List<WebElement> thermostatElementList = getElementsBySubElement(getDriver(), heatModeElement,
            By.className(HVAC_MODE_BTN), MEDIUM_TIMEOUT);
    for (WebElement webElement : thermostatElementList) {
        if (webElement.getAttribute(ATTR_VALUE).equalsIgnoreCase(COOL)) {
            WaitUtil.oneSec();
            webElement.click();
            tinyWait();
            // getAction().click(webElement);
            break;
        }
    }
    getAction().rejectAlert();
    verifyIdleState();
    LogUtil.setLogString("Check color changed to blue", true, CustomLogLevel.MEDIUM);
    Assert.assertTrue(verifyColorChanges(COOL_CONTAINER), "color is not changed to blue");
}

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

License:Open Source License

/**
 * Click mode off./*  w w  w . j a v  a  2  s.  c om*/
 */
public void clickModeOff() {

    LogUtil.setLogString("Click mode off", true, CustomLogLevel.LOW);
    WebElement offModeElement = getCurrentThermostatContainer();
    List<WebElement> thermostatElementList = getElementsBySubElement(getDriver(), offModeElement,
            By.className(HVAC_MODE_BTN), TINY_TIMEOUT);
    for (WebElement webElement : thermostatElementList) {
        if (webElement.getAttribute(ATTR_VALUE).equalsIgnoreCase(OFF)) {
            getAction().click(webElement);
            break;
        }
    }
}

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

License:Open Source License

/**
 * Checks if is given mode selected./* w  w w . j  av a2 s . c om*/
 * @param mode the mode
 * @return true, if is given mode selected
 */
private boolean isGivenModeSelected(String mode) {

    boolean selected = false;
    WebElement element = getElementBySubElementAttr(getDriver(), getCurrentThermostatContainer(),
            By.tagName(TAG_INPUT), ATTR_VALUE, mode, MEDIUM_TIMEOUT);
    if (element.getAttribute("class").contains("selected")) {
        String modeValue = element.getAttribute("value").toLowerCase();
        if (modeValue.equalsIgnoreCase(mode)) {
            LogUtil.setLogString(mode + " mode is selected", true, CustomLogLevel.MEDIUM);
            selected = true;
        }
    }
    return selected;
}

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

License:Open Source License

/**
 * Checks if is fan on.//from  w w  w . j a  v  a 2  s .  c  o  m
 * @return true, if is fan on
 * @see com.ecofactor.qa.automation.consumer.page.ConsumerHome#isFanOn()
 */
@Override
public boolean isFanOn() {

    WebElement fanOnElement = getElementBySubElementAttr(getDriver(), getCurrentThermostatContainer(),
            By.tagName(TAG_INPUT), ATTR_VALUE, FAN_ON, SHORT_TIMEOUT);
    boolean onSelected = fanOnElement.getAttribute("className").contains("selected");
    return onSelected;
}

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

License:Open Source License

/**
 * Gets the current mode./*from   w ww.  j  ava2  s.  c  o  m*/
 * @return the current mode
 * @see com.ecofactor.qa.automation.mobile.page.ThermostatControlPage#getCurrentMode()
 */
@Override
public String getCurrentMode() {

    String currentMode = "";
    LogUtil.setLogString("Get Current Mode", true, CustomLogLevel.HIGH);
    isDisplayedBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.className(THERMOSTAT_BTN_CONTAINER), TINY_TIMEOUT);
    WebElement thermostatElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.cssSelector("." + THERMOSTAT_BTN_CONTAINER), TINY_TIMEOUT);
    List<WebElement> thermostatElementList = getElementsBySubElement(getDriver(), thermostatElement,
            By.cssSelector("." + HVAC_MODE_BTN), TINY_TIMEOUT);
    for (WebElement webElement : thermostatElementList) {
        String currentClass = webElement.getAttribute(ATTR_CLASS);
        if (currentClass.contains(SELECTED)) {
            currentMode = webElement.getAttribute(ATTR_VALUE);
            break;
        }
    }
    LogUtil.setLogString("Current Mode is :" + currentMode, true);
    return currentMode;

}

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

License:Open Source License

/**
 * Gets the available modes.//  w  w w  .ja  v a  2  s . com
 * @return the available modes
 */
public List<String> getAvailableModes() {

    List<String> availableModeList = new ArrayList<String>();
    isDisplayedBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.className(THERMOSTAT_BTN_CONTAINER), TINY_TIMEOUT);
    WebElement thermostatElement = getElementBySubElement(getDriver(), getCurrentThermostatContainer(),
            By.cssSelector("." + THERMOSTAT_BTN_CONTAINER), TINY_TIMEOUT);
    List<WebElement> thermostatElementList = getElementsBySubElement(getDriver(), thermostatElement,
            By.cssSelector("." + HVAC_MODE_BTN), TINY_TIMEOUT);
    for (WebElement webElement : thermostatElementList) {
        availableModeList.add(webElement.getAttribute(ATTR_VALUE));
    }
    return availableModeList;
}