3 Copyright 2013 Emily O'Leary
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 from selenium import webdriver
18 from selenium.webdriver.common.by import By
19 from selenium.webdriver.support.ui import Select
20 from selenium.common.exceptions import NoSuchElementException
21 import unittest, time, re
23 class CreateAccount(unittest.TestCase):
25 self.driver = webdriver.Firefox()
26 self.driver.implicitly_wait(30)
27 self.base_url = "http://127.0.0.1:6543"
28 self.verificationErrors = []
29 self.accept_next_alert = True
31 def test_create_account(self):
33 driver.get(self.base_url + "/")
34 driver.find_element_by_link_text("Create an account at this site").click()
35 # Warning: verifyTextPresent may require manual changes
36 try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Create an account[\s\S]*$")
37 except AssertionError as e: self.verificationErrors.append(str(e))
38 self.assertTrue(self.is_element_present(By.ID, "username"))
39 self.assertTrue(self.is_element_present(By.ID, "password"))
40 self.assertTrue(self.is_element_present(By.ID, "email"))
41 driver.find_element_by_id("username").clear()
42 driver.find_element_by_id("username").send_keys("TestUser")
43 driver.find_element_by_id("password").clear()
44 driver.find_element_by_id("password").send_keys("TestPassword!1")
45 driver.find_element_by_id("email").clear()
46 driver.find_element_by_id("email").send_keys("gmgtests@failbox.org")
47 driver.find_element_by_css_selector("input.button_form").click()
48 # Warning: verifyTextPresent may require manual changes
49 try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Email verification needed[\s\S]*$")
50 except AssertionError as e: self.verificationErrors.append(str(e))
52 def is_element_present(self, how, what):
53 try: self.driver.find_element(by=how, value=what)
54 except NoSuchElementException, e: return False
57 def is_alert_present(self):
58 try: self.driver.switch_to_alert()
59 except NoAlertPresentException, e: return False
62 def close_alert_and_get_its_text(self):
64 alert = self.driver.switch_to_alert()
65 alert_text = alert.text
66 if self.accept_next_alert:
71 finally: self.accept_next_alert = True
75 self.assertEqual([], self.verificationErrors)
77 if __name__ == "__main__":