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.

TableWithContainerRequiringEqualsForItemIdTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.vaadin.tests.components.table;
  2. import static org.junit.Assert.assertEquals;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import org.openqa.selenium.WebElement;
  6. import com.vaadin.testbench.By;
  7. import com.vaadin.testbench.elements.TableElement;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. /**
  10. * Test for a Table with a customised BeanItemContainer.
  11. *
  12. * @author Vaadin Ltd
  13. */
  14. public class TableWithContainerRequiringEqualsForItemIdTest
  15. extends MultiBrowserTest {
  16. @Test
  17. public void testSorting() {
  18. openTestURL();
  19. TableElement table = $(TableElement.class).first();
  20. List<WebElement> rows = table.findElement(By.className("v-table-body"))
  21. .findElements(By.tagName("tr"));
  22. assertEquals("unexpect amount of rows", 46, rows.size());
  23. // click the button on the first visible row
  24. clickButton(table, 0, 3, "1. Button Button999 clicked");
  25. // click the button on the last visible row
  26. clickButton(table, 14, 3, "2. Button Button985 clicked");
  27. clickTableHeaderToSort(table);
  28. // check the first cell of the new first visible row
  29. checkFirstCell(table, "0");
  30. // click the button on the first visible row
  31. clickButton(table, 0, 3, "3. Button Button0 clicked");
  32. // sort by the first column (descending)
  33. clickTableHeaderToSort(table);
  34. // check the first cell of the new first visible row
  35. checkFirstCell(table, "999");
  36. // click the button on the first visible row
  37. clickButton(table, 0, 3, "4. Button Button999 clicked");
  38. }
  39. private void checkFirstCell(TableElement table, String expected) {
  40. assertEquals("unexpected contents", expected,
  41. table.getCell(0, 0).getText());
  42. }
  43. private void clickTableHeaderToSort(TableElement table) {
  44. table.findElement(By.className("v-table-header"))
  45. .findElement(By.tagName("tr"))
  46. .findElement(By.className("v-table-caption-container")).click();
  47. }
  48. private void clickButton(TableElement table, int row, int column,
  49. String expectedLog) {
  50. table.getCell(row, column).findElement(By.className("v-button"))
  51. .click();
  52. // check the new log row
  53. assertEquals("unexpected log row", expectedLog,
  54. findElement(By.id("Log_row_0")).getText());
  55. }
  56. }