List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:com.easytox.automation.steps.LabPhysicianImpl.java
@Then("^Records should be displayed on the ascending order of the selected field$") public void records_should_be_displayed_on_the_ascending_order() { try {//from w ww . j a v a 2 s . com WebElement table = driver.findElement(By.id(TABLE_LOCATOR)); List<WebElement> allRows = table.findElements(By.tagName(ROWS_LOCATOR)); int j; j = getSortColumn(allRows); String temp = allRows.get(1).findElements(By.xpath(CELLS_LOCATOR)).get(j).getText(); for (int i = 2; i < allRows.size(); i++) { if (temp.toLowerCase().contains( allRows.get(i).findElements(By.xpath(CELLS_LOCATOR)).get(j).getText().toLowerCase())) { Assert.assertTrue(true); } else { int order = temp.toLowerCase().compareTo( allRows.get(i).findElements(By.xpath(CELLS_LOCATOR)).get(j).getText().toLowerCase()); Assert.assertTrue(order <= 0); } } } catch (StaleElementReferenceException ex) { records_should_be_displayed_on_the_ascending_order(); } }
From source file:com.easytox.automation.steps.LabPhysicianImpl.java
@Then("^Records should be displayed on the descendig order of the selected field$") public void records_should_be_displayed_on_the_descending_order() { int j;// ww w . java2s . com WebElement table = driver.findElement(By.id(TABLE_LOCATOR)); List<WebElement> allRows = table.findElements(By.tagName(ROWS_LOCATOR)); j = getSortDescColumn(allRows); String temp = allRows.get(1).findElements(By.xpath(CELLS_LOCATOR)).get(j).getText(); for (int i = 2; i < allRows.size(); i++) { int order = temp.toLowerCase() .compareTo(allRows.get(i).findElements(By.xpath(CELLS_LOCATOR)).get(j).getText().toLowerCase()); Assert.assertTrue(order >= 0); } }
From source file:com.ecfeed.core.runner.java.SeleniumTestMethodInvoker.java
License:Open Source License
private boolean processSelect(String elementType, MethodParameterNode methodParameterNode, String argument) { if (!NodePropertyDefElemType.isSelect(elementType)) { return false; }//from w w w . j a va2s . com WebElement webElement = findWebElement(methodParameterNode); if (!isElementOkForInput(webElement)) { reportExceptionUnavailableElement(methodParameterNode); } String tagName = webElement.getTagName(); if (!StringHelper.isEqual(tagName, TAG_SELECT)) { return false; } List<WebElement> allOptions = webElement.findElements(By.tagName(TAG_OPTION)); for (WebElement option : allOptions) { String text = option.getText(); if (StringHelper.isEqual(text, argument)) { option.click(); return true; } } reportException("Option with text: '" + argument + "' not found.", methodParameterNode); return true; }
From source file:com.ecfeed.core.runner.java.SeleniumTestMethodInvoker.java
License:Open Source License
private WebElement findWebElementBy(String findByType, String findByValue) { checkWebDriver();//from w ww.j av a 2 s . com if (NodePropertyDefFindByType.isId(findByType)) { return fDriver.findElement(By.id(findByValue)); } if (NodePropertyDefFindByType.isClassName(findByType)) { return fDriver.findElement(By.className(findByValue)); } if (NodePropertyDefFindByType.isTagName(findByType)) { return fDriver.findElement(By.tagName(findByValue)); } if (NodePropertyDefFindByType.isTagName(findByType)) { return fDriver.findElement(By.tagName(findByValue)); } if (NodePropertyDefFindByType.isName(findByType)) { return fDriver.findElement(By.name(findByValue)); } if (NodePropertyDefFindByType.isLinkText(findByType)) { return fDriver.findElement(By.linkText(findByValue)); } if (NodePropertyDefFindByType.isPartialLinkText(findByType)) { return fDriver.findElement(By.partialLinkText(findByValue)); } if (NodePropertyDefFindByType.isCssSelector(findByType)) { return fDriver.findElement(By.cssSelector(findByValue)); } if (NodePropertyDefFindByType.isXPath(findByType)) { return fDriver.findElement(By.xpath(findByValue)); } return null; }
From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java
License:Open Source License
/** * Collect program names./*from www . j av a2s .c o m*/ * * @return the list * @see com.ecofactor.qa.automation.insite.page.DemandSideManagement#collectProgramNames() */ @Override public List<String> collectProgramNames() { logger.info("entered collect pgms"); if (formElement == null) loadForm(); List<String> pgmNames = new ArrayList<String>(); WebElement pgmListForm = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(PROGRAM_LIST_FORM))); WebElement programsListTable = retrieveElementByAttributeValueContainsForSubElement( DriverConfig.getDriver(), pgmListForm, TAG_TBODY, ATTR_ID, demandSideManagementConfig.get(PROGRAM_LIST_FORM_TABLEID), SHORT_TIMEOUT); List<WebElement> programsList = programsListTable.findElements(By.tagName(TAG_ANCHOR)); for (WebElement programElement : programsList) { pgmNames.add(programElement.getText()); logger.info("Program Name: " + programElement.getText()); logger.info("programElement.getText(): " + programElement.getText()); } logger.info("exit collect pgms"); return pgmNames; }
From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java
License:Open Source License
/** * Gets the program details.Retrieve the program data as displayed in the * screen./*from w ww . j av a 2 s .co m*/ * * @return the program details * @throws ParseException * the parse exception */ public Map<String, Object> getProgramDetails() throws ParseException { formatter = new SimpleDateFormat("MM-dd-yyyy"); DriverConfig.getDriver().switchTo().defaultContent(); smallWait(); DriverConfig.getDriver().switchTo().frame(0); WaitUtil.waitUntil(SHORT_TIMEOUT); logger.info("check if the form is displayed."); WebElement form1 = DriverConfig.getDriver().findElement(By.id(demandSideManagementConfig.get(FORM_ID))); WebElement programId = form1.findElement(By.id(demandSideManagementConfig.get(PROGRAM_ID_FIELDS_ID))); logger.info("programid: " + programId.getAttribute(ATTR_VALUE)); lsProgramId = Integer.parseInt(programId.getAttribute(ATTR_VALUE)); programPropertiesMap.put("ProgramId", programId.getAttribute(ATTR_VALUE)); WebElement propertiesFormElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(PROGRAM_TITLE_SPAN_ID))); logger.info("program name as displayed in Ui : " + propertiesFormElement.getText()); programPropertiesMap.put("ProgramName", propertiesFormElement.getText()); WebElement programProperties = DriverConfig.getDriver() .findElements(By.className(demandSideManagementConfig.get(PROGRAM_PROPERTIES_DIV_CLASS))).get(1); List<WebElement> propertyList = programProperties.findElements(By.tagName(TAG_TD)); Iterator<WebElement> iterator = propertyList.listIterator(); while (iterator.hasNext()) { programPropertiesMap.put(iterator.next().getText().replaceAll(" ", "_"), iterator.next().getText()); } return programPropertiesMap; }
From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java
License:Open Source License
/** * Click first program.Find the first LS program and click it. * // w w w . java 2s .co m * @throws ParseException * the parse exception */ public void clickFirstProgram() throws ParseException { WaitUtil.waitUntil(SHORT_TIMEOUT); DriverConfig.getDriver().switchTo().frame(0); logger.info("check if program list form is displayed."); formElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(PROGRAM_LIST_FORM))); WebElement tableElement = formElement .findElement(By.id(demandSideManagementConfig.get(PROGRAM_LIST_FORM_TABLEID))); DriverConfig.setLogString("select the first program.", true); List<WebElement> columnElements = tableElement .findElements(By.className(demandSideManagementConfig.get(PROGRAM_DIV_CLASS))); if (columnElements.size() > 0) { DriverConfig.setLogString( "Program Name: " + columnElements.get(0).findElement(By.tagName(TAG_ANCHOR)).getText(), true); columnElements.get(0).findElement(By.tagName(TAG_ANCHOR)).click(); } }
From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java
License:Open Source License
/** * Test available zipcodes are valid.//www . j a va 2 s.com * * @param programid * the programid * @param programName * the program name */ public void testAvailableZipcodesAreValid(int programid, String programName) { loadPageFrame(); DriverConfig.setLogString("select groups tab.", true); mainformElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(CREATE_EVENT_MAIN_FORM))); WebElement GroupsLink = mainformElement.findElement(By.id(demandSideManagementConfig.get(GROUPS_LINK))); GroupsLink.click(); loadPageFrame(); WaitUtil.waitUntil(5000); WebElement newFormElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(GROUP_LIST_FORM))); logger.info("check if create group link available and click it.", true); isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(CREATE_NEW_GROUP_LINK), SHORT_TIMEOUT); WebElement groupsFormElement = retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), newFormElement, TAG_ANCHOR, ATTR_ID, demandSideManagementConfig.get(CREATE_NEW_GROUP_LINK)); groupsFormElement.click(); WaitUtil.waitUntil(SHORT_TIMEOUT); isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(CREATE_GROUP_FORM), SHORT_TIMEOUT); WebElement createGroupsFormElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(CREATE_GROUP_FORM))); WaitUtil.waitUntil(5000); isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(RULE_NAME), SHORT_TIMEOUT); availableZipCodes = createGroupsFormElement.findElements(By.tagName("ul")); availableZipListElement = availableZipCodes.get(0); availableZipCodeElements = availableZipListElement.findElements(By.tagName("li")); DriverConfig.setLogString("get available zip codes from database.", true); List<Region> rules = regionDao .getAvailableZipcodes(lsProgramDao.findById(EcpCoreLSProgram.class, programid).getId()); int count = 0; DriverConfig.setLogString("check if all the available zipcodes are displayed in screen.", true); while (rules.iterator().hasNext()) { Assert.assertTrue( getListFromZipCodeElementList(availableZipCodeElements).contains(rules.get(count).getZip()), "Zipcodes are not available"); count++; } }
From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java
License:Open Source License
/** * Creates the groups.//from w w w. j a v a2 s . co m * * @return the string */ public String createGroups() { loadPageFrame(); ecpCoreLSProgram = new EcpCoreLSProgram(); lsProgramId = getProgramId(); DriverConfig.setLogString("get program data from DB.", true); ecpCoreLSProgram = (EcpCoreLSProgram) lsProgramDao.getEcpCoreLSProgram(lsProgramId).get(0); DriverConfig.setLogString("click create groups link.", true); mainformElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(CREATE_EVENT_MAIN_FORM))); WebElement GroupsLink = mainformElement.findElement(By.id(demandSideManagementConfig.get(GROUPS_LINK))); GroupsLink.click(); WaitUtil.waitUntil(SHORT_TIMEOUT); WaitUtil.waitUntil(5000); logger.info("check if create new group form is displayed."); WebElement newFormElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(GROUP_LIST_FORM))); isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(CREATE_NEW_GROUP_LINK), SHORT_TIMEOUT); WebElement groupsFormElement = retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), newFormElement, TAG_ANCHOR, ATTR_ID, demandSideManagementConfig.get(CREATE_NEW_GROUP_LINK)); groupsFormElement.click(); WaitUtil.waitUntil(SHORT_TIMEOUT); isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(CREATE_GROUP_FORM), SHORT_TIMEOUT); WebElement createGroupsFormElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(CREATE_GROUP_FORM))); WaitUtil.waitUntil(5000); isDisplayedById(DriverConfig.getDriver(), demandSideManagementConfig.get(RULE_NAME), SHORT_TIMEOUT); DriverConfig.setLogString("find the group name field and provide a name.", true); WebElement groupName = createGroupsFormElement .findElement(By.id(demandSideManagementConfig.get(RULE_NAME))); formatter = new SimpleDateFormat("MMddyyyyhhmma"); eventDate = Calendar.getInstance(); eventDate.setTimeZone(TimeZone.getTimeZone(ecpCoreLSProgram.getTimeZone())); eventDate.set(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); String group_Name = "GT".concat(formatter.format(eventDate.getTime())); DriverConfig.setLogString("enter group name.", true); groupName.sendKeys(group_Name); DriverConfig.setLogString("enter group description.", true); createGroupsFormElement.findElement(By.id(demandSideManagementConfig.get(RULE_DESC))) .sendKeys("GT" + formatter.format(eventDate.getTime())); availableZipCodes = createGroupsFormElement.findElements(By.tagName("ul")); availableZipListElement = availableZipCodes.get(0); selectedZipListElement = availableZipCodes.get(1); availableZipCodeElements = availableZipListElement.findElements(By.tagName("li")); WebElement addBtn = retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), createGroupsFormElement, TAG_BUTTON, ATTR_TITLE, "Add"); WebElement testRuleElement = retrieveElementByAttributeValueForSubElement(DriverConfig.getDriver(), createGroupsFormElement, TAG_ANCHOR, ATTR_ID, demandSideManagementConfig.get(TEST_RULE_LINK), SHORT_TIMEOUT); int locationsFound = 0; DriverConfig.setLogString("select available zipcodes.", true); while (locationsFound < 6) { createGroupsFormElement = DriverConfig.getDriver() .findElement(By.id(demandSideManagementConfig.get(CREATE_GROUP_FORM))); addBtn = retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), createGroupsFormElement, TAG_BUTTON, ATTR_TITLE, "Add"); testRuleElement = retrieveElementByAttributeValueForSubElement(DriverConfig.getDriver(), createGroupsFormElement, TAG_ANCHOR, ATTR_ID, demandSideManagementConfig.get(TEST_RULE_LINK), SHORT_TIMEOUT); locationsFound = selectOptions(createGroupsFormElement, addBtn, testRuleElement); } DriverConfig.setLogString("click save group button.", true); retrieveElementByAttributeValueForSubElement(DriverConfig.getDriver(), createGroupsFormElement, TAG_BUTTON, ATTR_ID, demandSideManagementConfig.get(SAVE_RULE_BTN), SHORT_TIMEOUT).click(); return group_Name; }
From source file:com.ecofactor.qa.automation.insite.page.DemandSideManagementImpl.java
License:Open Source License
/** * Select options./*from w w w. jav a 2 s . c om*/ * * @param createGroupsFormElement * the create groups form element * @param addBtn * the add btn * @param testRuleElement * the test rule element * @return the integer */ public Integer selectOptions(WebElement createGroupsFormElement, WebElement addBtn, WebElement testRuleElement) { availableZipCodes = createGroupsFormElement.findElements(By.tagName("ul")); availableZipListElement = availableZipCodes.get(0); selectedZipListElement = availableZipCodes.get(1); availableZipCodeElements = availableZipListElement.findElements(By.tagName("li")); WebElement listElement = null; @SuppressWarnings("rawtypes") ListIterator element = availableZipCodeElements.listIterator(); listElement = (WebElement) element.next(); logger.info("zip code" + listElement.getText()); listElement.click(); smallWait(); addBtn.click(); smallWait(); testRuleElement.click(); smallWait(); return Integer.parseInt(retrieveElementByAttributeValueByPassingElement(DriverConfig.getDriver(), createGroupsFormElement, "label", ATTR_ID, demandSideManagementConfig.get(NO_LOCATIONS_ELEMENT)) .getText().split(" ")[0].trim()); }