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.

GridUITest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.vaadin.tests.elements.grid;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. import org.openqa.selenium.NoSuchElementException;
  5. import com.vaadin.testbench.elements.GridElement;
  6. import com.vaadin.testbench.elements.GridElement.GridRowElement;
  7. import com.vaadin.tests.tb3.MultiBrowserTest;
  8. public class GridUITest extends MultiBrowserTest {
  9. @Test
  10. public void testRowCount() {
  11. openTestURL("rowCount=0");
  12. Assert.assertEquals(0, getRowCount());
  13. openTestURL("rowCount=1&restartApplication");
  14. Assert.assertEquals(1, getRowCount());
  15. openTestURL("rowCount=10&restartApplication");
  16. Assert.assertEquals(10, getRowCount());
  17. openTestURL("rowCount=1000&restartApplication");
  18. Assert.assertEquals(1000, getRowCount());
  19. }
  20. private long getRowCount() {
  21. return $(GridElement.class).first().getRowCount();
  22. }
  23. private Iterable<GridRowElement> getRows() {
  24. return $(GridElement.class).first().getRows();
  25. }
  26. @Test
  27. public void testGetRows() {
  28. openTestURL("rowCount=0");
  29. Assert.assertEquals(0, checkRows());
  30. openTestURL("rowCount=1&restartApplication");
  31. Assert.assertEquals(1, checkRows());
  32. openTestURL("rowCount=10&restartApplication");
  33. Assert.assertEquals(10, checkRows());
  34. openTestURL("rowCount=100&restartApplication");
  35. Assert.assertEquals(100, checkRows());
  36. }
  37. @Test
  38. public void testGetHeadersByCaptionFirstRowFirstColumn() {
  39. openTestURL("rowCount=10&restartApplication");
  40. GridElement grid = $(GridElement.class).first();
  41. grid.getHeaderCellByCaption("foo");
  42. }
  43. @Test
  44. public void testGetHeadersByCaptionFirstRowNotFirstColumn() {
  45. openTestURL("rowCount=10&restartApplication");
  46. GridElement grid = $(GridElement.class).first();
  47. grid.getHeaderCellByCaption("bar");
  48. }
  49. @Test(expected = NoSuchElementException.class)
  50. public void testGetHeadersByCaptionNoHeader() {
  51. openTestURL("rowCount=10&restartApplication");
  52. GridElement grid = $(GridElement.class).first();
  53. grid.getHeaderCellByCaption("not existing caption");
  54. }
  55. @Test(expected = NoSuchElementException.class)
  56. public void testGetHeadersByCaptionByIndexNoHeader() {
  57. openTestURL("rowCount=10&restartApplication");
  58. GridElement grid = $(GridElement.class).first();
  59. grid.getHeaderCellByCaption(0, "not existing caption");
  60. }
  61. @Test
  62. public void testGetHeadersByCaptionNotFirstRow() {
  63. openTestURL("rowCount=10&restartApplication");
  64. GridElement grid = $(GridElement.class).first();
  65. grid.getHeaderCellByCaption("extra row");
  66. }
  67. @Test
  68. public void testGetHeadersByCaptionByIndexNotFirstRow() {
  69. openTestURL("rowCount=10&restartApplication");
  70. GridElement grid = $(GridElement.class).first();
  71. grid.getHeaderCellByCaption(1, "extra row");
  72. }
  73. private int checkRows() {
  74. int rowCount = 0;
  75. for (final GridRowElement row : getRows()) {
  76. Assert.assertEquals("foo " + rowCount, row.getCell(0).getText());
  77. Assert.assertEquals("bar " + rowCount, row.getCell(1).getText());
  78. rowCount++;
  79. }
  80. return rowCount;
  81. }
  82. }