Added /tests/util directory with login/logout scripts.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_Logout.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 LogOut(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_log_out(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.button_action.header_dropdown_down"))
19         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
20         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Log out"))
21         driver.find_element_by_link_text("Log out").click()
22         try: self.assertTrue(self.is_element_present(By.LINK_TEXT, "Create an account at this site"))
23         except AssertionError as e: self.verificationErrors.append(str(e))
24         try: self.assertTrue(self.is_element_present(By.LINK_TEXT, "Log in"))
25         except AssertionError as e: self.verificationErrors.append(str(e))
26     
27     def is_element_present(self, how, what):
28         try: self.driver.find_element(by=how, value=what)
29         except NoSuchElementException, e: return False
30         return True
31     
32     def is_alert_present(self):
33         try: self.driver.switch_to_alert()
34         except NoAlertPresentException, e: return False
35         return True
36     
37     def close_alert_and_get_its_text(self):
38         try:
39             alert = self.driver.switch_to_alert()
40             alert_text = alert.text
41             if self.accept_next_alert:
42                 alert.accept()
43             else:
44                 alert.dismiss()
45             return alert_text
46         finally: self.accept_next_alert = True
47     
48     def tearDown(self):
49         self.driver.quit()
50         self.assertEqual([], self.verificationErrors)
51
52 if __name__ == "__main__":
53     unittest.main()