You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridEditorCheckBoxTest.java 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import static org.hamcrest.number.IsCloseTo.closeTo;
  4. import static org.junit.Assert.assertEquals;
  5. import java.util.List;
  6. import org.junit.Test;
  7. import org.openqa.selenium.By;
  8. import org.openqa.selenium.WebElement;
  9. import com.vaadin.testbench.elements.GridElement;
  10. import com.vaadin.tests.tb3.MultiBrowserTest;
  11. public class GridEditorCheckBoxTest extends MultiBrowserTest {
  12. @Test
  13. public void testPositions() {
  14. openTestURL();
  15. GridElement grid = $(GridElement.class).first();
  16. // open editor for second row
  17. grid.getCell(1, 1).doubleClick();
  18. waitForElementPresent(By.className("v-grid-editor"));
  19. // regular row cells
  20. List<WebElement> rowCells = grid.getRow(0)
  21. .findElements(By.className("v-grid-cell"));
  22. // editor cells are divided in two groups, first one for frozen columns,
  23. // second one for the rest
  24. List<WebElement> editorCellGroups = grid
  25. .findElements(By.className("v-grid-editor-cells"));
  26. int column = 0;
  27. for (WebElement editorCellGroup : editorCellGroups) {
  28. // find the actual editor cells (no shared class name)
  29. List<WebElement> editorCells = editorCellGroup
  30. .findElements(By.xpath("./child::*"));
  31. for (WebElement editorCell : editorCells) {
  32. // find the margin within the editor row
  33. List<WebElement> checkBoxElements = editorCell
  34. .findElements(By.className("v-checkbox"));
  35. WebElement editorInput;
  36. if (checkBoxElements.isEmpty()) {
  37. // use the actual input element for position check
  38. editorInput = editorCell.findElement(By.tagName("input"));
  39. } else {
  40. // v-checkbox positions a fake input element
  41. editorInput = checkBoxElements.get(0);
  42. }
  43. int editorMargin = editorInput.getLocation().getX()
  44. - editorCell.getLocation().getX();
  45. // find the margin within the regular row
  46. WebElement rowCell = rowCells.get(column);
  47. int comparisonMargin;
  48. if (column == 1 || column == 2) {
  49. // these columns have text content on regular rows, margin
  50. // is created with padding
  51. String padding = rowCell.getCssValue("padding-left");
  52. comparisonMargin = Integer.valueOf(
  53. padding.substring(0, padding.indexOf("px")));
  54. } else {
  55. WebElement rowContent = rowCell
  56. .findElement(By.tagName("input"));
  57. comparisonMargin = rowContent.getLocation().getX()
  58. - rowCell.getLocation().getX();
  59. }
  60. // ensure that the editor input position matches the regular row
  61. // content position
  62. assertThat(
  63. "Unexpected input location for column " + column
  64. + " editor",
  65. (double) editorMargin, closeTo(comparisonMargin, 1d));
  66. ++column;
  67. }
  68. }
  69. assertEquals("Unexpect amount of checked columns,", 5, column);
  70. }
  71. }