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.

ThemeTest.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package com.vaadin.tests.components.uitest;
  2. import java.io.IOException;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import org.openqa.selenium.Keys;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8. import com.vaadin.testbench.By;
  9. import com.vaadin.testbench.Parameters;
  10. import com.vaadin.testbench.elements.ButtonElement;
  11. import com.vaadin.testbench.elements.ComboBoxElement;
  12. import com.vaadin.testbench.elements.DateFieldElement;
  13. import com.vaadin.testbench.elements.NotificationElement;
  14. import com.vaadin.testbench.elements.TabSheetElement;
  15. import com.vaadin.testbench.elements.TableElement;
  16. import com.vaadin.testbench.elements.WindowElement;
  17. import com.vaadin.testbench.parallel.BrowserUtil;
  18. import com.vaadin.tests.tb3.MultiBrowserTest;
  19. public abstract class ThemeTest extends MultiBrowserTest {
  20. @Override
  21. protected boolean requireWindowFocusForIE() {
  22. return true;
  23. }
  24. @Override
  25. protected Class<?> getUIClass() {
  26. return ThemeTestUI.class;
  27. }
  28. protected abstract String getTheme();
  29. @Before
  30. public void before() {
  31. Parameters.setScreenshotComparisonTolerance(0.1);
  32. }
  33. @Test
  34. public void testTheme() throws Exception {
  35. openTestURL("theme=" + getTheme());
  36. runThemeTest();
  37. }
  38. private void runThemeTest() throws IOException, InterruptedException {
  39. TabSheetElement themeTabSheet = $(TabSheetElement.class).first();
  40. // Labels tab
  41. compareScreen("labels");
  42. // Buttons tab
  43. openTab(themeTabSheet, "Buttons");
  44. compareScreen("buttons");
  45. // Embedded tab
  46. openTab(themeTabSheet, "Embedded");
  47. compareScreen("embedded");
  48. // Dates tab
  49. openTab(themeTabSheet, "Dates");
  50. testDates();
  51. // TextFields tab
  52. openTab(themeTabSheet, "TextFields");
  53. compareScreen("textfields");
  54. // Selects tab
  55. openTab(themeTabSheet, "Selects");
  56. testSelects();
  57. // Sliders tab
  58. openTab(themeTabSheet, "Sliders");
  59. compareScreen("sliders");
  60. // Uploads tab
  61. openTab(themeTabSheet, "Uploads");
  62. compareScreen("uploads");
  63. // Forms tab
  64. openTab(themeTabSheet, "Forms");
  65. compareScreen("forms");
  66. // Tables tab
  67. openTab(themeTabSheet, "Tables");
  68. testTables();
  69. // Trees tab
  70. openTab(themeTabSheet, "Trees");
  71. compareScreen("trees");
  72. // TreeTable tab
  73. openTab(themeTabSheet, "TreeTable");
  74. compareScreen("treetable");
  75. // Layouts tab
  76. openTab(themeTabSheet, "Layouts");
  77. compareScreen("layouts");
  78. // TabSheets tab
  79. openTab(themeTabSheet, "TabSheets");
  80. compareScreen("tabsheets");
  81. // Accordions tab
  82. openTab(themeTabSheet, "Accordions");
  83. compareScreen("accordions");
  84. // Windows tab
  85. openTab(themeTabSheet, "Windows");
  86. testWindows();
  87. // Notifications tab
  88. openTab(themeTabSheet, "Notifications");
  89. testNotifications();
  90. }
  91. private void openTab(TabSheetElement themeTabSheet, String string) {
  92. themeTabSheet.openTab(string);
  93. /* Layouting takes a moment after tab has been opened. */
  94. try {
  95. Thread.sleep(300);
  96. } catch (InterruptedException e) {
  97. }
  98. }
  99. private void testNotifications() throws IOException {
  100. testNotification(0, "notification-humanized");
  101. testNotification(1, "notification-warning");
  102. testNotification(2, "notification-error");
  103. testNotification(3, "notification-tray");
  104. }
  105. private void testNotification(int id, String identifier)
  106. throws IOException {
  107. $(ButtonElement.class).id("notifButt" + id).click();
  108. // For some reason, this seems to be more reliable on IE11
  109. waitUntil(driver -> isElementPresent(NotificationElement.class), 10);
  110. compareScreen(identifier);
  111. $(NotificationElement.class).first().close();
  112. }
  113. protected void testWindows() throws IOException {
  114. testWindow(0, "subwindow-default");
  115. }
  116. protected void testWindow(int id, String identifier) throws IOException {
  117. $(ButtonElement.class).id("windButton" + id).click();
  118. sleep(200);
  119. compareScreen(identifier);
  120. WindowElement window = $(WindowElement.class).first();
  121. if (getTheme() == "chameleon"
  122. && BrowserUtil.isIE(getDesiredCapabilities())) {
  123. new Actions(getDriver()).moveToElement(window, 10, 10).click()
  124. .sendKeys(Keys.ESCAPE).perform();
  125. } else {
  126. window.findElement(By.className("v-window-closebox")).click();
  127. }
  128. }
  129. private void testTables() throws IOException {
  130. compareScreen("tables");
  131. TableElement table = $(TableElement.class).first();
  132. new Actions(driver).moveToElement(table.getCell(0, 1), 5, 5)
  133. .contextClick().perform();
  134. compareScreen("tables-contextmenu");
  135. table.findElement(By.className("v-table-column-selector")).click();
  136. compareScreen("tables-collapsemenu");
  137. }
  138. private void testSelects() throws IOException {
  139. compareScreen("selects");
  140. $(ComboBoxElement.class).id("select0").openPopup();
  141. compareScreen("selects-first-open");
  142. $(ComboBoxElement.class).id("select1").openPopup();
  143. compareScreen("selects-second-open");
  144. $(ComboBoxElement.class).id("select6").openPopup();
  145. compareScreen("selects-third-open");
  146. /* In chameleon theme search combobox has no visible popup button */
  147. ComboBoxElement searchComboBox = $(ComboBoxElement.class).id("select7");
  148. if (searchComboBox.findElement(By.tagName("div")).isDisplayed()) {
  149. searchComboBox.openPopup();
  150. } else {
  151. WebElement textBox = searchComboBox
  152. .findElement(By.vaadin("#textbox"));
  153. textBox.click();
  154. textBox.sendKeys(Keys.ARROW_DOWN);
  155. }
  156. compareScreen("selects-fourth-open");
  157. $(ComboBoxElement.class).id("select8").openPopup();
  158. compareScreen("selects-fifth-open");
  159. }
  160. private void testDates() throws IOException, InterruptedException {
  161. compareScreen("dates");
  162. $(DateFieldElement.class).id("datefield0").openPopup();
  163. Thread.sleep(200);
  164. compareScreen("dates-first-popup");
  165. $(DateFieldElement.class).id("datefield1").openPopup();
  166. Thread.sleep(200);
  167. compareScreen("dates-second-popup");
  168. $(DateFieldElement.class).id("datefield2").openPopup();
  169. Thread.sleep(200);
  170. compareScreen("dates-third-popup");
  171. $(DateFieldElement.class).id("datefield3").openPopup();
  172. Thread.sleep(200);
  173. compareScreen("dates-fourth-popup");
  174. }
  175. }