diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-07-14 18:50:35 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-07-15 15:40:35 +0300 |
commit | 8c91be9e2fe478038aa1bf327c9e88d5a040fc77 (patch) | |
tree | 61c212c6ac6739029da89d7d8d06eef0286e66a4 | |
parent | 44093bb40c6759e02bb7df3a27f649725e2f145d (diff) | |
download | vaadin-framework-8c91be9e2fe478038aa1bf327c9e88d5a040fc77.tar.gz vaadin-framework-8c91be9e2fe478038aa1bf327c9e88d5a040fc77.zip |
Add GridRowElement and GridCellElement (#13334)
Change-Id: Ia0fbc8e0a54089f826659969fa281ec8a79b6d87
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/GridElement.java | 65 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridKeyboardNavigationTest.java | 23 |
2 files changed, 60 insertions, 28 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridElement.java b/uitest/src/com/vaadin/tests/components/grid/GridElement.java index 091c9db1ce..5027c603d9 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridElement.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridElement.java @@ -15,6 +15,7 @@ */ package com.vaadin.tests.components.grid; +import java.util.ArrayList; import java.util.List; import org.openqa.selenium.NoSuchElementException; @@ -22,6 +23,7 @@ import org.openqa.selenium.NoSuchElementException; import com.vaadin.testbench.By; import com.vaadin.testbench.TestBenchElement; import com.vaadin.testbench.elements.AbstractComponentElement; +import com.vaadin.testbench.elements.AbstractElement; import com.vaadin.testbench.elements.ServerClass; /** @@ -33,6 +35,30 @@ import com.vaadin.testbench.elements.ServerClass; @ServerClass("com.vaadin.ui.components.grid.Grid") public class GridElement extends AbstractComponentElement { + public static class GridCellElement extends AbstractElement { + + private String ACTIVE_CLASS_NAME = "-cell-active"; + + public boolean isActive() { + return getAttribute("class").contains(ACTIVE_CLASS_NAME); + } + } + + public static class GridRowElement extends AbstractElement { + + private String ACTIVE_CLASS_NAME = "-row-active"; + private String SELECTED_CLASS_NAME = "-row-selected"; + + public boolean isActive() { + return getAttribute("class").contains(ACTIVE_CLASS_NAME); + } + + @Override + public boolean isSelected() { + return getAttribute("class").contains(SELECTED_CLASS_NAME); + } + } + /** * Scrolls Grid element so that wanted row is displayed * @@ -56,9 +82,10 @@ public class GridElement extends AbstractComponentElement { * Column index * @return Cell element with given indices. */ - public TestBenchElement getCell(int rowIndex, int colIndex) { + public GridCellElement getCell(int rowIndex, int colIndex) { scrollToRow(rowIndex); - return getSubPart("#cell[" + rowIndex + "][" + colIndex + "]"); + return getSubPart("#cell[" + rowIndex + "][" + colIndex + "]").wrap( + GridCellElement.class); } /** @@ -68,9 +95,9 @@ public class GridElement extends AbstractComponentElement { * Row index * @return Row element with given index. */ - public TestBenchElement getRow(int index) { + public GridRowElement getRow(int index) { scrollToRow(index); - return getSubPart("#cell[" + index + "]"); + return getSubPart("#cell[" + index + "]").wrap(GridRowElement.class); } /** @@ -82,8 +109,9 @@ public class GridElement extends AbstractComponentElement { * Column index * @return Header cell element with given indices. */ - public TestBenchElement getHeaderCell(int rowIndex, int colIndex) { - return getSubPart("#header[" + rowIndex + "][" + colIndex + "]"); + public GridCellElement getHeaderCell(int rowIndex, int colIndex) { + return getSubPart("#header[" + rowIndex + "][" + colIndex + "]").wrap( + GridCellElement.class); } /** @@ -95,8 +123,9 @@ public class GridElement extends AbstractComponentElement { * Column index * @return Footer cell element with given indices. */ - public TestBenchElement getFooterCell(int rowIndex, int colIndex) { - return getSubPart("#footer[" + rowIndex + "][" + colIndex + "]"); + public GridCellElement getFooterCell(int rowIndex, int colIndex) { + return getSubPart("#footer[" + rowIndex + "][" + colIndex + "]").wrap( + GridCellElement.class); } /** @@ -106,10 +135,14 @@ public class GridElement extends AbstractComponentElement { * Row index * @return Header cell elements on given row. */ - public List<TestBenchElement> getHeaderCells(int rowIndex) { - return TestBenchElement.wrapElements( + public List<GridCellElement> getHeaderCells(int rowIndex) { + List<GridCellElement> headers = new ArrayList<GridCellElement>(); + for (TestBenchElement e : TestBenchElement.wrapElements( getSubPart("#header[" + rowIndex + "]").findElements( - By.xpath("./th")), getTestBenchCommandExecutor()); + By.xpath("./th")), getCommandExecutor())) { + headers.add(e.wrap(GridCellElement.class)); + } + return headers; } /** @@ -119,10 +152,14 @@ public class GridElement extends AbstractComponentElement { * Row index * @return Header cell elements on given row. */ - public List<TestBenchElement> getFooterCells(int rowIndex) { - return TestBenchElement.wrapElements( + public List<GridCellElement> getFooterCells(int rowIndex) { + List<GridCellElement> footers = new ArrayList<GridCellElement>(); + for (TestBenchElement e : TestBenchElement.wrapElements( getSubPart("#footer[" + rowIndex + "]").findElements( - By.xpath("./td")), getTestBenchCommandExecutor()); + By.xpath("./td")), getCommandExecutor())) { + footers.add(e.wrap(GridCellElement.class)); + } + return footers; } /** diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridKeyboardNavigationTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridKeyboardNavigationTest.java index 94a25aa321..a297187b62 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridKeyboardNavigationTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridKeyboardNavigationTest.java @@ -29,13 +29,13 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { openTestURL(); GridElement grid = getGridElement(); - assertTrue("Body cell 0, 0 is not active on init.", - cellIsActive(grid, 0, 0)); + assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0) + .isActive()); grid.getCell(5, 2).click(); - assertFalse("Body cell 0, 0 was still active after clicking", - cellIsActive(grid, 0, 0)); + assertFalse("Body cell 0, 0 was still active after clicking", grid + .getCell(0, 0).isActive()); assertTrue("Body cell 5, 2 is not active after clicking", - cellIsActive(grid, 5, 2)); + grid.getCell(5, 2).isActive()); } @Test @@ -43,15 +43,10 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { openTestURL(); GridElement grid = getGridElement(); - assertTrue("Body cell 0, 0 is not active on init.", - cellIsActive(grid, 0, 0)); + assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0) + .isActive()); grid.getHeaderCell(0, 3).click(); - assertTrue("Body cell 0, 0 is not active after click on header.", - cellIsActive(grid, 0, 0)); - } - - private boolean cellIsActive(GridElement grid, int row, int col) { - return grid.getCell(row, col).getAttribute("class") - .contains("-cell-active"); + assertTrue("Body cell 0, 0 is not active after click on header.", grid + .getCell(0, 0).isActive()); } } |