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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright 2000-2013 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.ui;
  17. import java.io.IOException;
  18. import java.util.List;
  19. import org.junit.Test;
  20. import org.openqa.selenium.WebDriver;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.remote.DesiredCapabilities;
  23. import org.openqa.selenium.support.ui.ExpectedCondition;
  24. import com.vaadin.testbench.By;
  25. import com.vaadin.testbench.parallel.Browser;
  26. import com.vaadin.tests.tb3.MultiBrowserTest;
  27. /**
  28. * Test class for issue #13477, where selecting a combobox item that is too long
  29. * would render the ending of an item instead of the beginning, which was
  30. * considered less than informative.
  31. *
  32. * @author Vaadin Ltd
  33. */
  34. public class ComboboxSelectedItemTextTest extends MultiBrowserTest {
  35. public final String SCREENSHOT_NAME_EDITABLE = "LongComboboxItemSelectedEditable";
  36. public final String SCREENSHOT_NAME_NON_EDITABLE = "LongComboboxItemSelectedNonEditable";
  37. public final int INDEX_EDITABLE_COMBOBOX = 1;
  38. public final int INDEX_NON_EDITABLE_COMBOBOX = 2;
  39. @Override
  40. public List<DesiredCapabilities> getBrowsersToTest() {
  41. // Ignoring Chrome 40 because of a regression. See #16636.
  42. return getBrowserCapabilities(Browser.IE11, Browser.FIREFOX,
  43. Browser.PHANTOMJS);
  44. }
  45. @Test
  46. public void testCombobox() throws IOException {
  47. testCombobox(INDEX_EDITABLE_COMBOBOX, INDEX_NON_EDITABLE_COMBOBOX,
  48. SCREENSHOT_NAME_EDITABLE);
  49. }
  50. @Test
  51. public void testComboboxNonEditable() throws IOException {
  52. testCombobox(INDEX_NON_EDITABLE_COMBOBOX, INDEX_EDITABLE_COMBOBOX,
  53. SCREENSHOT_NAME_NON_EDITABLE);
  54. }
  55. private void testCombobox(int indexToTest, int indexToFocus,
  56. String screenshotIdentifier) throws IOException {
  57. openTestURL();
  58. WebElement comboBox = vaadinElement(
  59. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  60. + indexToTest + "]/VComboBox[0]");
  61. WebElement comboBoxFocus = vaadinElement(
  62. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  63. + indexToFocus + "]/VComboBox[0]");
  64. // Select an element from the first (to test) combobox.
  65. clickElement(
  66. comboBox.findElement(By.className("v-filterselect-button")));
  67. waitForPopup(comboBox);
  68. WebElement comboBoxPopup = vaadinElement(
  69. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  70. + indexToTest + "]/VComboBox[0]#popup");
  71. clickElement(comboBoxPopup.findElements(By.tagName("td")).get(2));
  72. // Select an element from the second (to focus) combobox to remove
  73. // focus from the first combobox
  74. clickElement(comboBoxFocus
  75. .findElement(By.className("v-filterselect-button")));
  76. waitForPopup(comboBoxFocus);
  77. comboBoxPopup = vaadinElement(
  78. "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot["
  79. + indexToFocus + "]/VComboBox[0]#popup");
  80. clickElement(comboBoxPopup.findElements(By.tagName("td")).get(2));
  81. // click the button of the first combobox. This would reveal the
  82. // unwanted behaviour.
  83. clickElement(
  84. comboBox.findElement(By.className("v-filterselect-button")));
  85. // sadly, screenshot comparison is the only reasonable way to test a
  86. // rendering issue.
  87. compareScreen(screenshotIdentifier);
  88. }
  89. private void waitForPopup(final WebElement comboBox) {
  90. waitUntilNot(new ExpectedCondition<Boolean>() {
  91. @Override
  92. public Boolean apply(WebDriver input) {
  93. return comboBox.findElements(By.vaadin("#popup")).isEmpty();
  94. }
  95. }, 10);
  96. }
  97. }