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.

ComboBoxScrollingWithArrowsTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.combobox;
  17. import com.vaadin.testbench.By;
  18. import com.vaadin.testbench.elements.ComboBoxElement;
  19. import com.vaadin.tests.tb3.MultiBrowserTest;
  20. import org.junit.Test;
  21. import org.openqa.selenium.Keys;
  22. import org.openqa.selenium.WebDriver;
  23. import org.openqa.selenium.WebElement;
  24. import org.openqa.selenium.support.ui.ExpectedCondition;
  25. import java.util.List;
  26. import static org.hamcrest.MatcherAssert.assertThat;
  27. import static org.hamcrest.Matchers.is;
  28. /**
  29. * When pressed down key, while positioned on the last item - should show next
  30. * page and focus on the first item of the next page.
  31. */
  32. public class ComboBoxScrollingWithArrowsTest extends MultiBrowserTest {
  33. private final int PAGESIZE = 10;
  34. @Override
  35. public void setup() throws Exception {
  36. super.setup();
  37. openTestURL();
  38. openPopup();
  39. }
  40. private WebElement getDropDown() {
  41. // Selenium is used instead of TestBench4, because there is no method to
  42. // access the popup of the combobox
  43. // The method ComboBoxElement.openPopup() opens the popup, but doesn't
  44. // provide any way to access the popup and send keys to it.
  45. // Ticket #13756
  46. return driver.findElement(By.className("v-filterselect-input"));
  47. }
  48. private void openPopup() {
  49. ComboBoxElement cb = $(ComboBoxElement.class).first();
  50. cb.openPopup();
  51. }
  52. @Test
  53. public void scrollDownArrowKeyTest() throws InterruptedException {
  54. WebElement dropDownComboBox = getDropDown();
  55. // go to the last item and then one more
  56. for (int i = 0; i < PAGESIZE + 1; i++) {
  57. dropDownComboBox.sendKeys(Keys.DOWN);
  58. }
  59. assertThat(getSelectedItemText(), is("item " + PAGESIZE)); // item 10
  60. }
  61. private String getSelectedItemText() {
  62. List<WebElement> items = driver.findElements(By
  63. .className("gwt-MenuItem-selected"));
  64. return items.get(0).getText();
  65. }
  66. @Test
  67. public void scrollUpArrowKeyTest() throws InterruptedException {
  68. WebElement dropDownComboBox = getDropDown();
  69. // go to the last item and then one more
  70. for (int i = 0; i < PAGESIZE + 1; i++) {
  71. dropDownComboBox.sendKeys(Keys.DOWN);
  72. }
  73. // move to one item up
  74. waitUntilNextPageIsVisible();
  75. dropDownComboBox.sendKeys(Keys.UP);
  76. assertThat(getSelectedItemText(), is("item " + (PAGESIZE - 1))); // item
  77. // 9
  78. }
  79. private void waitUntilNextPageIsVisible() {
  80. waitUntil(new ExpectedCondition<Boolean>() {
  81. @Override
  82. public Boolean apply(WebDriver input) {
  83. return getSelectedItemText().equals("item " + PAGESIZE);
  84. }
  85. }, 5);
  86. }
  87. }