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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.table;
  17. import static com.vaadin.tests.components.table.SelectAllRows.TOTAL_NUMBER_OF_ROWS;
  18. import static org.junit.Assert.assertEquals;
  19. import java.util.List;
  20. import org.junit.Test;
  21. import org.openqa.selenium.By;
  22. import org.openqa.selenium.Keys;
  23. import org.openqa.selenium.NoSuchElementException;
  24. import org.openqa.selenium.WebDriver;
  25. import org.openqa.selenium.WebElement;
  26. import org.openqa.selenium.interactions.Actions;
  27. import org.openqa.selenium.remote.DesiredCapabilities;
  28. import org.openqa.selenium.support.ui.ExpectedCondition;
  29. import com.vaadin.testbench.elements.ButtonElement;
  30. import com.vaadin.testbench.elements.LabelElement;
  31. import com.vaadin.testbench.elements.TableElement;
  32. import com.vaadin.tests.tb3.MultiBrowserTest;
  33. /**
  34. * Test to see if all items of the table can be selected by selecting first row,
  35. * press shift then select last (#13008)
  36. *
  37. * @author Vaadin Ltd
  38. */
  39. public class SelectAllRowsTest extends MultiBrowserTest {
  40. @Override
  41. protected boolean requireWindowFocusForIE() {
  42. return true;
  43. }
  44. @Override
  45. public List<DesiredCapabilities> getBrowsersToTest() {
  46. return getBrowsersSupportingShiftClick();
  47. }
  48. @Test
  49. public void testAllRowsAreSelected() {
  50. openTestURL();
  51. clickFirstRow();
  52. scrollTableToBottom();
  53. clickLastRow();
  54. assertEquals(TOTAL_NUMBER_OF_ROWS, countSelectedItems());
  55. }
  56. protected void clickFirstRow() {
  57. getVisibleTableRows().get(0).click();
  58. }
  59. private void clickLastRow() {
  60. List<WebElement> rows = getVisibleTableRows();
  61. shiftClickElement(rows.get(rows.size() - 1));
  62. }
  63. protected void shiftClickElement(WebElement element) {
  64. new Actions(getDriver()).keyDown(Keys.SHIFT).click(element)
  65. .keyUp(Keys.SHIFT).perform();
  66. }
  67. private int countSelectedItems() {
  68. $(ButtonElement.class).first().click();
  69. String count = $(LabelElement.class).get(1).getText();
  70. return Integer.parseInt(count);
  71. }
  72. private TableElement getTable() {
  73. return $(TableElement.class).first();
  74. }
  75. private void scrollTableToBottom() {
  76. testBenchElement(getTable().findElement(By.className("v-scrollable")))
  77. .scroll(TOTAL_NUMBER_OF_ROWS * 30);
  78. waitUntilRowIsVisible(TOTAL_NUMBER_OF_ROWS - 1);
  79. }
  80. private void waitUntilRowIsVisible(final int row) {
  81. waitUntil(new ExpectedCondition<Object>() {
  82. @Override
  83. public Object apply(WebDriver input) {
  84. try {
  85. return getTable().getCell(row, 0) != null;
  86. } catch (NoSuchElementException e) {
  87. return false;
  88. }
  89. }
  90. });
  91. }
  92. protected List<WebElement> getVisibleTableRows() {
  93. return getTable().findElements(By.cssSelector(".v-table-table tr"));
  94. }
  95. }