Added login call to each file. (Some still need users added to data.ini).
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_SilenceComments.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 SilenceComments(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_silence_comments(self):
17         driver = self.driver
18         driver.get(self.base_url + "/")
19         tLogin = login.Login()
20         #data = {"username" : "", "password" : ""}
21         tLogin.log_in(self, data)
22         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Gavroche Test"))
23         driver.find_element_by_link_text("Gavroche Test").click()
24         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Silence comments"))
25         driver.find_element_by_link_text("Silence comments").click()
26         try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "li.message_success"))
27         except AssertionError as e: self.verificationErrors.append(str(e))
28     
29     def is_element_present(self, how, what):
30         try: self.driver.find_element(by=how, value=what)
31         except NoSuchElementException, e: return False
32         return True
33     
34     def is_alert_present(self):
35         try: self.driver.switch_to_alert()
36         except NoAlertPresentException, e: return False
37         return True
38     
39     def close_alert_and_get_its_text(self):
40         try:
41             alert = self.driver.switch_to_alert()
42             alert_text = alert.text
43             if self.accept_next_alert:
44                 alert.accept()
45             else:
46                 alert.dismiss()
47             return alert_text
48         finally: self.accept_next_alert = True
49     
50     def tearDown(self):
51         self.driver.quit()
52         self.assertEqual([], self.verificationErrors)
53
54 if __name__ == "__main__":
55     unittest.main()