Added #!/usr/bin/env python to tests.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_ForgotPassword.py
1 #!/usr/bin/env python
2 '''
3    Copyright 2013 Emily O'Leary
4
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
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
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.
16 '''
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
22
23 class ForgotPassword(unittest.TestCase):
24     def setUp(self):
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
30     
31     def test_forgot_password(self):
32         driver = self.driver
33         driver.get(self.base_url + "/")
34         driver.find_element_by_link_text("Log in").click()
35         driver.find_element_by_id("forgot_password").click()
36         # Warning: verifyTextPresent may require manual changes
37         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Recover password[\s\S]*$")
38         except AssertionError as e: self.verificationErrors.append(str(e))
39     
40     def is_element_present(self, how, what):
41         try: self.driver.find_element(by=how, value=what)
42         except NoSuchElementException, e: return False
43         return True
44     
45     def is_alert_present(self):
46         try: self.driver.switch_to_alert()
47         except NoAlertPresentException, e: return False
48         return True
49     
50     def close_alert_and_get_its_text(self):
51         try:
52             alert = self.driver.switch_to_alert()
53             alert_text = alert.text
54             if self.accept_next_alert:
55                 alert.accept()
56             else:
57                 alert.dismiss()
58             return alert_text
59         finally: self.accept_next_alert = True
60     
61     def tearDown(self):
62         self.driver.quit()
63         self.assertEqual([], self.verificationErrors)
64
65 if __name__ == "__main__":
66     unittest.main()