List of usage examples for org.openqa.selenium WebElement getText
String getText();
From source file:com.consol.citrus.selenium.actions.DropDownSelectAction.java
License:Apache License
private boolean isSameValue(WebElement option, String value) { if (StringUtils.hasText(option.getText())) { return value.equals(option.getText()); } else {//from www. ja va2 s . c o m return value.equals(option.getAttribute("value")); } }
From source file:com.consol.citrus.selenium.actions.FindElementAction.java
License:Apache License
/** * Validates found web element with expected content. * @param element/* ww w . ja v a 2 s . c om*/ * @param browser * @param context */ protected void validate(WebElement element, SeleniumBrowser browser, TestContext context) { validateElementProperty("tag-name", tagName, element.getTagName(), context); validateElementProperty("text", text, element.getText(), context); Assert.isTrue(displayed == element.isDisplayed(), String.format( "Selenium web element validation failed, " + "property 'displayed' expected '%s', but was '%s'", displayed, element.isDisplayed())); Assert.isTrue(enabled == element.isEnabled(), String.format( "Selenium web element validation failed, " + "property 'enabled' expected '%s', but was '%s'", enabled, element.isEnabled())); for (Map.Entry<String, String> attributeEntry : attributes.entrySet()) { validateElementProperty(String.format("attribute '%s'", attributeEntry.getKey()), attributeEntry.getValue(), element.getAttribute(attributeEntry.getKey()), context); } for (Map.Entry<String, String> styleEntry : styles.entrySet()) { validateElementProperty(String.format("css style '%s'", styleEntry.getKey()), styleEntry.getValue(), element.getCssValue(styleEntry.getKey()), context); } }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
public void validate(By by, String expected, ValidationRuleEnum validationRule) { String actual = null;/*from ww w .java 2 s. c om*/ WebElement foundElement = null; if (by != null) { foundElement = findElement(by); if (foundElement != null) { actual = foundElement.getText(); } } validate(actual, expected, validationRule); }
From source file:com.continuuity.test.pagetest.CreateClustertemplateTest.java
License:Apache License
@Test public void test_01_submitHadoopDistributed() throws Exception { globalDriver.get(Constants.CLUSTERTEMPLATE_CREATE_URI); ClusterTemplate clusterTemplate = EXAMPLE_READER.getClusterTemplate(Constants.CLUSTERTEMPLATE_PATH) .get("hadoop-distributed"); WebElement inputName = globalDriver.findElement(By.cssSelector("#inputName")); inputName.sendKeys(clusterTemplate.getName()); WebElement inputDescription = globalDriver.findElement(By.cssSelector("#inputDescription")); inputDescription.sendKeys(clusterTemplate.getDescription()); List<WebElement> leaseDurationInputs = globalDriver .findElements(By.cssSelector("#lease-duration-table .number-input")); for (WebElement input : leaseDurationInputs) { input.sendKeys("0"); }/*from w w w .j av a 2s .c om*/ globalDriver.findElement(By.cssSelector("#general .next-tab-button")).click(); Global.driverWait(1); Set<String> compatibleServices = clusterTemplate.getCompatibilities().getServices(); Select serviceSelect = new Select( globalDriver.findElement(By.cssSelector("#compatibility .service-select"))); WebElement addServiceBtn = globalDriver.findElement(By.cssSelector("#compatibility .add-service-btn")); for (String service : compatibleServices) { serviceSelect.selectByVisibleText(service); addServiceBtn.click(); } Set<String> compatibleHardwaretypes = clusterTemplate.getCompatibilities().getHardwaretypes(); Select hardwaretypeSelect = new Select( globalDriver.findElement(By.cssSelector("#compatibility .hardwaretype-select"))); WebElement addHardwaretypeBtn = globalDriver .findElement(By.cssSelector("#compatibility .add-hardwaretype-btn")); for (String hardwaretype : compatibleHardwaretypes) { hardwaretypeSelect.selectByVisibleText(hardwaretype); addHardwaretypeBtn.click(); } Set<String> compatibleImagetypes = clusterTemplate.getCompatibilities().getImagetypes(); Select imagetypeSelect = new Select( globalDriver.findElement(By.cssSelector("#compatibility .imagetype-select"))); WebElement addImagetypeBtn = globalDriver.findElement(By.cssSelector("#compatibility .add-imagetype-btn")); for (String imagetype : compatibleImagetypes) { imagetypeSelect.selectByVisibleText(imagetype); addImagetypeBtn.click(); } globalDriver.findElement(By.cssSelector("#compatibility .next-tab-button")).click(); Global.driverWait(1); new Select(globalDriver.findElement(By.cssSelector("#defaults .provider-select"))) .selectByVisibleText(clusterTemplate.getClusterDefaults().getProvider()); Select defaulthardwaretype = new Select( globalDriver.findElement(By.cssSelector("#defaults .hardwaretype-select"))); Select defaultimagetype = new Select( globalDriver.findElement(By.cssSelector("#defaults .imagetype-select"))); List<WebElement> defaultHardwareOptions = defaulthardwaretype.getOptions(); List<WebElement> defaultImageOptions = defaultimagetype.getOptions(); Set<String> defaultHardwareItems = Sets.newHashSet(); for (WebElement item : defaultHardwareOptions) { if (item.getText().length() != 0) { defaultHardwareItems.add(item.getText()); } } Set<String> defaultImageItems = Sets.newHashSet(); for (WebElement item : defaultImageOptions) { if (item.getText().length() != 0) { defaultImageItems.add(item.getText()); } } defaulthardwaretype.selectByVisibleText(clusterTemplate.getClusterDefaults().getHardwaretype()); defaultimagetype.selectByVisibleText(clusterTemplate.getClusterDefaults().getImagetype()); globalDriver.findElement(By.cssSelector("#inputDnsSuffix")) .sendKeys(clusterTemplate.getClusterDefaults().getDnsSuffix().toString()); globalDriver.findElement(By.cssSelector("#inputConfig")) .sendKeys(clusterTemplate.getClusterDefaults().getConfig().toString()); Set<String> defaultServices = clusterTemplate.getClusterDefaults().getServices(); Select defaultServiceSelect = new Select( globalDriver.findElement(By.cssSelector("#defaults .service-select"))); List<WebElement> defaultServiceSelectOptions = defaultServiceSelect.getOptions(); Set<String> defaultServiceSelectItems = Sets.newHashSet(); for (WebElement item : defaultServiceSelectOptions) { if (item.getText().length() != 0) { defaultServiceSelectItems.add(item.getText()); } } assertEquals(compatibleHardwaretypes, defaultHardwareItems); assertEquals(compatibleImagetypes, defaultImageItems); assertEquals(defaultServices, defaultServiceSelectItems); WebElement addServicebtn = globalDriver.findElement(By.cssSelector("#defaults .add-service-btn")); for (String service : defaultServices) { defaultServiceSelect.selectByVisibleText(service); addServicebtn.click(); } globalDriver.findElement(By.cssSelector("#defaults .next-tab-button")).click(); Global.driverWait(1); globalDriver.findElement(By.cssSelector(".add-must-coexist-group")).click(); Global.driverWait(1); Set<String> mustcoexistgroup1 = clusterTemplate.getConstraints().getLayoutConstraint() .getServicesThatMustCoexist().iterator().next(); Select mustCoExistSelect = new Select( globalDriver.findElement(By.cssSelector("#must-coexist-modal .must-coexist-select"))); addServiceBtn = globalDriver.findElement(By.cssSelector("#must-coexist-modal .add-service-btn")); for (WebElement close : globalDriver.findElements(By.cssSelector("#cant-coexist-modal .service-delete"))) { close.click(); } for (String serviceEntry : mustcoexistgroup1) { mustCoExistSelect.selectByVisibleText(serviceEntry); addServiceBtn.click(); } globalDriver.findElement(By.cssSelector("#must-coexist-modal .add-group-btn")).click(); Global.driverWait(1); Set<Set<String>> cantcoexistgroups = clusterTemplate.getConstraints().getLayoutConstraint() .getServicesThatMustNotCoexist(); for (Set<String> cantcoexistentry : cantcoexistgroups) { globalDriver.findElement(By.cssSelector(".add-cant-coexist-group")).click(); Global.driverWait(1); for (WebElement close : globalDriver .findElements(By.cssSelector("#cant-coexist-modal .service-delete"))) { close.click(); } Select cantcoexistSelect = new Select( globalDriver.findElement(By.cssSelector("#cant-coexist-modal .cant-coexist-select"))); addServiceBtn = globalDriver.findElement(By.cssSelector("#cant-coexist-modal .add-service-btn")); for (String serviceEntry : cantcoexistentry) { cantcoexistSelect.selectByVisibleText(serviceEntry); addServiceBtn.click(); } globalDriver.findElement(By.cssSelector("#cant-coexist-modal .add-group-btn")).click(); Global.driverWait(1); } Map<String, ServiceConstraint> serviceConstraints = clusterTemplate.getConstraints() .getServiceConstraints(); Select serviceNameSelect = new Select( globalDriver.findElement(By.cssSelector("#service-constraint-modal .service-select"))); Select serviceHardwaretypeSelect = new Select( globalDriver.findElement(By.cssSelector("#service-constraint-modal .hardwaretype-select"))); addHardwaretypeBtn = globalDriver .findElement(By.cssSelector("#service-constraint-modal .add-hardwaretype-btn")); Select serviceImagetypeSelect = new Select( globalDriver.findElement(By.cssSelector("#service-constraint-modal .imagetype-select"))); addImagetypeBtn = globalDriver.findElement(By.cssSelector("#service-constraint-modal .add-imagetype-btn")); WebElement minConstraint = globalDriver .findElement(By.cssSelector("#service-constraint-modal .constraint-min")); WebElement maxConstraint = globalDriver .findElement(By.cssSelector("#service-constraint-modal .constraint-max")); WebElement addServiceConstraintBtn = globalDriver .findElement(By.cssSelector(".add-service-constraint-btn")); WebElement addServiceConstraintModal = globalDriver .findElement(By.cssSelector(".add-serviceconstraint-modal")); for (Map.Entry<String, ServiceConstraint> entry : serviceConstraints.entrySet()) { addServiceConstraintModal.click(); Global.driverWait(1); minConstraint.clear(); maxConstraint.clear(); String key = entry.getKey(); ServiceConstraint constraint = entry.getValue(); serviceNameSelect.selectByVisibleText(key); if (constraint.getRequiredHardwareTypes() != null) { for (String hardwaretype : constraint.getRequiredHardwareTypes()) { serviceHardwaretypeSelect.selectByVisibleText(hardwaretype); addHardwaretypeBtn.click(); } } if (constraint.getRequiredImageTypes() != null) { for (String imagetype : constraint.getRequiredImageTypes()) { serviceImagetypeSelect.selectByVisibleText(imagetype); addImagetypeBtn.click(); } } minConstraint.sendKeys(String.valueOf(constraint.getMinCount())); maxConstraint.sendKeys(String.valueOf(constraint.getMaxCount())); addServiceConstraintBtn.click(); Global.driverWait(1); } globalDriver.findElement(By.cssSelector("#create-clustertemplate-form")).submit(); Global.driverWait(1); assertEquals(Constants.CLUSTERTEMPLATES_URL, globalDriver.getCurrentUrl()); }
From source file:com.continuuity.test.pagetest.IndexTest.java
License:Apache License
@Test public void test_08_catalogPanel() throws Exception { // Verify panel title WebElement servicesPanel = TEST_UTIL.getPanelHead(CLUSTERTEMPLATE); assertEquals("Catalog", servicesPanel.getText()); assertEquals(Constants.INDEX_URL + Constants.CLUSTERTEMPLATE_HREF, servicesPanel.getAttribute(HREF)); Map<String, ClusterTemplate> nameServices = EXAMPLE_READER .getClusterTemplate(Constants.CLUSTERTEMPLATE_PATH); // Verify the table in the panel WebElement table = TEST_UTIL.getTable(Constants.CLUSTERTEMPLATE_TABLE); assertEquals("The number of rows is not equal to the number of providers in the examples.", nameServices.size(), TEST_UTIL.getRowCount(table)); for (int row = 0; row < TEST_UTIL.getRowCount(table); row++) { String name = TEST_UTIL.getTd(table, row, 0); assertTrue("Name is not in the examples.", nameServices.containsKey(name)); assertEquals("Description is not equal.", nameServices.get(name).getDescription(), TEST_UTIL.getTd(table, row, 1)); }// ww w. ja v a 2 s. com }
From source file:com.conwet.silbops.EndToEndHTMLIT.java
License:Open Source License
@Test public void shouldCloseConnection() { System.out.println("start close connection test..."); shouldOpenConnection();// w w w .j a v a2 s . c o m cleanTextArea("messageTextArea"); System.out.println("selecting endpoints to close..."); // iterates through options and close endPoints WebElement disconnect = browser.findElement(By.id("disconnectButton")); List<String> endpointList = new ArrayList<>(); for (WebElement option : browser.findElements(By.cssSelector("option[id*=\"#\"]"))) { System.out.println("disconnecting " + option.getText()); endpointList.add(option.getAttribute("id")); disconnect.click(); } System.out.println("done."); System.out.print("waiting disconnect message..."); waitMessage("messageTextArea", "disconnected"); String msg = getTextAreaValue("messageTextArea"); for (String endpoint : endpointList) { assertThat(msg).contains(endpoint); } System.out.println("done."); System.out.println("end close connection test"); }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private String getFileName() { String fileName = null;/* ww w. ja v a 2 s. co m*/ try { WebElement fileNameElement = longWait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector( "body > div > div > div.transfer > div > div.scrollable.transfer__contents > div.scrollable__content > ul > li > span.filelist__name"))); fileName = fileNameElement.getText(); } catch (Exception e) { log.error(e); } return fileName; }
From source file:com.daarons.transfer.UploadTask.java
License:Apache License
private int getUploadTime(WebDriverWait wait) { WebElement timeLeftElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector( "body > div > div > div.transfer.transfer--half-panel > div > div.transfer__contents > p:nth-child(4)"))); // then get the text in the time_left element & calculate the time to upload String timeLeft = timeLeftElement.getText(); int until;/*from www. j a v a2s . com*/ if (timeLeft.matches("(.*)hour(.*)") || timeLeft.matches("(.*)hours(.*)")) { //hours timeLeft = timeLeft.replaceAll("\\D+", ""); if (timeLeft.isEmpty()) { until = 60; } else { until = new Integer(timeLeft) * 60; } } else if (timeLeft.matches("(.*)under a minute(.*)")) { // < 1min until = 1; } else { //everything else but mostly 'minutes' timeLeft = timeLeft.replaceAll("\\D+", ""); try { until = new Integer(timeLeft); } catch (NumberFormatException ex) { log.error("The upload time did not contains integers", ex); until = 1; } } return until; }
From source file:com.day.cq.social.comments.CloudServiceMTIT.java
@Test public void testConfigureTIFOnPublish() throws InterruptedException { browseTo(getURL(cloudServiceMTPage), true); WebElement tranIntegration = driver.findElement(By.cssSelector("div.product.machine-translation a")); tranIntegration.click();/* ww w . j a v a2 s . c o m*/ assertTrue("Unable to find configuration button", isElementPresent(By.cssSelector("#machine-translation-more"))); WebElement defaultConfig = driver .findElement(By.linkText("Default configuration (Translation Integration configuration)")); defaultConfig.click(); assertTrue("Unable to find go to translation integration button", isElementPresent(By.linkText("Go to Translation Integration Framework"))); assertTrue("Unable to find edit button", isElementPresent(By.id("cq-gen13"))); WebElement edit = driver.findElement(By.id("cq-gen14")); assertEquals("Edit", edit.getText()); edit.click(); assertTrue("Unable to find edit component", isElementPresent(By.id("cq-gen40"))); assertEquals("Edit Component", driver.findElement(By.id("cq-gen40")).getText()); assertEquals("Machine Translation Configuration", driver.findElement(By.id("ext-comp-1010")).getText()); assertEquals("Go to Translation Integration Framework", driver.findElement(By.cssSelector("#ext-comp-1014 a")).getText()); assertTrue("Unable to find category", isElementPresent(By.id("ext-comp-1024"))); }
From source file:com.denimgroup.threadfix.selenium.pages.ApiKeysIndexPage.java
License:Mozilla Public License
public int getIndex(String roleName) { int i = -1;// www.j av a 2 s. c om for (WebElement note : notes) { i++; String text = note.getText().trim(); if (text.equals(roleName.trim())) { return i; } } return -1; }