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.6KB

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