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.

NativeButtonIconAndTextTest.java 3.1KB

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