Updated documentation / scripts / compiled selenium scripts.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_CreateAccount.py
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
7 class CreateAccount(unittest.TestCase):
8     def setUp(self):
9         self.driver = webdriver.Firefox()
10         self.driver.implicitly_wait(30)
11         self.base_url = "http://127.0.0.1:6543"
12         self.verificationErrors = []
13         self.accept_next_alert = True
14     
15     def test_create_account(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         driver.find_element_by_link_text("Create an account at this site").click()
19         # Warning: verifyTextPresent may require manual changes
20         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Create an account[\s\S]*$")
21         except AssertionError as e: self.verificationErrors.append(str(e))
22         self.assertTrue(self.is_element_present(By.ID, "username"))
23         self.assertTrue(self.is_element_present(By.ID, "password"))
24         self.assertTrue(self.is_element_present(By.ID, "email"))
25         driver.find_element_by_id("username").clear()
26         driver.find_element_by_id("username").send_keys("TestUser")
27         driver.find_element_by_id("password").clear()
28         driver.find_element_by_id("password").send_keys("TestPassword!1")
29         driver.find_element_by_id("email").clear()
30         driver.find_element_by_id("email").send_keys("gmgtests@failbox.org")
31         driver.find_element_by_css_selector("input.button_form").click()
32         # Warning: verifyTextPresent may require manual changes
33         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Email verification needed[\s\S]*$")
34         except AssertionError as e: self.verificationErrors.append(str(e))
35     
36     def is_element_present(self, how, what):
37         try: self.driver.find_element(by=how, value=what)
38         except NoSuchElementException, e: return False
39         return True
40     
41     def is_alert_present(self):
42         try: self.driver.switch_to_alert()
43         except NoAlertPresentException, e: return False
44         return True
45     
46     def close_alert_and_get_its_text(self):
47         try:
48             alert = self.driver.switch_to_alert()
49             alert_text = alert.text
50             if self.accept_next_alert:
51                 alert.accept()
52             else:
53                 alert.dismiss()
54             return alert_text
55         finally: self.accept_next_alert = True
56     
57     def tearDown(self):
58         self.driver.quit()
59         self.assertEqual([], self.verificationErrors)
60
61 if __name__ == "__main__":
62     unittest.main()