Fixed more typos.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_ForgotPassword.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 '''
4    Copyright 2013 Emily O'Leary
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 '''
18 from selenium import webdriver
19 from selenium.webdriver.common.by import By
20 from selenium.webdriver.support.ui import Select
21 from selenium.common.exceptions import NoSuchElementException
22 import unittest, time, re
23
24 class ForgotPassword(unittest.TestCase):
25     def setUp(self):
26         self.driver = webdriver.Firefox()
27         self.driver.implicitly_wait(30)
28         self.base_url = "http://127.0.0.1:6543"
29         self.verificationErrors = []
30         self.accept_next_alert = True
31     
32     def test_forgot_password(self):
33         driver = self.driver
34         driver.get(self.base_url + "/")
35         driver.find_element_by_link_text("Log in").click()
36         driver.find_element_by_id("forgot_password").click()
37         # Warning: verifyTextPresent may require manual changes
38         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Recover password[\s\S]*$")
39         except AssertionError as e: self.verificationErrors.append(str(e))
40     
41     def is_element_present(self, how, what):
42         try: self.driver.find_element(by=how, value=what)
43         except NoSuchElementException, e: return False
44         return True
45     
46     def is_alert_present(self):
47         try: self.driver.switch_to_alert()
48         except NoAlertPresentException, e: return False
49         return True
50     
51     def close_alert_and_get_its_text(self):
52         try:
53             alert = self.driver.switch_to_alert()
54             alert_text = alert.text
55             if self.accept_next_alert:
56                 alert.accept()
57             else:
58                 alert.dismiss()
59             return alert_text
60         finally: self.accept_next_alert = True
61     
62     def tearDown(self):
63         self.driver.quit()
64         self.assertEqual([], self.verificationErrors)
65
66 if __name__ == "__main__":
67     unittest.main()