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