Added login call to each file. (Some still need users added to data.ini).
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_DeleteCollection.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 DeleteCollection(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_delete_collection(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         try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.button_action.header_dropdown_down"))
23         except AssertionError as e: self.verificationErrors.append(str(e))
24         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
25         self.assertTrue(self.is_element_present(By.LINK_TEXT, "testuser"))
26         driver.find_element_by_link_text("testuser").click()
27         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Browse collections"))
28         driver.find_element_by_link_text("Browse collections").click()
29         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Test Collection Delete"))
30         driver.find_element_by_link_text("Test Collection Delete").click()
31         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Delete"))
32         driver.find_element_by_link_text("Delete").click()
33         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "label"))
34         driver.find_element_by_id("confirm").click()
35         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
36         driver.find_element_by_css_selector("input.button_form").click()
37         try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "li.message_success"))
38         except AssertionError as e: self.verificationErrors.append(str(e))
39     
40     def is_element_present(self, how, what):
41         try: self.driver.find_element(by=how, value=what)
42         except NoSuchElementException, e: return False
43         return True
44     
45     def is_alert_present(self):
46         try: self.driver.switch_to_alert()
47         except NoAlertPresentException, e: return False
48         return True
49     
50     def close_alert_and_get_its_text(self):
51         try:
52             alert = self.driver.switch_to_alert()
53             alert_text = alert.text
54             if self.accept_next_alert:
55                 alert.accept()
56             else:
57                 alert.dismiss()
58             return alert_text
59         finally: self.accept_next_alert = True
60     
61     def tearDown(self):
62         self.driver.quit()
63         self.assertEqual([], self.verificationErrors)
64
65 if __name__ == "__main__":
66     unittest.main()