Added login call to each file. (Some still need users added to data.ini).
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_Logout.py
1 from util import login
2 from selenium import webdriver
3 from selenium.webdriver.common.by import By
4 from selenium.webdriver.support.ui import Select
5 from selenium.common.exceptions import NoSuchElementException
6 import unittest, time, re
7
8 class LogOut(unittest.TestCase):
9     def setUp(self):
10         self.driver = webdriver.Firefox()
11         self.driver.implicitly_wait(30)
12         self.base_url = "http://127.0.0.1:6543/"
13         self.verificationErrors = []
14         self.accept_next_alert = True
15     
16     def test_log_out(self):
17         driver = self.driver
18         driver.get(self.base_url + "/")
19         tLogin = login.Login()
20         data = {"username" : "testlogout", "password" : "OkayTestingPassworD42"}
21         tLogin.log_in(self, data)
22         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.button_action.header_dropdown_down"))
23         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
24         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Log out"))
25         driver.find_element_by_link_text("Log out").click()
26         try: self.assertTrue(self.is_element_present(By.LINK_TEXT, "Create an account at this site"))
27         except AssertionError as e: self.verificationErrors.append(str(e))
28         try: self.assertTrue(self.is_element_present(By.LINK_TEXT, "Log in"))
29         except AssertionError as e: self.verificationErrors.append(str(e))
30     
31     def is_element_present(self, how, what):
32         try: self.driver.find_element(by=how, value=what)
33         except NoSuchElementException, e: return False
34         return True
35     
36     def is_alert_present(self):
37         try: self.driver.switch_to_alert()
38         except NoAlertPresentException, e: return False
39         return True
40     
41     def close_alert_and_get_its_text(self):
42         try:
43             alert = self.driver.switch_to_alert()
44             alert_text = alert.text
45             if self.accept_next_alert:
46                 alert.accept()
47             else:
48                 alert.dismiss()
49             return alert_text
50         finally: self.accept_next_alert = True
51     
52     def tearDown(self):
53         self.driver.quit()
54         self.assertEqual([], self.verificationErrors)
55
56 if __name__ == "__main__":
57     unittest.main()