List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
From source file:com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.java
License:Open Source License
/** * Selects the sheet with the given name. Only visible sheets can be * selected./*from w ww . j a v a 2s. c o m*/ * * @param sheetName * Name of sheet to select */ public void selectSheet(String sheetName) { WebElement tabContainer = findElement(By.className("sheet-tabsheet-container")); List<WebElement> tabs = tabContainer.findElements(By.xpath(".//*")); for (WebElement tab : tabs) { if (tab.getText().equals(sheetName)) { scrollSheetVisible(tab); tab.click(); break; } } }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
@Test public void tableWithData() { doLogin();//from ww w . j av a 2 s .c o m WebElement table = findElement(By.className("v-grid")); List<WebElement> headers = table.findElements(By.tagName("th")); Assert.assertEquals(6, headers.size()); hasText(headers.get(0), "Id"); hasText(headers.get(1), "Product Name"); hasText(headers.get(2), "Price"); hasText(headers.get(3), "Availability"); hasText(headers.get(4), "Stock Count"); hasText(headers.get(5), "Category"); List<WebElement> rows = getRows(); Collection<Product> products = dataService.getAllProducts(); int size = rows.size(); Assert.assertTrue(size > 0); int i = 0; for (Iterator<Product> iterator = products.iterator(); iterator.hasNext() && i < size;) { Product product = iterator.next(); assertRowData(rows.get(i), product); i++; } }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
@Test public void selectRow() { doLogin();/*from w w w. ja va 2 s. co m*/ int index = 0; List<WebElement> rows = getRows(); rows.get(index).findElement(By.tagName("td")).click(); WebElement form = findElement(By.className("product-form")); List<WebElement> buttons = form.findElements(By.className("v-button")); Assert.assertEquals(3, buttons.size()); List<WebElement> fields = form.findElements(By.className("v-textfield")); Assert.assertTrue(fields.size() >= 3); Optional<Product> selectedProduct = dataService.getAllProducts().stream().skip(index).findFirst(); Product product = selectedProduct.get(); checkTextField(fields.get(0), "Product name", product.getProductName(), true); checkTextField(fields.get(1), "Price", product.getPrice().toPlainString(), false); checkTextField(fields.get(2), "In Stock", String.valueOf(product.getStockCount()), true); WebElement combo = form.findElement(By.className("v-filterselect-input")); checkTextField(combo, "Availability", product.getAvailability().toString(), true); checkCategories(form, product); }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
@Test public void updateProduct() { doLogin();// ww w .j ava2 s . com int index = 1; List<WebElement> rows = getRows(); rows.get(index).findElement(By.tagName("td")).click(); WebElement form = findElement(By.className("product-form")); List<WebElement> fields = form.findElements(By.className("v-textfield")); WebElement productName = fields.get(0); productName.clear(); productName.sendKeys("Updated Product Name"); form.findElement(By.className("primary")).click(); // fixme This check fails because of some PhantomJS issues. // disabled, because it is not life-critical // checkFormLocation(form); rows = getRows(); WebElement firstNameColumn = rows.get(index).findElements(By.tagName("td")).get(1); hasText(firstNameColumn, "Updated Product Name"); }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
@Test public void validationError() { doLogin();// w w w . j a va2 s . co m int index = 3; List<WebElement> rows = getRows(); rows.get(index).findElement(By.tagName("td")).click(); WebElement form = findElement(By.className("product-form")); Assert.assertFalse(isElementPresent(By.className("v-errorindicator"))); Assert.assertFalse(isElementPresent(By.className("v-textfield-error"))); List<WebElement> fields = form.findElements(By.className("v-textfield")); WebElement productName = fields.get(0); productName.clear(); productName.sendKeys("a"); productName.sendKeys(Keys.TAB); Assert.assertTrue(isElementPresent(By.className("v-errorindicator"))); Assert.assertTrue(isElementPresent(By.className("v-textfield-error"))); }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
private void checkCategories(WebElement form, Product product) { WebElement categories = form.findElement(By.className("v-select-optiongroup")); WebElement captionElement = categories.findElement(By.xpath("..")).findElement(By.className("v-caption")); Assert.assertEquals("Categories", captionElement.getText()); List<WebElement> checkboxes = categories.findElements(By.className("v-checkbox")); Set<String> cats = checkboxes.stream().map(WebElement::getText).collect(Collectors.toSet()); Set<String> allCats = dataService.getAllCategories().stream().map(Category::getName) .collect(Collectors.toSet()); Assert.assertEquals(allCats, cats);/*from w w w.jav a2s . c o m*/ Map<String, Category> productCategories = product.getCategory().stream() .collect(Collectors.toMap(Category::getName, Function.identity())); checkboxes.forEach(checkbox -> checkCategory(checkbox, productCategories)); }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
private List<WebElement> getRows() { WebElement table = findElement(By.className("v-grid")); List<WebElement> bodies = table.findElements(By.tagName("tbody")); List<WebElement> rows = bodies.get(bodies.size() - 1).findElements(By.tagName("tr")); return rows;//from w w w .ja v a2 s.c om }
From source file:com.vaadin.framework7.samples.SpringCrudIT.java
License:Apache License
private void assertRowData(WebElement row, Product product) { List<WebElement> columns = row.findElements(By.tagName("td")); Assert.assertEquals(6, columns.size()); hasText(columns.get(0), String.valueOf(product.getId())); hasText(columns.get(1), product.getProductName()); hasText(columns.get(2), String.valueOf(product.getPrice())); hasText(columns.get(3), product.getAvailability().toString()); int stockCount = product.getStockCount(); if (stockCount == 0) { hasText(columns.get(4), ">-<"); } else {//from w w w .j a v a 2s . c o m hasText(columns.get(4), String.valueOf(stockCount)); } product.getCategory().forEach(cat -> hasText(columns.get(5), cat.getName())); }
From source file:com.vaadin.framework8.samples.SpringCrudIT.java
License:Apache License
@Test public void selectRow() { doLogin();//w w w.j a va 2 s . c om int index = 0; List<WebElement> rows = getRows(); rows.get(index).findElement(By.tagName("td")).click(); WebElement form = findElement(By.className("product-form")); List<WebElement> buttons = form.findElements(By.className("v-button")); Assert.assertEquals(4, buttons.size()); List<WebElement> fields = form.findElements(By.className("v-textfield")); Assert.assertTrue(fields.size() >= 3); Optional<Product> selectedProduct = dataService.getAllProducts().stream().skip(index).findFirst(); Product product = selectedProduct.get(); checkTextField(fields.get(0), "Product name", product.getProductName(), true, true); checkTextField(fields.get(1), "Price", product.getPrice().toPlainString(), false, false); checkTextField(fields.get(2), "In Stock", String.valueOf(product.getStockCount()), true, false); WebElement combo = form.findElement(By.className("v-filterselect-input")); checkTextField(combo, "Availability", product.getAvailability().toString(), true, true); checkCategories(form, product); }
From source file:com.vaadin.framework8.samples.SpringCrudIT.java
License:Apache License
@Test public void updateContact() { doLogin();//from w ww.ja va2 s. c o m int index = 1; List<WebElement> rows = getRows(); rows.get(index).findElement(By.tagName("td")).click(); WebElement form = findElement(By.className("product-form")); List<WebElement> fields = form.findElements(By.className("v-textfield")); WebElement productName = fields.get(0); productName.clear(); productName.sendKeys("Updated Product Name"); form.findElement(By.className("primary")).click(); // This check does not work under PhantomJS // checkFormLocation(form); rows = getRows(); WebElement firstNameColumn = rows.get(index).findElements(By.tagName("td")).get(1); hasText(firstNameColumn, "Updated Product Name"); }