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
7 class LogOut(unittest.TestCase):
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
15 def test_log_out(self):
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))
27 def is_element_present(self, how, what):
28 try: self.driver.find_element(by=how, value=what)
29 except NoSuchElementException, e: return False
32 def is_alert_present(self):
33 try: self.driver.switch_to_alert()
34 except NoAlertPresentException, e: return False
37 def close_alert_and_get_its_text(self):
39 alert = self.driver.switch_to_alert()
40 alert_text = alert.text
41 if self.accept_next_alert:
46 finally: self.accept_next_alert = True
50 self.assertEqual([], self.verificationErrors)
52 if __name__ == "__main__":