/auiplugin-tests/src/test/java/it/com/atlassian/aui/javascript/integrationTests/AUIDialogTest.java

https://bitbucket.org/versionzero/aui · Java · 254 lines · 174 code · 67 blank · 13 comment · 0 complexity · bb4db1c2d47f114b9fd3b126f2f6be41 MD5 · raw file

  1. package it.com.atlassian.aui.javascript.integrationTests;
  2. import com.atlassian.pageobjects.elements.PageElement;
  3. import com.atlassian.pageobjects.elements.PageElementFinder;
  4. import com.atlassian.pageobjects.elements.WebDriverElement;
  5. import com.atlassian.webdriver.AtlassianWebDriver;
  6. import it.com.atlassian.aui.javascript.AbstractAuiIntegrationTest;
  7. import it.com.atlassian.aui.javascript.pages.DialogTestPage;
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. import org.openqa.selenium.By;
  11. import org.openqa.selenium.Dimension;
  12. import org.openqa.selenium.Keys;
  13. import org.openqa.selenium.WebElement;
  14. import org.openqa.selenium.interactions.Actions;
  15. import static com.atlassian.pageobjects.elements.query.Poller.waitUntilTrue;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertTrue;
  19. public class AUIDialogTest extends AbstractAuiIntegrationTest
  20. {
  21. private DialogTestPage dialogTestPage;
  22. private PageElementFinder elementFinder;
  23. @Before
  24. public void setup()
  25. {
  26. dialogTestPage = product.visit(DialogTestPage.class);
  27. elementFinder = dialogTestPage.getElementFinder();
  28. }
  29. @Test
  30. public void testPopupDim()
  31. {
  32. elementFinder.find(By.id("popup-button")).click();
  33. PageElement blanket = elementFinder.find(By.className("aui-blanket"));
  34. assertTrue("The dim blanket should be present in the dom", blanket.isPresent());
  35. assertTrue("The dim blanket should be visible", blanket.isVisible());
  36. }
  37. //Test that dims for dialogs work
  38. @Test
  39. public void testDialogDim()
  40. {
  41. elementFinder.find(By.id("dialog-button")).click();
  42. PageElement blanket = elementFinder.find(By.className("aui-blanket"));
  43. assertTrue("The dim blanket should be present in the dom", blanket.isPresent());
  44. assertTrue("The dim blanket should be visible", blanket.isVisible());
  45. }
  46. //test that the popup shows correctly
  47. @Test
  48. public void testPopupShow()
  49. {
  50. elementFinder.find(By.id("popup-button")).click();
  51. PageElement popup = elementFinder.find(By.id("my-popup"));
  52. assertTrue("The popup should be present", popup.isPresent());
  53. assertTrue("The popup should be visible", popup.isVisible());
  54. }
  55. //test that dialogs show correctly
  56. @Test
  57. public void testDialogShow()
  58. {
  59. elementFinder.find(By.id("dialog-button")).click();
  60. PageElement dialog = elementFinder.find(By.id("dialog-test"));
  61. assertTrue("The popup should be present", dialog.isPresent());
  62. assertTrue("The popup should be visible", dialog.isVisible());
  63. }
  64. //test that popup hides correctly after escape key is hit
  65. @Test
  66. public void testPopupEscHide()
  67. {
  68. elementFinder.find(By.id("popup-button")).click();
  69. PageElement popup = elementFinder.find(By.id("my-popup"));
  70. assertTrue("The popup should be present", popup.isPresent());
  71. assertTrue("The popup should be visible", popup.isVisible());
  72. new Actions(product.getTester().getDriver()).sendKeys(Keys.ESCAPE).perform();
  73. assertFalse("The popup should not be visible", popup.isVisible());
  74. }
  75. //test that dialog is hidden correctly after escape key is hit
  76. @Test
  77. public void testDialogEscHide()
  78. {
  79. elementFinder.find(By.id("dialog-button")).click();
  80. PageElement dialog = elementFinder.find(By.id("dialog-test"));
  81. assertTrue("The dialog should be present", dialog.isPresent());
  82. assertTrue("The dialog should be visible", dialog.isVisible());
  83. new Actions(product.getTester().getDriver()).sendKeys(Keys.ESCAPE).perform();
  84. assertFalse("The dialog should not be visible", dialog.isVisible());
  85. }
  86. //test that Dialog hides correctly when pressing a close button
  87. @Test
  88. public void testDialogButtonHide()
  89. {
  90. elementFinder.find(By.id("dialog-button")).click();
  91. PageElement dialog = elementFinder.find(By.id("dialog-test"));
  92. assertTrue("The dialog should be present", dialog.isPresent());
  93. assertTrue("The dialog should be visible", dialog.isVisible());
  94. dialog.find(By.cssSelector("button.button-panel-button:nth-child(3)")).click();
  95. assertFalse("The dialog should not be visible", dialog.isVisible());
  96. }
  97. //test that popups are set to the correct size
  98. @Test
  99. public void testPopupSize()
  100. {
  101. elementFinder.find(By.id("popup-button")).click();
  102. WebDriverElement popup = (WebDriverElement) elementFinder.find(By.id("my-popup"));
  103. WebElement el = popup.asWebElement();
  104. Dimension size = el.getSize();
  105. assertEquals("Dialog: 'my-popup' Height is not 200px", 200, size.getHeight());
  106. assertEquals("Dialog: 'my-popup' Width is not 400px", 400, size.getWidth());
  107. }
  108. //test that dialogs are set to the correct size
  109. @Test
  110. public void testDialogSize()
  111. {
  112. elementFinder.find(By.id("dialog-button")).click();
  113. WebDriverElement dialog = (WebDriverElement) elementFinder.find(By.id("dialog-test"));
  114. WebElement el = dialog.asWebElement();
  115. Dimension size = el.getSize();
  116. assertEquals("Dialog: 'dialog-test' Height is not 530px + 2px of border", 532, size.getHeight());
  117. assertEquals("Dialog: 'dialog-test' Width is not 860px + 2px of border", 862, size.getWidth());
  118. }
  119. //test that one stacking dialog works correctly
  120. @Test
  121. public void testOneStackingDialogShow()
  122. {
  123. elementFinder.find(By.id("dialog-button")).click();
  124. PageElement dialog = elementFinder.find(By.id("dialog-test"));
  125. assertTrue("The dialog should be present", dialog.isPresent());
  126. assertTrue("The dialog should be visible", dialog.isVisible());
  127. dialog.find(By.cssSelector("button.button-panel-button:nth-child(4)")).click();
  128. assertTrue("The dialog should still be present", dialog.isPresent());
  129. assertTrue("The dialog should still be visible", dialog.isVisible());
  130. PageElement stackedDialog = elementFinder.find(By.id("stack-dialog1"));
  131. assertTrue("The stacked dialog should be present", stackedDialog.isPresent());
  132. assertTrue("The stacked dialog should be visible", stackedDialog.isVisible());
  133. }
  134. //test that 2 stacking dialogs work correctly
  135. @Test
  136. public void testTwoStackingDialogsShow()
  137. {
  138. elementFinder.find(By.id("dialog-button")).click();
  139. PageElement dialog = elementFinder.find(By.id("dialog-test"));
  140. assertTrue("The dialog should be present", dialog.isPresent());
  141. assertTrue("The dialog should be visible", dialog.isVisible());
  142. dialog.find(By.cssSelector("button.button-panel-button:nth-child(4)")).click();
  143. PageElement stackedDialog = elementFinder.find(By.id("stack-dialog1"));
  144. stackedDialog.find(By.cssSelector("button.button-panel-button:nth-child(2)")).click();
  145. PageElement stackedDialog2 = elementFinder.find(By.id("stack-dialog2"));
  146. assertTrue("The dialog should be present", dialog.isPresent());
  147. assertTrue("The dialog should be visible", dialog.isVisible());
  148. assertTrue("The stacked dialog should be present", stackedDialog.isPresent());
  149. assertTrue("The stacked dialog should be visible", stackedDialog.isVisible());
  150. assertTrue("The second stacked dialog should be present", stackedDialog2.isPresent());
  151. assertTrue("The second stacked dialog should be visible", stackedDialog2.isVisible());
  152. }
  153. //test addPanel
  154. @Test
  155. public void testAddPanel()
  156. {
  157. elementFinder.find(By.id("test-add-panel-button")).click();
  158. PageElement dialog = elementFinder.find(By.id("test-panel-dialog"));
  159. assertTrue("The dialog should be present", dialog.isPresent());
  160. assertTrue("The dialog should be visible", dialog.isVisible());
  161. assertTrue("The dialog panel should be present", dialog.find(By.className("dialog-panel-body")).isPresent());
  162. }
  163. //test addButton
  164. @Test
  165. public void testAddButton()
  166. {
  167. elementFinder.find(By.id("test-add-button-button")).click();
  168. PageElement dialog = elementFinder.find(By.id("test-button-dialog"));
  169. assertTrue("The dialog should be present", dialog.isPresent());
  170. assertTrue("The dialog should be visible", dialog.isVisible());
  171. assertTrue("The dialog panel should be present", dialog.find(By.className("dialog-button-panel")).isPresent());
  172. assertTrue("The dialog panel button should be present", dialog.find(By.cssSelector("button.button-panel-button:nth-child(1)")).isPresent());
  173. }
  174. //test remove focus on hide
  175. @Test
  176. public void testDialogRemoveFocusOnHide()
  177. {
  178. AtlassianWebDriver webDriver = product.getTester().getDriver();
  179. elementFinder.find(By.id("test-remove-focus-button")).click();
  180. PageElement input = elementFinder.find(By.id("test-remove-focus-input"));
  181. waitUntilTrue(input.timed().isVisible());
  182. input.click();
  183. assertTrue(webDriver.switchTo().activeElement().getAttribute("id").equals("test-remove-focus-input"));
  184. new Actions(product.getTester().getDriver()).sendKeys(Keys.ESCAPE).perform();
  185. assertFalse(webDriver.switchTo().activeElement().getAttribute("id").equals("test-remove-focus-input"));
  186. }
  187. }