Example usage for org.openqa.selenium By cssSelector

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

Introduction

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

Prototype

public static By cssSelector(String cssSelector) 

Source Link

Document

Find elements via the driver's underlying W3C Selector engine.

Usage

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

License:Open Source License

/**
 * Close away settings popup./*from w w w  . jav a  2  s . co m*/
 * @see com.ecofactor.qa.automation.newapp.page.SetAwayPage#closeAwaySettingsPopup()
 */
@Override
public void closeAwaySettingsPopup() {

    setLogString("Click cancel button on away settings popup.", true);
    final WebElement cancelButton = getElement(getDriver(),
            By.cssSelector("input.ctaButton.setAwayCancelButton"), TINY_TIMEOUT);
    getAction().click(cancelButton);
}

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

License:Open Source License

/**
 * Click set away button./* w  ww  .  j  a v a2  s  .  c o  m*/
 * @return true, if successful
 * @see com.ecofactor.qa.automation.newapp.page.SetAwayPage#clickSetAwayButton()
 */
@Override
public boolean clickSetAwayButton() {

    WaitUtil.tinyWait();
    setLogString("Click set button on away settings popup.", true);
    getAction().rejectAlert();
    final WebElement setButton = getElement(getDriver(), By.cssSelector("input.ctaButton.setAwaySubmitButton"),
            TINY_TIMEOUT);
    WaitUtil.oneSec();
    getAction().click(setButton);
    getAction().rejectAlert();

    return isDisplayed(getDriver(), By.cssSelector("div.view_toast_container"), TINY_TIMEOUT);
}

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

License:Open Source License

/**
 * Click away parameter.//from w w w . j  a  va2s. co m
 * @param param the param
 * @return true, if successful
 */
@Override
public boolean clickAwayParamPicker(final SetAwayParams param) {

    final List<WebElement> dateAndTimePickers = getElements(getDriver(),
            By.cssSelector("div.setAwayPicker.awayEndDateTimePicker"), TINY_TIMEOUT);
    WebElement awayParamElement = null;
    if (param.equals(SetAwayParams.Days)) {
        awayParamElement = dateAndTimePickers.get(0);
    } else if (param.equals(SetAwayParams.Hours)) {
        awayParamElement = dateAndTimePickers.get(1);
    } else {
        awayParamElement = getElement(getDriver(), By.cssSelector("input.awaySetpointPicker"), TINY_TIMEOUT);
    }
    getAction().click(awayParamElement);

    return isDisplayed(getDriver(), By.cssSelector("div.dw-li.dw-v.dw-sel"), TINY_TIMEOUT);
}

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

License:Open Source License

/**
 * Sets the away param picker.//w w  w.  j  a va2  s .co  m
 * @param setAwayParams the set away params
 * @param expectedValue the expected value
 * @return true, if successful
 * @see com.ecofactor.qa.automation.newapp.page.SetAwayPage#setAwayParamPicker(com.ecofactor.qa.automation.newapp.enums.SetAwayParams,
 *      int)
 */
@Override
public boolean setAwayParamPicker(final SetAwayParams setAwayParams, final int expectedValue) {

    setLogString("Set " + setAwayParams + " as :" + expectedValue, true);

    Assert.assertTrue(clickAwayParamPicker(setAwayParams), setAwayParams + " picker not displayed.");

    final WebElement currentReadingElement = getElement(getDriver(), By.cssSelector(CURRENT_VALUE),
            TINY_TIMEOUT);
    final int currentReadingValue = Integer.parseInt(currentReadingElement.getAttribute(DATA_VALUE));

    final int setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;

    return changeAwayParamValue(setAwayParams, setPointValue).equals(expectedValue);

}

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

License:Open Source License

/**
 * Sets the away date.//from www  .ja v  a  2s.c  om
 * @param reqDateTime the new away date
 * @return true, if successful
 */
@Override
public boolean setAwayDate(final Calendar reqDateTime) {

    SimpleDateFormat enddateFormat = new SimpleDateFormat("E - MMM dd, YYYY");
    enddateFormat.setTimeZone(enddateFormat.getTimeZone());
    String enddate = enddateFormat.format(reqDateTime.getTime());
    setLogString("Set away date as :" + enddate, true, CustomLogLevel.MEDIUM);

    Assert.assertTrue(clickAwayParamPicker(SetAwayParams.Days), SetAwayParams.Days + " picker not displayed.");

    final WebElement dateContainerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl1"),
            TINY_TIMEOUT);
    final WebElement monthContainerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl0"),
            TINY_TIMEOUT);
    final WebElement yearContainerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl2"),
            TINY_TIMEOUT);

    boolean dateUpdated = true;

    final WebElement dateCurrentReadingElement = getElementBySubElement(getDriver(), dateContainerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    int currentReadingValue = Integer.parseInt(dateCurrentReadingElement.getAttribute(DATA_VALUE));
    int expectedValue = reqDateTime.get(Calendar.DATE);
    int setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;
    dateUpdated = dateUpdated
            && changeRequiredParameter(dateContainerElement, setPointValue, reqDateTime.get(Calendar.DATE));

    final WebElement monthCurrentReadingElement = getElementBySubElement(getDriver(), monthContainerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    currentReadingValue = Integer.parseInt(monthCurrentReadingElement.getAttribute(DATA_VALUE));
    expectedValue = reqDateTime.get(Calendar.MONTH);
    setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;
    dateUpdated = dateUpdated
            && changeRequiredParameter(monthContainerElement, setPointValue, reqDateTime.get(Calendar.MONTH));

    final WebElement yearCurrentReadingElement = getElementBySubElement(getDriver(), yearContainerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    currentReadingValue = Integer.parseInt(yearCurrentReadingElement.getAttribute(DATA_VALUE));
    expectedValue = reqDateTime.get(Calendar.YEAR);
    setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;
    dateUpdated = dateUpdated
            && changeRequiredParameter(yearContainerElement, setPointValue, reqDateTime.get(Calendar.YEAR));

    saveAwaySettings();

    return dateUpdated;
}

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

License:Open Source License

/**
 * Sets the away time.// ww  w.j  ava 2s. c o m
 * @param reqDateTime the new away time
 * @return true, if successful
 */
@Override
public boolean setAwayTime(final Calendar reqDateTime) {

    SimpleDateFormat endtimeFormat = new SimpleDateFormat("HH:MM a Z");
    endtimeFormat.setTimeZone(endtimeFormat.getTimeZone());
    String endtime = endtimeFormat.format(reqDateTime.getTime());
    setLogString("Set away time as :" + endtime, true, CustomLogLevel.MEDIUM);

    boolean timeUpdated = true;
    Assert.assertTrue(clickAwayParamPicker(SetAwayParams.Hours),
            SetAwayParams.Hours + " picker not displayed.");

    final WebElement hourContainerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl0"),
            TINY_TIMEOUT);
    final WebElement minuteContainerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl1"),
            TINY_TIMEOUT);
    final WebElement ampmContainerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl2"),
            TINY_TIMEOUT);

    final WebElement hourCurrentReadingElement = getElementBySubElement(getDriver(), hourContainerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    int currentReadingValue = Integer.parseInt(hourCurrentReadingElement.getAttribute(DATA_VALUE));
    int expectedValue = reqDateTime.get(Calendar.HOUR);
    int setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;
    timeUpdated = timeUpdated
            && changeRequiredParameter(hourContainerElement, setPointValue, reqDateTime.get(Calendar.HOUR));

    final WebElement minuteCurrentReadingElement = getElementBySubElement(getDriver(), minuteContainerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    currentReadingValue = Integer.parseInt(minuteCurrentReadingElement.getAttribute(DATA_VALUE));
    expectedValue = reqDateTime.get(Calendar.MINUTE);
    setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;
    timeUpdated = timeUpdated
            && changeRequiredParameter(minuteContainerElement, setPointValue, reqDateTime.get(Calendar.MINUTE));

    final WebElement ampmCurrentReadingElement = getElementBySubElement(getDriver(), ampmContainerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    currentReadingValue = Integer.parseInt(ampmCurrentReadingElement.getAttribute(DATA_VALUE));
    expectedValue = reqDateTime.get(Calendar.AM_PM);
    setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;
    timeUpdated = timeUpdated
            && changeRequiredParameter(ampmContainerElement, setPointValue, reqDateTime.get(Calendar.AM_PM));

    saveAwaySettings();
    return timeUpdated;
}

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

License:Open Source License

/**
 * Change required parameter.//from   ww w .  j ava2  s. co  m
 * @param containerElement the container element
 * @param noOfSetPoints the no of set points
 * @param expectedValue the expected value
 * @return true, if successful
 */
private boolean changeRequiredParameter(final WebElement containerElement, final int noOfSetPoints,
        final int expectedValue) {

    final int setPoints = Math.abs(noOfSetPoints);
    final WebElement upOrDownArrow = expectedValue > 0
            ? getElementBySubElement(getDriver(), containerElement, By.cssSelector("a.dwb-e.dwwb.dwwbm"),
                    SHORT_TIMEOUT)
            : getElementBySubElement(getDriver(), containerElement, By.cssSelector("a.dwb-e.dwwb.dwwbp"),
                    SHORT_TIMEOUT);

    for (int count = 0; count < setPoints; count++) {
        getAction().click(upOrDownArrow);
    }

    final WebElement currentReadingElement = getElementBySubElement(getDriver(), containerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    final Integer currentReadingValue = Integer.parseInt(currentReadingElement.getAttribute(DATA_VALUE));

    return currentReadingValue.equals(expectedValue);
}

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

License:Open Source License

/**
 * Gets the default time to set away./*from w w  w.  j a va2s .  c om*/
 * @return String default away time
 * @see com.ecofactor.qa.automation.newapp.page.SetAwayPage#getDefaultAwayTime
 */
@Override
public String getDefaultAwayTime() {

    final List<WebElement> dateTimePickers = getElements(getDriver(),
            By.cssSelector(".setAwayPicker.awayEndDateTimePicker"), TINY_TIMEOUT);

    final String currentTimeString = dateTimePickers.get(1).getText();

    return currentTimeString;
}

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

License:Open Source License

/**
 * Click Set button in away popup.//from w w  w  .jav  a 2  s .  c om
 * @see com.ecofactor.qa.automation.newapp.page.SetAwayPage#clickSetButton()
 */
@Override
public void clickSetButton() {

    setLogString("Click Set Button", true, CustomLogLevel.MEDIUM);
    final WebElement footerElement = getElement(getDriver(), By.cssSelector(".footerAwayPicker"),
            SHORT_TIMEOUT);
    final WebElement awaySettingsPopUp = getElementBySubElement(getDriver(), footerElement,
            By.cssSelector(".ctaButton.setAwaySubmitButton"), TINY_TIMEOUT);
    getAction().click(awaySettingsPopUp);
    getAction().rejectAlert();
}

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

License:Open Source License

/**
 * Click Set Away from Settigns page./* w w w .ja v  a 2  s  .  c  o m*/
 * @see com.ecofactor.qa.automation.newapp.page.SetAwayPage#clickAwaySettings()
 */
@Override
public void clickAwaySettings() {

    WaitUtil.tinyWait();
    setLogString("Click SetAway in Settings", true, CustomLogLevel.MEDIUM);
    getAction().rejectAlert();
    final WebElement awaySettings = getElement(getDriver(), By.cssSelector(AWAY_SETTINGS), TINY_TIMEOUT);
    WaitUtil.oneSec();
    awaySettings.click();
    getAction().rejectAlert();
}