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.

SelectAllRowsTest.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.vaadin.tests.components.table;
  2. import static com.vaadin.tests.components.table.SelectAllRows.TOTAL_NUMBER_OF_ROWS;
  3. import static org.junit.Assert.assertEquals;
  4. import java.util.List;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.Keys;
  8. import org.openqa.selenium.NoSuchElementException;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.interactions.Actions;
  11. import org.openqa.selenium.remote.DesiredCapabilities;
  12. import com.vaadin.testbench.elements.ButtonElement;
  13. import com.vaadin.testbench.elements.LabelElement;
  14. import com.vaadin.testbench.elements.TableElement;
  15. import com.vaadin.tests.tb3.MultiBrowserTest;
  16. /**
  17. * Test to see if all items of the table can be selected by selecting first row,
  18. * press shift then select last (#13008)
  19. *
  20. * @author Vaadin Ltd
  21. */
  22. public class SelectAllRowsTest extends MultiBrowserTest {
  23. @Override
  24. protected boolean requireWindowFocusForIE() {
  25. return true;
  26. }
  27. @Override
  28. public List<DesiredCapabilities> getBrowsersToTest() {
  29. return getBrowsersSupportingShiftClick();
  30. }
  31. @Test
  32. public void testAllRowsAreSelected() {
  33. openTestURL();
  34. clickFirstRow();
  35. scrollTableToBottom();
  36. clickLastRow();
  37. assertEquals(TOTAL_NUMBER_OF_ROWS, countSelectedItems());
  38. }
  39. protected void clickFirstRow() {
  40. getVisibleTableRows().get(0).click();
  41. }
  42. private void clickLastRow() {
  43. List<WebElement> rows = getVisibleTableRows();
  44. shiftClickElement(rows.get(rows.size() - 1));
  45. }
  46. protected void shiftClickElement(WebElement element) {
  47. new Actions(getDriver()).keyDown(Keys.SHIFT).click(element)
  48. .keyUp(Keys.SHIFT).perform();
  49. }
  50. private int countSelectedItems() {
  51. $(ButtonElement.class).first().click();
  52. String count = $(LabelElement.class).get(1).getText();
  53. return Integer.parseInt(count);
  54. }
  55. private TableElement getTable() {
  56. return $(TableElement.class).first();
  57. }
  58. private void scrollTableToBottom() {
  59. testBenchElement(getTable().findElement(By.className("v-scrollable")))
  60. .scroll(TOTAL_NUMBER_OF_ROWS * 30);
  61. waitUntilRowIsVisible(TOTAL_NUMBER_OF_ROWS - 1);
  62. }
  63. private void waitUntilRowIsVisible(final int row) {
  64. waitUntil(input -> {
  65. try {
  66. return getTable().getCell(row, 0) != null;
  67. } catch (NoSuchElementException e) {
  68. return false;
  69. }
  70. });
  71. }
  72. protected List<WebElement> getVisibleTableRows() {
  73. return getTable().findElements(By.cssSelector(".v-table-table tr"));
  74. }
  75. }