Initial version of the mediagoblin-selenium tool chain.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_ForgotPassword.py
1 import pytest
2 try:
3     import selenium
4     from selenium import webdriver
5     from selenium.webdriver.common.by import By
6     from selenium.webdriver.support.ui import Select
7     from selenium.common.exceptions import NoSuchElementException
8     import unittest, time, re
9
10     @pytest.mark.skipif("selenium.__version__ < '2.33'")
11     class ForgotPassword(unittest.TestCase):
12         def setUp(self):
13             self.driver = webdriver.Firefox()
14             self.driver.implicitly_wait(30)
15             self.base_url = "http://127.0.0.1:6543"
16             self.verificationErrors = []
17             self.accept_next_alert = True
18         
19         def test_forgot_password(self):
20             driver = self.driver
21             driver.get(self.base_url + "/")
22             driver.find_element_by_link_text("Log in").click()
23             driver.find_element_by_id("forgot_password").click()
24             # Warning: verifyTextPresent may require manual changes
25             try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Recover password[\s\S]*$")
26             except AssertionError as e: self.verificationErrors.append(str(e))
27         
28         def is_element_present(self, how, what):
29             try: self.driver.find_element(by=how, value=what)
30             except NoSuchElementException, e: return False
31             return True
32         
33         def is_alert_present(self):
34             try: self.driver.switch_to_alert()
35             except NoAlertPresentException, e: return False
36             return True
37         
38         def close_alert_and_get_its_text(self):
39             try:
40                 alert = self.driver.switch_to_alert()
41                 alert_text = alert.text
42                 if self.accept_next_alert:
43                     alert.accept()
44                 else:
45                     alert.dismiss()
46                 return alert_text
47             finally: self.accept_next_alert = True
48         
49         def tearDown(self):
50             self.driver.quit()
51             self.assertEqual([], self.verificationErrors)
52
53     if __name__ == "__main__":
54         unittest.main()
55 except ImportError:
56     pytester = pytest.mark.skip()