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.

GridComponentsTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.vaadin.tests.components.grid;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. import org.openqa.selenium.WebElement;
  5. import com.vaadin.testbench.By;
  6. import com.vaadin.testbench.elements.ButtonElement;
  7. import com.vaadin.testbench.elements.GridElement;
  8. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  9. import com.vaadin.testbench.elements.GridElement.GridRowElement;
  10. import com.vaadin.testbench.elements.NotificationElement;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. public class GridComponentsTest extends MultiBrowserTest {
  13. @Test
  14. public void testReuseTextFieldOnScroll() {
  15. openTestURL();
  16. GridElement grid = $(GridElement.class).first();
  17. editTextFieldInCell(grid, 0, 1);
  18. // Scroll out of view port
  19. grid.getRow(900);
  20. // Scroll back
  21. grid.getRow(0);
  22. WebElement textField = grid.getCell(0, 1)
  23. .findElement(By.tagName("input"));
  24. Assert.assertEquals("TextField value was reset", "Foo",
  25. textField.getAttribute("value"));
  26. Assert.assertTrue("No mention in the log",
  27. logContainsText("1. Reusing old text field for: Row 0"));
  28. }
  29. @Test
  30. public void testReuseTextFieldOnSelect() {
  31. openTestURL();
  32. GridElement grid = $(GridElement.class).first();
  33. editTextFieldInCell(grid, 1, 1);
  34. // Select row
  35. grid.getCell(1, 1).click(1, 1);
  36. WebElement textField = grid.getCell(1, 1)
  37. .findElement(By.tagName("input"));
  38. Assert.assertEquals("TextField value was reset", "Foo",
  39. textField.getAttribute("value"));
  40. Assert.assertTrue("No mention in the log",
  41. logContainsText("1. Reusing old text field for: Row 1"));
  42. }
  43. @Test
  44. public void testReplaceData() {
  45. openTestURL();
  46. assertRowExists(5, "Row 5");
  47. $(ButtonElement.class).caption("Reset data").first().click();
  48. assertRowExists(5, "Row 1005");
  49. }
  50. @Test
  51. public void testTextFieldSize() {
  52. openTestURL();
  53. GridCellElement cell = $(GridElement.class).first().getCell(0, 1);
  54. int cellWidth = cell.getSize().getWidth();
  55. int fieldWidth = cell.findElement(By.tagName("input")).getSize()
  56. .getWidth();
  57. // padding left and right, +1 to fix sub pixel issues
  58. int padding = 18 * 2 + 1;
  59. int extraSpace = Math.abs(fieldWidth - cellWidth);
  60. Assert.assertTrue("Too much unused space in cell. Expected: " + padding
  61. + " Actual: " + extraSpace, extraSpace <= padding);
  62. }
  63. private void editTextFieldInCell(GridElement grid, int row, int col) {
  64. WebElement textField = grid.getCell(row, col)
  65. .findElement(By.tagName("input"));
  66. textField.clear();
  67. textField.sendKeys("Foo");
  68. }
  69. @Test
  70. public void testRow5() {
  71. openTestURL();
  72. assertRowExists(5, "Row 5");
  73. }
  74. @Test
  75. public void testRow0() {
  76. openTestURL();
  77. assertRowExists(0, "Row 0");
  78. Assert.assertEquals("Grid row height is not what it should be", 40,
  79. $(GridElement.class).first().getRow(0).getSize().getHeight());
  80. }
  81. @Test
  82. public void testRow999() {
  83. openTestURL();
  84. assertRowExists(999, "Row 999");
  85. }
  86. @Test
  87. public void testHeaders() {
  88. openTestURL();
  89. GridElement grid = $(GridElement.class).first();
  90. Assert.assertEquals("Label", grid.getHeaderCell(0, 0).getText());
  91. Assert.assertEquals("Other Components",
  92. grid.getHeaderCell(0, 1).getText());
  93. }
  94. private void assertRowExists(int i, String string) {
  95. GridRowElement row = $(GridElement.class).first().getRow(i);
  96. Assert.assertEquals("Label text did not match", string,
  97. row.getCell(0).getText());
  98. row.findElement(By.id(string.replace(' ', '_').toLowerCase())).click();
  99. // IE 11 is slow, need to wait for the notification.
  100. waitUntil(driver -> isElementPresent(NotificationElement.class), 10);
  101. Assert.assertTrue("Notification should contain given text",
  102. $(NotificationElement.class).first().getText()
  103. .contains(string));
  104. }
  105. }