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.

ComboBoxItemIconTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.vaadin.tests.components.combobox;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import static org.junit.Assert.assertEquals;
  5. import org.junit.Test;
  6. import org.openqa.selenium.Keys;
  7. import org.openqa.selenium.remote.DesiredCapabilities;
  8. import com.vaadin.testbench.By;
  9. import com.vaadin.testbench.elements.ComboBoxElement;
  10. import com.vaadin.testbench.parallel.Browser;
  11. import com.vaadin.testbench.parallel.TestCategory;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. @TestCategory("xvfb-test")
  14. public class ComboBoxItemIconTest extends MultiBrowserTest {
  15. @Override
  16. public List<DesiredCapabilities> getBrowsersToTest() {
  17. return Arrays.asList(Browser.CHROME.getDesiredCapabilities(),
  18. Browser.FIREFOX.getDesiredCapabilities());
  19. }
  20. @Test
  21. public void testIconsInComboBox() throws Exception {
  22. openTestURL();
  23. ComboBoxElement firstCombo = $(ComboBoxElement.class).first();
  24. firstCombo.openPopup();
  25. compareScreen(firstCombo.getSuggestionPopup(), "first-combobox-open");
  26. // null item not on the list, so use index 1
  27. firstCombo.selectByText(firstCombo.getPopupSuggestions().get(1));
  28. compareScreen(firstCombo, "fi-hu-selected");
  29. ComboBoxElement secondCombo = $(ComboBoxElement.class).get(1);
  30. secondCombo.openPopup();
  31. compareScreen(secondCombo.getSuggestionPopup(), "second-combobox-open");
  32. secondCombo.selectByText(secondCombo.getPopupSuggestions().get(2));
  33. compareScreen(secondCombo, "fi-au-selected");
  34. ComboBoxElement thirdCombo = $(ComboBoxElement.class).get(2);
  35. thirdCombo.openPopup();
  36. compareScreen(thirdCombo.getSuggestionPopup(), "third-combobox-open");
  37. thirdCombo.selectByText(thirdCombo.getPopupSuggestions().get(3));
  38. compareScreen(thirdCombo, "classresource");
  39. }
  40. @Test
  41. public void iconResetOnSelectionCancelByEscape() {
  42. openTestURL();
  43. ComboBoxElement cb = $(ComboBoxElement.class).get(1);
  44. assertSelection(cb, "hu.gif", "Hungary");
  45. cb.openPopup();
  46. cb.sendKeys(Keys.UP);
  47. assertSelection(cb, "au.gif", "Australia");
  48. cb.sendKeys(Keys.ESCAPE);
  49. assertSelection(cb, "hu.gif", "Hungary");
  50. }
  51. @Test
  52. public void iconResetOnSelectionCancelByClickingOutside() {
  53. openTestURL();
  54. ComboBoxElement cb = $(ComboBoxElement.class).get(1);
  55. assertSelection(cb, "hu.gif", "Hungary");
  56. cb.openPopup();
  57. cb.sendKeys(Keys.UP);
  58. assertSelection(cb, "au.gif", "Australia");
  59. findElement(By.tagName("body")).click();
  60. assertSelection(cb, "hu.gif", "Hungary");
  61. }
  62. private void assertSelection(ComboBoxElement cb, String imageSuffix,
  63. String caption) {
  64. assertEquals(caption, cb.getValue());
  65. String imgSrc = cb.findElement(By.className("v-icon"))
  66. .getAttribute("src");
  67. imgSrc = imgSrc.substring(imgSrc.lastIndexOf('/') + 1);
  68. assertEquals(imageSuffix, imgSrc);
  69. }
  70. }