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.

LegacyComponentThemeChangeTest.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.vaadin.tests.themes;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertTrue;
  4. import java.util.List;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.remote.DesiredCapabilities;
  9. import com.vaadin.testbench.elements.ButtonElement;
  10. import com.vaadin.testbench.elements.ComboBoxElement;
  11. import com.vaadin.testbench.elements.EmbeddedElement;
  12. import com.vaadin.testbench.elements.MenuBarElement;
  13. import com.vaadin.testbench.elements.TableElement;
  14. import com.vaadin.testbench.parallel.BrowserUtil;
  15. import com.vaadin.tests.tb3.MultiBrowserTest;
  16. public class LegacyComponentThemeChangeTest extends MultiBrowserTest {
  17. @Override
  18. public List<DesiredCapabilities> getBrowsersToTest() {
  19. // For some reason, IE times out when trying to open the combobox,
  20. // #18341
  21. return getBrowsersExcludingIE();
  22. }
  23. @Test
  24. public void legacyComponentThemeResourceChange() {
  25. openTestURL();
  26. String theme = "reindeer";
  27. assertMenubarTheme(theme);
  28. assertCombobBoxTheme(theme);
  29. assertTableTheme(theme);
  30. assertEmbeddedTheme(theme);
  31. theme = "runo";
  32. changeTheme(theme);
  33. assertMenubarTheme(theme);
  34. assertCombobBoxTheme(theme);
  35. assertTableTheme(theme);
  36. assertEmbeddedTheme(theme);
  37. theme = "reindeer";
  38. changeTheme(theme);
  39. assertMenubarTheme(theme);
  40. assertCombobBoxTheme(theme);
  41. assertTableTheme(theme);
  42. assertEmbeddedTheme(theme);
  43. }
  44. private void assertEmbeddedTheme(String theme) {
  45. if (BrowserUtil.isChrome(getDesiredCapabilities())) {
  46. // Chrome 47 won't initialize the dummy flash properly
  47. return;
  48. }
  49. EmbeddedElement e = $(EmbeddedElement.class).first();
  50. WebElement movieParam = e
  51. .findElement(By.xpath(".//param[@name='movie']"));
  52. WebElement embed = e.findElement(By.xpath(".//embed"));
  53. assertAttributePrefix(movieParam, "value", theme);
  54. assertAttributePrefix(embed, "src", theme);
  55. assertAttributePrefix(embed, "movie", theme);
  56. }
  57. private void assertTableTheme(String theme) {
  58. TableElement t = $(TableElement.class).first();
  59. t.getRow(0).contextClick();
  60. WebElement popup = findElement(By.className("v-contextmenu"));
  61. WebElement actionImage = popup.findElement(By.xpath(".//img"));
  62. assertAttributePrefix(actionImage, "src", theme);
  63. }
  64. private void assertCombobBoxTheme(String theme) {
  65. ComboBoxElement cb = $(ComboBoxElement.class).first();
  66. WebElement selectedImage = cb.findElement(By.xpath("./img"));
  67. assertAttributePrefix(selectedImage, "src", theme);
  68. cb.openPopup();
  69. WebElement popup = findElement(
  70. By.className("v-filterselect-suggestpopup"));
  71. WebElement itemImage = popup.findElement(By.xpath(".//img"));
  72. assertAttributePrefix(itemImage, "src", theme);
  73. }
  74. private void assertMenubarTheme(String theme) {
  75. // The runoImage must always come from Runo
  76. WebElement runoImage = $(MenuBarElement.class).first()
  77. .findElement(By.xpath(".//span[text()='runo']/img"));
  78. String runoImageSrc = runoImage.getAttribute("src");
  79. // Something in Selenium normalizes the image so it becomes
  80. // "/themes/runo/icons/16/ok.png" here although it is
  81. // "/themes/<currenttheme>/../runo/icons/16/ok.png" in the browser
  82. assertEquals(getThemeURL("runo") + "icons/16/ok.png", runoImageSrc);
  83. // The other image should change with the theme
  84. WebElement themeImage = $(MenuBarElement.class).first()
  85. .findElement(By.xpath(".//span[text()='selectedtheme']/img"));
  86. assertAttributePrefix(themeImage, "src", theme);
  87. WebElement subMenuItem = $(MenuBarElement.class).first()
  88. .findElement(By.xpath(".//span[text()='sub menu']"));
  89. subMenuItem.click();
  90. WebElement subMenu = findElement(By.className("v-menubar-popup"));
  91. WebElement subMenuRuno = subMenu
  92. .findElement(By.xpath(".//span[text()='runo']/img"));
  93. String subMenuRunoImageSrc = subMenuRuno.getAttribute("src");
  94. assertEquals(getThemeURL("runo") + "icons/16/ok.png",
  95. subMenuRunoImageSrc);
  96. WebElement subMenuThemeImage = subMenu
  97. .findElement(By.xpath(".//span[text()='selectedtheme']/img"));
  98. assertAttributePrefix(subMenuThemeImage, "src", theme);
  99. // Close menu item.
  100. subMenuItem.click();
  101. }
  102. private void assertAttributePrefix(WebElement element, String attribute,
  103. String theme) {
  104. String value = element.getAttribute(attribute);
  105. String expectedPrefix = getThemeURL(theme);
  106. assertTrue(
  107. "Attribute " + attribute + "='" + value
  108. + "' does not start with " + expectedPrefix,
  109. value.startsWith(expectedPrefix));
  110. }
  111. private String getThemeURL(String theme) {
  112. return getBaseURL() + "/VAADIN/themes/" + theme + "/";
  113. }
  114. private void changeTheme(String theme) {
  115. $(ButtonElement.class).id(theme).click();
  116. waitForThemeToChange(theme);
  117. }
  118. }