Added basic exported Python webdriver scripts from HTML.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_CheckNotifications.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 CheckNotifications(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_check_notifications(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         self.assertTrue(self.is_element_present(By.LINK_TEXT, "1"))
19         driver.find_element_by_link_text("1").click()
20         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
21         try: self.assertEqual("This is a test comment.", driver.find_element_by_css_selector("div.comment_content > p").text)
22         except AssertionError as e: self.verificationErrors.append(str(e))
23     
24     def is_element_present(self, how, what):
25         try: self.driver.find_element(by=how, value=what)
26         except NoSuchElementException, e: return False
27         return True
28     
29     def is_alert_present(self):
30         try: self.driver.switch_to_alert()
31         except NoAlertPresentException, e: return False
32         return True
33     
34     def close_alert_and_get_its_text(self):
35         try:
36             alert = self.driver.switch_to_alert()
37             alert_text = alert.text
38             if self.accept_next_alert:
39                 alert.accept()
40             else:
41                 alert.dismiss()
42             return alert_text
43         finally: self.accept_next_alert = True
44     
45     def tearDown(self):
46         self.driver.quit()
47         self.assertEqual([], self.verificationErrors)
48
49 if __name__ == "__main__":
50     unittest.main()