您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NativeButtonIconAndTextTest.java 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.nativebutton;
  17. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.BUTTON_TEXT;
  18. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.BUTTON_TEXT_ICON;
  19. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.BUTTON_TEXT_ICON_ALT;
  20. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.INITIAL_ALTERNATE_TEXT;
  21. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.NATIVE_BUTTON_TEXT;
  22. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.NATIVE_BUTTON_TEXT_ICON;
  23. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.NATIVE_BUTTON_TEXT_ICON_ALT;
  24. import static com.vaadin.tests.components.nativebutton.NativeButtonIconAndText.UPDATED_ALTERNATE_TEXT;
  25. import java.util.List;
  26. import org.junit.Assert;
  27. import org.junit.Test;
  28. import org.openqa.selenium.By;
  29. import org.openqa.selenium.WebElement;
  30. import com.vaadin.tests.tb3.MultiBrowserTest;
  31. public class NativeButtonIconAndTextTest extends MultiBrowserTest {
  32. @Test
  33. public void testNativeButtonIconAltText() {
  34. openTestURL();
  35. assertAltText(BUTTON_TEXT, "");
  36. assertAltText(BUTTON_TEXT_ICON, "");
  37. assertAltText(BUTTON_TEXT_ICON_ALT, INITIAL_ALTERNATE_TEXT);
  38. assertAltText(NATIVE_BUTTON_TEXT, "");
  39. assertAltText(NATIVE_BUTTON_TEXT_ICON, "");
  40. assertAltText(NATIVE_BUTTON_TEXT_ICON_ALT, INITIAL_ALTERNATE_TEXT);
  41. clickElements(BUTTON_TEXT, BUTTON_TEXT_ICON, BUTTON_TEXT_ICON_ALT,
  42. NATIVE_BUTTON_TEXT, NATIVE_BUTTON_TEXT_ICON,
  43. NATIVE_BUTTON_TEXT_ICON_ALT);
  44. // Button without icon - should not get alt text
  45. assertAltText(BUTTON_TEXT, "");
  46. assertAltText(BUTTON_TEXT_ICON, UPDATED_ALTERNATE_TEXT);
  47. assertAltText(BUTTON_TEXT_ICON_ALT, "");
  48. // Button without icon - should not get alt text
  49. assertAltText(NATIVE_BUTTON_TEXT, "");
  50. assertAltText(NATIVE_BUTTON_TEXT_ICON, UPDATED_ALTERNATE_TEXT);
  51. assertAltText(NATIVE_BUTTON_TEXT_ICON_ALT, "");
  52. }
  53. private void clickElements(String... ids) {
  54. for (String id : ids) {
  55. vaadinElementById(id).click();
  56. }
  57. }
  58. /**
  59. * If the button identified by 'buttonId' has an icon, asserts that the
  60. * alternate text of the icon matches 'expected'. "" and null are considered
  61. * equivalent.
  62. *
  63. * @param buttonId
  64. * the id of the button who possibly contains an icon
  65. * @param expected
  66. * the expected alternate text, cannot be null
  67. */
  68. private void assertAltText(String buttonId, String expected) {
  69. WebElement button = vaadinElementById(buttonId);
  70. List<WebElement> imgList = button.findElements(By.xpath(".//img"));
  71. if (imgList.isEmpty()) {
  72. return;
  73. }
  74. WebElement img = imgList.get(0);
  75. String alt = img.getAttribute("alt");
  76. if (alt == null) {
  77. alt = "";
  78. }
  79. Assert.assertEquals(expected, alt);
  80. }
  81. }