PageRenderTime 31ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/acceptance_tests/sharing_test_suite/register_and_share_1.py

https://bitbucket.org/isanneh/smart-house-web-app-isatou
Python | 188 lines | 176 code | 7 blank | 5 comment | 17 complexity | 14d4c40f45978fd63e5d853bba05f29c MD5 | raw file
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.support.ui import Select
  4. from selenium.common.exceptions import NoSuchElementException
  5. import unittest, time, re
  6. class RegisterAndShare1(unittest.TestCase):
  7. def setUp(self):
  8. self.driver = webdriver.Firefox()
  9. self.driver.implicitly_wait(30)
  10. self.base_url = "http://shwa.herokuapp.com/"
  11. self.verificationErrors = []
  12. self.accept_next_alert = True
  13. def test_register_and_share1(self):
  14. driver = self.driver
  15. driver.get(self.base_url + "/register")
  16. driver.find_element_by_link_text("Register").click()
  17. driver.find_element_by_id("first_name").clear()
  18. driver.find_element_by_id("first_name").send_keys("u")
  19. driver.find_element_by_id("last_name").clear()
  20. driver.find_element_by_id("last_name").send_keys("l")
  21. driver.find_element_by_id("email").clear()
  22. driver.find_element_by_id("email").send_keys("u1@gmail.com")
  23. driver.find_element_by_id("nickname").clear()
  24. driver.find_element_by_id("nickname").send_keys("u1")
  25. driver.find_element_by_id("password").clear()
  26. driver.find_element_by_id("password").send_keys("test")
  27. driver.find_element_by_id("confirm_password").clear()
  28. driver.find_element_by_id("confirm_password").send_keys("test")
  29. driver.find_element_by_css_selector("input.btn").click()
  30. driver.find_element_by_link_text("Register").click()
  31. driver.find_element_by_id("first_name").clear()
  32. driver.find_element_by_id("first_name").send_keys("u")
  33. driver.find_element_by_id("last_name").clear()
  34. driver.find_element_by_id("last_name").send_keys("l")
  35. driver.find_element_by_id("email").clear()
  36. driver.find_element_by_id("email").send_keys("u2@gmail.com")
  37. driver.find_element_by_id("nickname").clear()
  38. driver.find_element_by_id("nickname").send_keys("u2")
  39. driver.find_element_by_id("password").clear()
  40. driver.find_element_by_id("password").send_keys("test")
  41. driver.find_element_by_id("confirm_password").clear()
  42. driver.find_element_by_id("confirm_password").send_keys("test")
  43. driver.find_element_by_css_selector("input.btn").click()
  44. driver.find_element_by_link_text("Register").click()
  45. driver.find_element_by_id("first_name").clear()
  46. driver.find_element_by_id("first_name").send_keys("u")
  47. driver.find_element_by_id("last_name").clear()
  48. driver.find_element_by_id("last_name").send_keys("l")
  49. driver.find_element_by_id("email").clear()
  50. driver.find_element_by_id("email").send_keys("u3")
  51. driver.find_element_by_id("nickname").clear()
  52. driver.find_element_by_id("nickname").send_keys("u3")
  53. driver.find_element_by_id("password").clear()
  54. driver.find_element_by_id("password").send_keys("test")
  55. driver.find_element_by_id("confirm_password").clear()
  56. driver.find_element_by_id("confirm_password").send_keys("test")
  57. driver.find_element_by_id("email").clear()
  58. driver.find_element_by_id("email").send_keys("u3@gmail.com")
  59. driver.find_element_by_css_selector("input.btn").click()
  60. driver.find_element_by_id("email").clear()
  61. driver.find_element_by_id("email").send_keys("u1@gmail.com")
  62. driver.find_element_by_id("password").clear()
  63. driver.find_element_by_id("password").send_keys("test")
  64. driver.find_element_by_css_selector("input.btn").click()
  65. driver.find_element_by_link_text("Rooms").click()
  66. driver.find_element_by_link_text("Add room").click()
  67. driver.find_element_by_id("name").clear()
  68. driver.find_element_by_id("name").send_keys("test_room1")
  69. driver.find_element_by_id("webcam_url").clear()
  70. driver.find_element_by_id("webcam_url").send_keys("http://test.com")
  71. driver.find_element_by_css_selector("input.btn").click()
  72. driver.find_element_by_link_text("Add room").click()
  73. driver.find_element_by_id("name").clear()
  74. driver.find_element_by_id("name").send_keys("test_room2")
  75. driver.find_element_by_id("webcam_url").clear()
  76. driver.find_element_by_id("webcam_url").send_keys("http://test.com")
  77. driver.find_element_by_css_selector("input.btn").click()
  78. driver.find_element_by_link_text("Add device").click()
  79. driver.find_element_by_id("name").clear()
  80. driver.find_element_by_id("name").send_keys("test_device1")
  81. driver.find_element_by_id("url").clear()
  82. driver.find_element_by_id("url").send_keys("http://test.com/test1")
  83. driver.find_element_by_id("command").clear()
  84. driver.find_element_by_id("command").send_keys("test")
  85. driver.find_element_by_css_selector("input.btn").click()
  86. driver.find_element_by_link_text("Add device").click()
  87. driver.find_element_by_id("name").clear()
  88. driver.find_element_by_id("name").send_keys("test_device2")
  89. driver.find_element_by_id("url").clear()
  90. driver.find_element_by_id("url").send_keys("http://test.com/test2")
  91. driver.find_element_by_id("command").clear()
  92. driver.find_element_by_id("command").send_keys("test")
  93. driver.find_element_by_css_selector("input.btn").click()
  94. driver.find_element_by_xpath("(//a[contains(text(),'Add device')])[2]").click()
  95. driver.find_element_by_id("name").clear()
  96. driver.find_element_by_id("name").send_keys("test_device3")
  97. driver.find_element_by_id("url").clear()
  98. driver.find_element_by_id("url").send_keys("http://test.com/test3")
  99. driver.find_element_by_id("command").clear()
  100. driver.find_element_by_id("command").send_keys("test")
  101. driver.find_element_by_css_selector("input.btn").click()
  102. driver.find_element_by_xpath("(//a[contains(text(),'Add device')])[2]").click()
  103. driver.find_element_by_id("name").clear()
  104. driver.find_element_by_id("name").send_keys("test_device4")
  105. driver.find_element_by_id("url").clear()
  106. driver.find_element_by_id("url").send_keys("http://test.com/test4")
  107. driver.find_element_by_id("command").clear()
  108. driver.find_element_by_id("command").send_keys("test")
  109. driver.find_element_by_css_selector("input.btn").click()
  110. driver.find_element_by_link_text("Add users").click()
  111. driver.find_element_by_id("users-0-email").clear()
  112. driver.find_element_by_id("users-0-email").send_keys("u2")
  113. driver.find_element_by_id("add_user").click()
  114. driver.find_element_by_id("users-0-email").clear()
  115. driver.find_element_by_id("users-0-email").send_keys("u2@gmail.com")
  116. # ERROR: Caught exception [ReferenceError: selectLocator is not defined]
  117. driver.find_element_by_id("users-1-email").clear()
  118. driver.find_element_by_id("users-1-email").send_keys("u3@gmail.com")
  119. driver.find_element_by_css_selector("input.btn").click()
  120. driver.find_element_by_css_selector("a[alt=\"share test_device3\"]").click()
  121. driver.find_element_by_id("email").clear()
  122. driver.find_element_by_id("email").send_keys("u2@gmail.com")
  123. driver.find_element_by_css_selector("input[type=\"submit\"]").click()
  124. driver.find_element_by_css_selector("a[alt=\"share test_device3\"]").click()
  125. driver.find_element_by_id("email").clear()
  126. driver.find_element_by_id("email").send_keys("u3@gmail.com")
  127. driver.find_element_by_css_selector("input[type=\"submit\"]").click()
  128. driver.find_element_by_link_text("Sign out").click()
  129. driver.find_element_by_link_text("Sign in").click()
  130. driver.find_element_by_id("email").clear()
  131. driver.find_element_by_id("email").send_keys("u2@gmail.com")
  132. driver.find_element_by_id("password").clear()
  133. driver.find_element_by_id("password").send_keys("test")
  134. driver.find_element_by_css_selector("input.btn").click()
  135. driver.find_element_by_css_selector("a[title=\"Devices shared with me settings\"]").click()
  136. # Warning: verifyTextPresent may require manual changes
  137. try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*test_device3[\s\S]*$")
  138. except AssertionError as e: self.verificationErrors.append(str(e))
  139. driver.find_element_by_css_selector("a[title=\"Rooms shared with me settings\"]").click()
  140. # Warning: verifyTextPresent may require manual changes
  141. try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*test_room1 \(owner u1 \)[\s\S]*$")
  142. except AssertionError as e: self.verificationErrors.append(str(e))
  143. driver.find_element_by_link_text("Sign out").click()
  144. driver.find_element_by_link_text("Sign in").click()
  145. driver.find_element_by_id("email").clear()
  146. driver.find_element_by_id("email").send_keys("u3@gmail.com")
  147. driver.find_element_by_id("password").clear()
  148. driver.find_element_by_id("password").send_keys("test")
  149. driver.find_element_by_css_selector("input.btn").click()
  150. driver.find_element_by_css_selector("a[title=\"Devices shared with me settings\"]").click()
  151. # Warning: verifyTextPresent may require manual changes
  152. try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*test_device3[\s\S]*$")
  153. except AssertionError as e: self.verificationErrors.append(str(e))
  154. driver.find_element_by_css_selector("a[title=\"Rooms shared with me settings\"]").click()
  155. # Warning: verifyTextPresent may require manual changes
  156. try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*test_room1 \(owner u1 \)[\s\S]*$")
  157. except AssertionError as e: self.verificationErrors.append(str(e))
  158. driver.find_element_by_link_text("Sign out").click()
  159. def is_element_present(self, how, what):
  160. try: self.driver.find_element(by=how, value=what)
  161. except NoSuchElementException, e: return False
  162. return True
  163. def is_alert_present(self):
  164. try: self.driver.switch_to_alert()
  165. except NoAlertPresentException, e: return False
  166. return True
  167. def close_alert_and_get_its_text(self):
  168. try:
  169. alert = self.driver.switch_to_alert()
  170. alert_text = alert.text
  171. if self.accept_next_alert:
  172. alert.accept()
  173. else:
  174. alert.dismiss()
  175. return alert_text
  176. finally: self.accept_next_alert = True
  177. def tearDown(self):
  178. self.driver.quit()
  179. self.assertEqual([], self.verificationErrors)
  180. if __name__ == "__main__":
  181. unittest.main()