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.

ComboboxSelectedItemTextTest.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.vaadin.tests.components.ui;
  2. import java.io.IOException;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.remote.DesiredCapabilities;
  7. import com.vaadin.testbench.By;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. /**
  10. * Test class for issue #13477, where selecting a combobox item that is too long
  11. * would render the ending of an item instead of the beginning, which was
  12. * considered less than informative.
  13. *
  14. * @author Vaadin Ltd
  15. */
  16. public class ComboboxSelectedItemTextTest extends MultiBrowserTest {
  17. public final String SCREENSHOT_NAME_EDITABLE = "LongComboboxItemSelectedEditable";
  18. public final String SCREENSHOT_NAME_NON_EDITABLE = "LongComboboxItemSelectedNonEditable";
  19. public final int INDEX_EDITABLE_COMBOBOX = 1;
  20. public final int INDEX_NON_EDITABLE_COMBOBOX = 2;
  21. @Override
  22. public List<DesiredCapabilities> getBrowsersToTest() {
  23. // Regression. See #16636.
  24. return getBrowsersExcludingChrome();
  25. }
  26. @Test
  27. public void testCombobox() throws IOException {
  28. testCombobox(INDEX_EDITABLE_COMBOBOX, INDEX_NON_EDITABLE_COMBOBOX,
  29. SCREENSHOT_NAME_EDITABLE);
  30. }
  31. @Test
  32. public void testComboboxNonEditable() throws IOException {
  33. testCombobox(INDEX_NON_EDITABLE_COMBOBOX, INDEX_EDITABLE_COMBOBOX,
  34. SCREENSHOT_NAME_NON_EDITABLE);
  35. }
  36. private void testCombobox(int indexToTest, int indexToFocus,
  37. String screenshotIdentifier) throws IOException {
  38. openTestURL();
  39. WebElement comboBox = vaadinElement(
  40. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  41. + indexToTest + "]/VComboBox[0]");
  42. WebElement comboBoxFocus = vaadinElement(
  43. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  44. + indexToFocus + "]/VComboBox[0]");
  45. // Select an element from the first (to test) combobox.
  46. clickElement(
  47. comboBox.findElement(By.className("v-filterselect-button")));
  48. waitForPopup(comboBox);
  49. WebElement comboBoxPopup = vaadinElement(
  50. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  51. + indexToTest + "]/VComboBox[0]#popup");
  52. clickElement(comboBoxPopup.findElements(By.tagName("td")).get(2));
  53. // Select an element from the second (to focus) combobox to remove
  54. // focus from the first combobox
  55. clickElement(comboBoxFocus
  56. .findElement(By.className("v-filterselect-button")));
  57. waitForPopup(comboBoxFocus);
  58. comboBoxPopup = vaadinElement(
  59. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  60. + indexToFocus + "]/VComboBox[0]#popup");
  61. clickElement(comboBoxPopup.findElements(By.tagName("td")).get(2));
  62. // click the button of the first combobox. This would reveal the
  63. // unwanted behavior.
  64. clickElement(
  65. comboBox.findElement(By.className("v-filterselect-button")));
  66. // sadly, screenshot comparison is the only reasonable way to test a
  67. // rendering issue.
  68. compareScreen(screenshotIdentifier);
  69. }
  70. private void waitForPopup(final WebElement comboBox) {
  71. waitUntilNot(
  72. input -> comboBox.findElements(By.vaadin("#popup")).isEmpty(),
  73. 10);
  74. }
  75. }