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.

ComboBoxInputPromptTest.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 static org.hamcrest.MatcherAssert.assertThat;
  18. import static org.hamcrest.Matchers.is;
  19. import static org.hamcrest.Matchers.isEmptyString;
  20. import static org.junit.Assert.assertEquals;
  21. import com.vaadin.testbench.elements.ButtonElement;
  22. import com.vaadin.testbench.elements.ComboBoxElement;
  23. import com.vaadin.testbench.elements.TextFieldElement;
  24. import com.vaadin.tests.tb3.AbstractTB3Test;
  25. import org.junit.Test;
  26. import org.openqa.selenium.By;
  27. import org.openqa.selenium.WebElement;
  28. import com.vaadin.tests.tb3.MultiBrowserTest;
  29. public class ComboBoxInputPromptTest extends MultiBrowserTest {
  30. @Test
  31. public void promptIsHiddenForDisabledAndReadonly() {
  32. openTestURL();
  33. ComboBoxElement normalComboBox = getComboBoxWithCaption("Normal");
  34. ComboBoxElement disabledComboBox = getComboBoxWithCaption("Disabled");
  35. ComboBoxElement readOnlyComboBox = getComboBoxWithCaption("Read-only");
  36. assertThat(getInputPromptValue(normalComboBox),
  37. is("Normal input prompt"));
  38. assertThat(getInputPromptValue(disabledComboBox), isEmptyString());
  39. assertThat(getInputPromptValue(readOnlyComboBox), isEmptyString());
  40. toggleDisabledAndReadonly();
  41. assertThat(getInputPromptValue(disabledComboBox),
  42. is("Disabled input prompt"));
  43. assertThat(getInputPromptValue(readOnlyComboBox),
  44. is("Read-only input prompt"));
  45. toggleDisabledAndReadonly();
  46. assertThat(getInputPromptValue(disabledComboBox), isEmptyString());
  47. assertThat(getInputPromptValue(readOnlyComboBox), isEmptyString());
  48. }
  49. private void toggleDisabledAndReadonly() {
  50. $(ButtonElement.class).first().click();
  51. }
  52. private String getInputPromptValue(ComboBoxElement comboBox) {
  53. WebElement input = comboBox.findElement(By.tagName("input"));
  54. return input.getAttribute("value");
  55. }
  56. private ComboBoxElement getComboBoxWithCaption(String caption) {
  57. return $(ComboBoxElement.class).caption(caption).first();
  58. }
  59. }