Example usage for org.openqa.selenium By tagName

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

Introduction

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

Prototype

public static By tagName(String tagName) 

Source Link

Usage

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Gets the page size./*from   w w w.  j  a v a  2 s .com*/
 * 
 * @param eventListTable
 *            the event list table
 * @return the page size
 */
public Integer getPageSize(WebElement eventListTable) {

    DriverConfig.setLogString("get the page size displayed in screen.", true);
    WebElement pageSize = retrieveElementByAttributeValueForSubElement(DriverConfig.getDriver(), eventListTable,
            TAG_SPAN, ATTR_CLASS, demandSideManagementConfig.get(CURRENT_PAGINATOR), LONG_TIMEOUT);
    String eventListElement = pageSize.getText();
    log(eventListElement.substring(eventListElement.indexOf("of ") + 3, eventListElement.length() - 1));
    String pageLength = eventListElement.substring(eventListElement.indexOf("of ") + 3,
            eventListElement.length() - 1);
    WaitUtil.waitUntil(1000);
    logger.info("get the paginator Bottom UI Element.");
    WebElement paginatorBottomElement = retrieveElementByAttributeValueForSubElement(DriverConfig.getDriver(),
            eventListTable, "td", ATTR_ID, demandSideManagementConfig.get(EVENT_PAGINATION_BOTTOM_ELEMENT),
            LONG_TIMEOUT);
    WaitUtil.waitUntil(1000);
    List<WebElement> paginatorItems = paginatorBottomElement.findElements(By.tagName(TAG_SPAN));
    WaitUtil.waitUntil(1000);
    paginatorItems.get(paginatorItems.size() - 1).click();
    WaitUtil.waitUntil(SHORT_TIMEOUT);
    logger.info("page size is " + pageLength);
    return Integer.parseInt(pageLength);
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Test event pagination limit.//  w  ww  .  ja  v a2s  .  c  om
 * 
 * @param programName
 *            the program name
 * @param duration
 *            the duration
 * @param eventMode
 *            the event mode
 * @param precoolOpted
 *            the precool opted
 * @param eventCheckCount
 *            the event check count
 * @throws ParseException
 *             the parse exception
 */

public void testEventPaginationLimit(final String programName, final String duration, final String eventMode,
        final boolean precoolOpted, Integer eventCheckCount) throws ParseException {

    int i = 0;
    int eventCount = 0;
    int rowCount = 0;
    WebElement eventListTable = null;
    WebElement eventListTableDataRows = null;
    List<WebElement> paginationSection = null;
    List<WebElement> eventRows;
    Integer totalPagesDisplayed = 0;

    pickGivenProgram(programName);
    WaitUtil.waitUntil(SHORT_TIMEOUT);

    ecpCoreLSProgram = new EcpCoreLSProgram();
    lsProgramId = getProgramId();
    DriverConfig.setLogString("get program details from DB.", true);
    ecpCoreLSProgram = (EcpCoreLSProgram) lsProgramDao.getEcpCoreLSProgram(lsProgramId).get(0);

    logger.info("get the event list page form element.");
    formElement = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME)));
    eventListTable = formElement.findElement(By.id(demandSideManagementConfig.get(FORM_EVENT_LIST_TABLE)));
    paginationSection = eventListTable
            .findElements(By.id(demandSideManagementConfig.get(FORM_EVENT_LIST_TABLE_PAGINATOR_BOTTOM)));

    if (paginationSection.size() > 0)
        totalPagesDisplayed = getPageSize(eventListTable);
    mediumWait();

    formElement = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME)));
    eventListTable = formElement.findElement(By.id(demandSideManagementConfig.get(FORM_EVENT_LIST_TABLE)));

    eventListTableDataRows = formElement
            .findElement(By.id(demandSideManagementConfig.get(FORM_EVENT_LIST_PAGINATION_DATA)));
    eventRows = eventListTableDataRows.findElements(By.tagName("tr"));
    rowCount = eventRows.size();

    eventCount = 10 - rowCount;

    if (eventCheckCount == 11) {
        eventCount = 10 - rowCount;
        eventCount++;
    }

    logger.info("event Check Count: " + eventCheckCount);
    logger.info("event Count: " + eventCount);
    logger.info("pagination Section size: " + paginationSection.size());
    logger.info("Total pages: " + totalPagesDisplayed);
    logger.info("Row count: " + rowCount);

    while (i < eventCount) {
        formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
        eventDate = Calendar.getInstance();
        eventDate.setTimeZone(TimeZone.getTimeZone(ecpCoreLSProgram.getTimeZone()));
        logger.info("program  minimum start time :" + ecpCoreLSProgram.getMinStartHour());
        eventDate.add(Calendar.DATE, Integer.parseInt(demandSideManagementConfig.get(ADD_EVENT_DATE_PART)));
        eventDate.set(Calendar.HOUR, ecpCoreLSProgram.getMinStartHour());

        if (ecpCoreLSProgram.getMinStartHour() >= 12)
            eventDate.set(Calendar.AM_PM, 1);
        else
            eventDate.set(Calendar.AM_PM, 0);

        createEvent(false, formatter.format(eventDate.getTime()), duration, eventMode, precoolOpted, null);
        WaitUtil.waitUntil(5000);
        i++;
    }
    smallWait();
    eventListTable = formElement.findElement(By.id(demandSideManagementConfig.get(FORM_EVENT_LIST_TABLE)));
    paginationSection = eventListTable
            .findElements(By.id(demandSideManagementConfig.get(FORM_EVENT_LIST_TABLE_PAGINATOR_BOTTOM)));
    DriverConfig.setLogString("check if new page displayed if event count greater than 10.", true);
    if (eventCheckCount == 10) {
        if (paginationSection.size() > 0) {
            Assert.assertTrue(totalPagesDisplayed.equals(getPageSize(eventListTable)),
                    "page size is different");
        } else {
            Assert.assertTrue(totalPagesDisplayed == 0, "page count is not zero");
        }
    } else {
        if (paginationSection.size() > 0) {
            Assert.assertFalse(totalPagesDisplayed.equals(getPageSize(eventListTable)),
                    "page size is different");
        } else {
            Assert.assertTrue(totalPagesDisplayed > 0, "page count is less than zero");
        }
    }

}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Create Event Method creates LS Event in a given LS Program. Start date ,
 * duration and mode (draft/save & schedule) for event creation are provided
 * as input .//from w  w  w  . ja v a2 s .co  m
 * 
 * @param pastEvent
 *            the past event
 * @param startDate
 *            the start date
 * @param duration
 *            the duration
 * @param mode
 *            the mode
 * @param precoolOpted
 *            the precool opted
 * @param groupName
 *            the group name
 * @return the string
 * @throws ParseException
 *             the parse exception
 */
public String createEvent(final boolean pastEvent, final String startDate, final String duration,
        final String mode, final boolean precoolOpted, String groupName) throws ParseException {

    DriverConfig.setLogString("Start create new event.", true);
    formatter = new SimpleDateFormat("yyyyMMddhhmmss");
    WaitUtil.waitUntil(18000);
    // WaitUtil.waitUntil(10000);
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME),
            SHORT_TIMEOUT);
    formElement = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME)));
    DriverConfig.setLogString("click create new event link.", true);
    WebElement newEventLink = formElement.findElement(By.linkText(demandSideManagementConfig.get(NEW_EVENT)));
    newEventLink.click();

    inputEventName = "Test_" + formatter.format(new java.util.Date());
    inputEventDesc = "Description for Test_" + formatter.format(new java.util.Date());
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_CREATE_FORM_NAME),
            SHORT_TIMEOUT);

    newEventWizardForm = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_CREATE_FORM_NAME)));
    WaitUtil.waitUntil(5000);
    DriverConfig.setLogString("find event name field.", true);
    WebElement eventName = newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_NAME)));
    DriverConfig.setLogString("Enter event name." + inputEventName, true);
    eventName.sendKeys(inputEventName);
    DriverConfig.setLogString("find event description field & send values to it.", true);
    newEventWizardForm.findElement(By.tagName(TAG_TEXTAREA)).sendKeys(inputEventDesc);
    DriverConfig.setLogString("Event Name provided :" + inputEventName, true);
    DriverConfig.setLogString("Event Desc provided :" + inputEventDesc, true);
    DriverConfig.setLogString("Event Start date provided :" + startDate, true);
    DriverConfig.setLogString("find start date field and enter start date.", true);
    newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(START_TIME))).clear();
    newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(START_TIME))).sendKeys(startDate);
    roleManagement.clickDone();
    DriverConfig.setLogString("find event duration field.", true);
    isFormDisplayedById(DriverConfig.getDriver(), newEventWizardForm,
            demandSideManagementConfig.get(EVENT_DURATION_ELEMENT), SHORT_TIMEOUT);
    DriverConfig.setLogString("select duration.", true);
    selectOptionByValue(newEventWizardForm, demandSideManagementConfig.get(EVENT_DURATION_ELEMENT), duration);
    DriverConfig.setLogString("Event Duration provided :" + duration + " minutes.", true);

    WaitUtil.waitUntil(1000);
    WebElement precoolOption = newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(PRECOOL)));

    newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_DURATION_ELEMENT))).click();
    DriverConfig.setLogString("select precool option if needed.", true);
    WaitUtil.waitUntil(SHORT_TIMEOUT);
    if (precoolOpted) {
        isFormElementClickableById(DriverConfig.getDriver(), demandSideManagementConfig.get(PRECOOL),
                MEDIUM_TIMEOUT);
        if (precoolOption.isSelected() == false)
            precoolOption.click();
    }
    smallWait();
    // DriverConfig.setLogString("Unselect the group for event.", true);
    // select groups
    WebElement selectGroupsForm = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(POPUP_FORM)));
    if (groupName != null) {
        DriverConfig.setLogString("select groups for event." + groupName, true);
        retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), selectGroupsForm, TAG_SPAN,
                ATTR_CLASS, demandSideManagementConfig.get(SELECT_GROUPS_CHECKBOX)).click();
        WebElement groupsTableElement = retrieveElementByAttributeValueByPassingElement(
                DriverConfig.getDriver(), selectGroupsForm, TAG_TBODY, ATTR_ID,
                demandSideManagementConfig.get(GROUP_LIST_TABLE));
        List<WebElement> groupRows = groupsTableElement.findElements(By.tagName("tr"));
        for (WebElement element : groupRows) {
            List<WebElement> groupColumns = element.findElements(By.tagName("td"));
            if (!groupColumns.isEmpty()) {
                WebElement checkBoxElement = groupColumns.get(0).findElement(By.tagName(TAG_INPUT));
                WebElement groupNameElement = groupColumns.get(1);
                if (groupNameElement.findElement(By.tagName(TAG_DIV)).getText().equalsIgnoreCase(groupName))
                    // select the group name check box
                    checkBoxElement.click();
            }
        }
    }
    // End Select groups
    DriverConfig.setLogString("Mode " + mode, true);
    smallWait();
    isFormDisplayedById(DriverConfig.getDriver(), newEventWizardForm,
            demandSideManagementConfig.get(EVENT_SAVE_BTN), MEDIUM_TIMEOUT);
    if (mode.equalsIgnoreCase(demandSideManagementConfig.get(EVENT_TYPE_DRAFT))) {
        WaitUtil.waitUntil(SHORT_TIMEOUT);
        DriverConfig.setLogString("click draft button.", true);
        newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_SAVE_BTN))).click();
    } else if (mode.equalsIgnoreCase(demandSideManagementConfig.get(EVENT_TYPE_SCHEDULED))) {
        WaitUtil.waitUntil(SHORT_TIMEOUT);
        DriverConfig.setLogString("click schedule button.", true);
        newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_SCHEDULED_BTN))).click();
    } else {
        smallWait();
        DriverConfig.setLogString("click cancel button.", true);
        newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_CANCEL_BTN))).click();
    }

    return inputEventName;
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * select Event Link Initiates event search by loading event list page.
 * //from   w ww  .  j a  v  a 2  s  .  com
 * @param inputEventName
 *            the input event name
 */
public void selectEventLink(String inputEventName) {

    DriverConfig.setLogString("Select the event " + inputEventName + " from the list.", true);
    loadPageFrame();
    WaitUtil.waitUntil(10000);
    logger.info("check if event list form displayed.");
    WebElement formElement = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME)));
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME),
            SHORT_TIMEOUT);
    mediumWait();
    logger.info("check if event pagination element is displayed.", true);
    if (formElement.findElements(By.id(demandSideManagementConfig.get(EVENT_PAGINATION_BOTTOM_ELEMENT)))
            .size() > 0) {
        isFormDisplayedById(DriverConfig.getDriver(), formElement,
                demandSideManagementConfig.get(EVENT_PAGINATION_BOTTOM_ELEMENT), SHORT_TIMEOUT);
        WebElement eventIndexElement = retrieveElementByAttributeValue(DriverConfig.getDriver(), TAG_TD,
                ATTR_ID, demandSideManagementConfig.get(EVENT_PAGINATION_BOTTOM_ELEMENT));
        if (eventIndexElement != null) {
            WebElement pageIndexElement = formElement
                    .findElement(By.id(demandSideManagementConfig.get(EVENT_PAGINATION_BOTTOM_ELEMENT)));
            List<WebElement> pageIndexes = pageIndexElement.findElements(By.tagName(TAG_SPAN));
            lastPageElement = pageIndexes.get(pageIndexes.size() - 1);
            if (!lastPageElement.getAttribute(ATTR_CLASS).endsWith(demandSideManagementConfig.get(DISABLED))) {
                lastPageElement.click();
                smallWait();
            }
            nextPageElement = pageIndexes.get(pageIndexes.size() - 4);
            iterateEventList();
        }
    } else {
        logger.info("there is no pagination select event in the default page.");
        WebElement eventElement = retrieveElementByTagTextForSubElement(DriverConfig.getDriver(), formElement,
                TAG_ANCHOR, inputEventName);
        if (eventElement != null) {
            smallWait();
            DriverConfig.setLogString("select the event link.", true);
            eventElement.click();
            eventfound = true;
        }
    }
    if (eventfound == false) {
        DriverConfig.setLogString("Event name '" + inputEventName + "' not found.", true);
    }
    loadPageFrame();
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_CREATE_FORM_NAME),
            SHORT_TIMEOUT);
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * iterateAndClickParticularProgram Iterate the Pagination and click on
 * particular program, if it was found./* ww w . ja va  2 s  .  c o m*/
 * 
 * @param programeName
 *            the programe name
 */
public void iterateAndClickParticularProgram(final String programeName) {

    DriverConfig.setLogString("Iterate the program list and click on specified program.", true);
    // WaitUtil.waitUntil(30000);
    WaitUtil.waitUntil(20000);
    logger.info("check if program list form displayed.");
    formElement = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(PROGRAM_LIST_FORM)));
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(PROGRAM_LIST_FORM), LONG_TIMEOUT);
    List<WebElement> lastPageDisabledState = retrieveElementsByAttributeValueList(DriverConfig.getDriver(),
            TAG_SPAN, ATTR_CLASS, demandSideManagementConfig.get(LAST_PAGE_DISABLED));
    logger.info("check if program pagination element displayed.");
    if (formElement.findElements(By.id(demandSideManagementConfig.get(PROGRAM_PAGINATION_BOTTOM_ELEMENT)))
            .size() > 0 && lastPageDisabledState.size() == 0) {

        isFormDisplayedById(DriverConfig.getDriver(), formElement,
                demandSideManagementConfig.get(PROGRAM_PAGINATION_BOTTOM_ELEMENT), SHORT_TIMEOUT);
        WebElement paginationBottomElement = formElement
                .findElement(By.id(demandSideManagementConfig.get(PROGRAM_PAGINATION_BOTTOM_ELEMENT)));
        logger.info("check if last page button displayed.");
        List<WebElement> paginationElements = paginationBottomElement.findElements(By.tagName(TAG_SPAN));
        for (WebElement items : paginationElements) {
            if (items.getAttribute(ATTR_CLASS).equalsIgnoreCase(demandSideManagementConfig.get(LAST_PAGE_ICON))
                    || items.getAttribute(ATTR_CLASS)
                            .equalsIgnoreCase(demandSideManagementConfig.get(LAST_PAGE_WITHOUT_HOVER))) {
                logger.info("select last page.");
                items.click();
                logger.info("Last page is clicked." + items.getAttribute(ATTR_CLASS));
                break;
            }
        }

        retrieveElementByAttributeValue(DriverConfig.getDriver(), TAG_SPAN, ATTR_CLASS,
                demandSideManagementConfig.get(LAST_PAGE_DISABLED));
        WebElement programIndexElement = retrieveElementByAttributeValue(DriverConfig.getDriver(), TAG_TD,
                ATTR_ID, demandSideManagementConfig.get(PROGRAM_PAGINATION_BOTTOM_ELEMENT));
        if (programIndexElement != null) {
            WebElement pageIndexElement = formElement
                    .findElement(By.id(demandSideManagementConfig.get(PROGRAM_PAGINATION_BOTTOM_ELEMENT)));
            List<WebElement> pageIndexes = pageIndexElement.findElements(By.tagName(TAG_SPAN));
            previousPageElement = pageIndexes.get(pageIndexes.size() - 4);
            iterateProgramList(programeName);
        }

    } else {
        logger.info("There are no multiple pages available. Select from the default page.");
        WebElement programElement = retrieveElementByTagTextForSubElement(DriverConfig.getDriver(), formElement,
                TAG_ANCHOR, programeName);
        if (programElement != null) {
            smallWait();
            DriverConfig.setLogString("click the program element.", true);
            programElement.click();
            programfound = true;
        }

    }

    if (programfound == false) {
        DriverConfig.setLogString("Load shapping program '" + programeName + "' not found.", true);
    }

}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Test Event Status Filter verifies that the event status filter shows up
 * list of events with selected event status.
 * //  w  ww  . ja  va  2s .c o m
 * @param programName
 *            the program name
 * @throws ParseException
 *             the parse exception
 */
public void testEventStatusFilter(final String programName) throws ParseException {

    pickGivenProgram(programName);
    loadPageFrame();
    logger.info("check if event list form available.", true);
    isDisplayedById(DriverConfig.getDriver(), "form", SHORT_TIMEOUT);

    formElement = DriverConfig.getDriver().findElement(By.id("form"));
    DriverConfig.setLogString("find the event filter element.", true);
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_STATUS_FILTER),
            SHORT_TIMEOUT);
    DriverConfig.setLogString(
            "select options displayed in event status filter element and check if resulting event list displays events correspondingly.",
            true);
    WebElement select = formElement.findElement(By.id(demandSideManagementConfig.get(EVENT_STATUS_FILTER)));
    List<WebElement> options = select.findElements(By.tagName("option"));
    int i = 0;
    for (WebElement option : options) {

        selectOptionByText(formElement, demandSideManagementConfig.get(EVENT_STATUS_FILTER), option.getText());
        if (option.isSelected()) {
            WaitUtil.waitUntil(2000);
            DriverConfig.setLogString("filter for " + option.getText() + ".", true);
            List<WebElement> listedEventStatus = retrieveElementsByAttributeValueList(DriverConfig.getDriver(),
                    TAG_SPAN, ATTR_CLASS, demandSideManagementConfig.get(EVENT_STATUS_CLASS));

            for (WebElement listItem : listedEventStatus) {
                WaitUtil.waitUntil(1000);
                log(listItem.getText());
                if (i > 0) {
                    Assert.assertTrue(listItem.getText().equalsIgnoreCase(option.getText()),
                            "Status are different");
                }
            }
        }
        i++;
    }
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Filter status.//from w ww  .  j  a v a  2s.  c  om
 * 
 * @param status
 *            the status
 */
public void filterStatus(String status) {

    formElement = DriverConfig.getDriver().findElement(By.id("form"));
    DriverConfig.setLogString("find the event filter element.", true);
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_STATUS_FILTER),
            SHORT_TIMEOUT);
    DriverConfig.setLogString(
            "select options displayed in event status filter element and check if resulting event list displays events correspondingly.",
            true);
    WebElement select = formElement.findElement(By.id(demandSideManagementConfig.get(EVENT_STATUS_FILTER)));
    List<WebElement> options = select.findElements(By.tagName("option"));
    int i = 0;
    for (WebElement option : options) {

        if (option.getText().equalsIgnoreCase(status)) {
            selectOptionByText(formElement, demandSideManagementConfig.get(EVENT_STATUS_FILTER),
                    option.getText());
            if (option.isSelected()) {
                WaitUtil.waitUntil(2000);
                DriverConfig.setLogString("filter for " + option.getText() + ".", true);
                List<WebElement> listedEventStatus = retrieveElementsByAttributeValueList(
                        DriverConfig.getDriver(), TAG_SPAN, ATTR_CLASS,
                        demandSideManagementConfig.get(EVENT_STATUS_CLASS));

                for (WebElement listItem : listedEventStatus) {
                    WaitUtil.waitUntil(1000);
                    log(listItem.getText());
                    if (i > 0) {
                        Assert.assertTrue(listItem.getText().equalsIgnoreCase(option.getText()),
                                "Status are different");
                    }
                }
            }
            i++;
        }
    }
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Completed event status view./*  ww w  .j  a va2  s .c o m*/
 * 
 * @param programName
 *            the program name
 * @return the load shaping event report
 * @throws ParseException
 *             the parse exception
 */
public LoadShapingEventReport completedEventStatusView(final String programName) throws ParseException {

    List<String> eventReport = new ArrayList<String>();
    pickGivenProgram(programName);
    loadPageFrame();
    logger.info("check if event list form is available.", true);
    isDisplayedById(DriverConfig.getDriver(), "form", SHORT_TIMEOUT);
    formElement = DriverConfig.getDriver().findElement(By.id("form"));
    logger.info("check if event status filter is available.", true);
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_STATUS_FILTER),
            SHORT_TIMEOUT);

    WebElement select = formElement.findElement(By.id(demandSideManagementConfig.get(EVENT_STATUS_FILTER)));
    List<WebElement> options = select.findElements(By.tagName("option"));

    for (WebElement option : options) {
        if (option.getAttribute("value").contains(Status.COMPLETED.toString())) {
            selectOptionByText(formElement, demandSideManagementConfig.get(EVENT_STATUS_FILTER),
                    option.getText());
            WaitUtil.waitUntil(2000);
            List<WebElement> listedEventStatus = retrieveElementsByAttributeValueList(DriverConfig.getDriver(),
                    TAG_ANCHOR, ATTR_CLASS, demandSideManagementConfig.get(EVENT_STATUS_LINK_CLASS));
            logger.info("size:" + listedEventStatus.size());
            for (WebElement listItem : listedEventStatus) {
                WaitUtil.waitUntil(1000);
                // DriverConfig.setLogString("listItem " +
                // listItem.getAttribute(ATTR_ID));
                if (listItem.getText().equalsIgnoreCase(Status.COMPLETED.toString())) {
                    listItem.click();
                    WaitUtil.waitUntil(1000);
                    WebElement spanForm = DriverConfig.getDriver()
                            .findElement(By.id(demandSideManagementConfig.get(REPORT_DISPLAY_FORM)));
                    WaitUtil.waitUntil(1000);
                    List<WebElement> labelElements = spanForm.findElements(By.tagName("label"));

                    for (WebElement labels : labelElements) {
                        logger.info("Labels: " + labels.getText().toString());
                        eventReport.add(labels.getText());
                    }
                    break;
                }
            }
        }
    }

    Iterator<String> iterator = eventReport.iterator();
    Calendar rDate = Calendar.getInstance();
    while (iterator.hasNext()) {
        // PROGRAM,EVENT,EVENT_PERIOD,EVENT_STATUS ,LOCATIONS_TARGETED,
        // LOCATIONS_PARTICIPATED
        formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
        String labelText = iterator.next();
        String labelValue = null;
        logger.info("Label text: " + labelText);
        if (labelText.equalsIgnoreCase(demandSideManagementConfig.get(PROGRAM))) {
            labelValue = iterator.next();
            lsEventReportUI.getLoadShapingEvent().getEcpCoreLSProgram().setName(labelValue);
        } else if (labelText.equalsIgnoreCase(demandSideManagementConfig.get(EVENT))) {
            labelValue = iterator.next();
            lsEventReportUI.getLoadShapingEvent().setName(labelValue);
        } else if (labelText.equalsIgnoreCase(demandSideManagementConfig.get(LOCATIONS_TARGETED))) {
            labelValue = iterator.next();
            lsEventReportUI.setNumExpectedLocations(Integer.parseInt(labelValue));

        } else if (labelText.equalsIgnoreCase(demandSideManagementConfig.get(LOCATIONS_PARTICIPATED))) {
            labelValue = iterator.next();
            lsEventReportUI.setNumActualLocations(Integer.parseInt(labelValue));

        } else if (labelText.equalsIgnoreCase(demandSideManagementConfig.get(EVENT_STATUS))) {
            labelValue = iterator.next();
            lsEventReportUI.getLoadShapingEvent().setStatus(Status.valueOf(labelValue));

        } else if (labelText.equalsIgnoreCase(demandSideManagementConfig.get(EVENT_PERIOD))) {
            labelValue = iterator.next();
            rDate.setTime(formatter.parse(labelValue.trim()));
            lsEventReportUI.getLoadShapingEvent().setStartDate(rDate);
            labelValue = iterator.next();
            String endTimePart = labelValue.trim();

            rDate.set(Calendar.HOUR, Integer.parseInt(endTimePart.split(":")[0]));
            rDate.set(Calendar.MINUTE,
                    Integer.parseInt(endTimePart.substring(endTimePart.indexOf(":") + 1, 5)));

            if (endTimePart.substring(endTimePart.indexOf(" ") + 1, 8).equalsIgnoreCase("AM")) {
                rDate.set(Calendar.AM, 1);
            } else {
                rDate.set(Calendar.PM, 1);
            }
            lsEventReport.getLoadShapingEvent().setEndDate(rDate);

            /*
             * rDate.setTime(formatter.parse(iterator.next().split("-")[1]));
             * lsEventReport.getLoadShapingEvent().setEndDate(rDate);
             * rDate.setTimeZone(TimeZone.
             * getTimeZone(lsEventReportUI.getLoadShapingEvent
             * ().getTimeZone()));
             */
        }
    }

    return lsEventReportUI;
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Create Event Method creates LS Event in a given LS Program. Start date ,
 * duration and mode (draft/save & schedule) for event creation are provided
 * as input ./*from  w  w w .ja  va 2 s  . c  o m*/
 * 
 * @param pastEvent
 *            the past event
 * @param startDate
 *            the start date
 * @param duration
 *            the duration
 * @param mode
 *            the mode
 * @param precoolOpted
 *            the precool opted
 * @param groupName
 *            the group name
 * @return the string
 * @throws ParseException
 *             the parse exception
 */
public String createEventWithoutStartTime(final boolean pastEvent, final String startDate,
        final String duration, final String mode, final boolean precoolOpted, String groupName)
        throws ParseException {

    DriverConfig.setLogString("Start create new event.", true);
    formatter = new SimpleDateFormat("yyyyMMddhhmmss");
    WaitUtil.waitUntil(18000);
    // WaitUtil.waitUntil(10000);
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME),
            SHORT_TIMEOUT);
    formElement = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_LIST_PAGE_FORM_NAME)));
    DriverConfig.setLogString("click create new event link.", true);
    WebElement newEventLink = formElement.findElement(By.linkText(demandSideManagementConfig.get(NEW_EVENT)));
    newEventLink.click();

    inputEventName = "Test_" + formatter.format(new java.util.Date());
    inputEventDesc = "Description for Test_" + formatter.format(new java.util.Date());
    isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(EVENT_CREATE_FORM_NAME),
            SHORT_TIMEOUT);

    newEventWizardForm = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(EVENT_CREATE_FORM_NAME)));
    WaitUtil.waitUntil(5000);
    DriverConfig.setLogString("find event name field.", true);
    WebElement eventName = newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_NAME)));
    DriverConfig.setLogString("Enter event name." + inputEventName, true);
    eventName.sendKeys(inputEventName);
    DriverConfig.setLogString("find event description field & send values to it.", true);
    newEventWizardForm.findElement(By.tagName(TAG_TEXTAREA)).sendKeys(inputEventDesc);
    DriverConfig.setLogString("Event Name provided :" + inputEventName, true);
    DriverConfig.setLogString("Event Desc provided :" + inputEventDesc, true);
    DriverConfig.setLogString("Event Start date provided :" + startDate, true);
    DriverConfig.setLogString("find start date field and enter start date.", true);
    newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(START_TIME))).clear();
    newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(START_TIME))).sendKeys(startDate);
    roleManagement.clickDone();
    DriverConfig.setLogString("find event duration field.", true);
    isFormDisplayedById(DriverConfig.getDriver(), newEventWizardForm,
            demandSideManagementConfig.get(EVENT_DURATION_ELEMENT), SHORT_TIMEOUT);
    DriverConfig.setLogString("select duration.", true);
    selectOptionByValue(newEventWizardForm, demandSideManagementConfig.get(EVENT_DURATION_ELEMENT), duration);
    DriverConfig.setLogString("Event Duration provided :" + duration + " minutes.", true);

    WaitUtil.waitUntil(1000);
    WebElement precoolOption = newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(PRECOOL)));

    newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_DURATION_ELEMENT))).click();
    DriverConfig.setLogString("select precool option if needed.", true);
    WaitUtil.waitUntil(SHORT_TIMEOUT);
    if (precoolOpted) {
        isFormElementClickableById(DriverConfig.getDriver(), demandSideManagementConfig.get(PRECOOL),
                MEDIUM_TIMEOUT);
        if (precoolOption.isSelected() == false)
            precoolOption.click();
    }
    smallWait();
    // DriverConfig.setLogString("Unselect the group for event.", true);
    // select groups
    WebElement selectGroupsForm = DriverConfig.getDriver()
            .findElement(By.id(demandSideManagementConfig.get(POPUP_FORM)));
    if (groupName != null) {
        DriverConfig.setLogString("select groups for event." + groupName, true);
        retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), selectGroupsForm, TAG_SPAN,
                ATTR_CLASS, demandSideManagementConfig.get(SELECT_GROUPS_CHECKBOX)).click();
        WebElement groupsTableElement = retrieveElementByAttributeValueByPassingElement(
                DriverConfig.getDriver(), selectGroupsForm, TAG_TBODY, ATTR_ID,
                demandSideManagementConfig.get(GROUP_LIST_TABLE));
        List<WebElement> groupRows = groupsTableElement.findElements(By.tagName("tr"));
        for (WebElement element : groupRows) {
            List<WebElement> groupColumns = element.findElements(By.tagName("td"));
            if (!groupColumns.isEmpty()) {
                WebElement checkBoxElement = groupColumns.get(0).findElement(By.tagName(TAG_INPUT));
                WebElement groupNameElement = groupColumns.get(1);
                if (groupNameElement.findElement(By.tagName(TAG_DIV)).getText().equalsIgnoreCase(groupName))
                    // select the group name check box
                    checkBoxElement.click();
            }
        }
    }
    // End Select groups
    DriverConfig.setLogString("Mode " + mode, true);
    smallWait();
    isFormDisplayedById(DriverConfig.getDriver(), newEventWizardForm,
            demandSideManagementConfig.get(EVENT_SAVE_BTN), MEDIUM_TIMEOUT);
    if (mode.equalsIgnoreCase(demandSideManagementConfig.get(EVENT_TYPE_DRAFT))) {
        WaitUtil.waitUntil(SHORT_TIMEOUT);
        DriverConfig.setLogString("click draft button.", true);
        newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_SAVE_BTN))).click();
    } else if (mode.equalsIgnoreCase(demandSideManagementConfig.get(EVENT_TYPE_SCHEDULED))) {
        WaitUtil.waitUntil(SHORT_TIMEOUT);
        DriverConfig.setLogString("click schedule button.", true);
        newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_SCHEDULED_BTN))).click();
    } else {
        smallWait();
        DriverConfig.setLogString("click cancel button.", true);
        newEventWizardForm.findElement(By.id(demandSideManagementConfig.get(EVENT_CANCEL_BTN))).click();
    }

    return inputEventName;
}

From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java

License:Open Source License

/**
 * Gets the next program button./*from  w w  w . j  av a  2  s  . c o  m*/
 * 
 * @return the next program button
 */
private boolean getNextProgramButton() {

    DriverConfig.setLogString("click next page element.", true);
    boolean nextpageFound = false;
    WebElement paginationBottom = formElement
            .findElement(By.id(demandSideManagementConfig.get(PROGRAM_PAGINATION_BOTTOM_ELEMENT)));

    List<WebElement> pageLists = paginationBottom.findElements(By.tagName(TAG_SPAN));

    WebElement nextpage = pageLists.get(8);
    String classDisplayed = nextpage.getAttribute("class");
    logger.info(DISABLED_CLASS + " : nextpage.getAttribute(class): " + classDisplayed, true);
    nextpageFound = classDisplayed.endsWith(demandSideManagementConfig.get(DISABLED_CLASS)) ? true : false;

    if (nextpageFound == false) {
        logger.info(nextpage.isEnabled() + "next page found!");
        nextpage.click();
        DriverConfig.setLogString("next page clicked!", true);
    }
    return !nextpageFound;
}