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.

ListSelectMultiSelectionTest.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.vaadin.tests.components.listselect;
  2. import static org.junit.Assert.assertEquals;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import org.openqa.selenium.Keys;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8. import org.openqa.selenium.support.ui.Select;
  9. import com.vaadin.testbench.By;
  10. import com.vaadin.testbench.elements.ListSelectElement;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. public class ListSelectMultiSelectionTest extends MultiBrowserTest {
  13. @Override
  14. protected Class<?> getUIClass() {
  15. return ListSelectTestUI.class;
  16. }
  17. @Test
  18. public void testShiftSelect() {
  19. openTestURL();
  20. ListSelectElement listSelect = $(ListSelectElement.class).first();
  21. Select select = new Select(listSelect.getSelectElement());
  22. List<WebElement> options = listSelect
  23. .findElements(By.tagName("option"));
  24. options.get(0).click();
  25. List<WebElement> selected = select.getAllSelectedOptions();
  26. assertEquals(1, selected.size());
  27. assertEquals("Item 0", selected.get(0).getText());
  28. new Actions(getDriver()).keyDown(Keys.SHIFT).perform();
  29. options.get(1).click();
  30. new Actions(getDriver()).keyUp(Keys.SHIFT).perform();
  31. selected = select.getAllSelectedOptions();
  32. assertEquals(2, selected.size());
  33. assertEquals("Item 1", selected.get(1).getText());
  34. new Actions(getDriver()).keyDown(Keys.SHIFT).perform();
  35. options.get(2).click();
  36. new Actions(getDriver()).keyUp(Keys.SHIFT).perform();
  37. // ensure second shift selection added instead of moved
  38. selected = select.getAllSelectedOptions();
  39. assertEquals(3, selected.size());
  40. assertEquals("Item 2", selected.get(2).getText());
  41. assertEquals("Item 0", selected.get(0).getText());
  42. }
  43. }