Added login call to each file. (Some still need users added to data.ini).
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_AddMediaToCollection.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 AddMediaToCollection(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_add_media_to_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         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, "Add to a collection"))
25         driver.find_element_by_link_text("Add to a collection").click()
26         self.assertTrue(self.is_element_present(By.ID, "button_addcollection"))
27         driver.find_element_by_id("button_addcollection").click()
28         try: self.assertTrue(self.is_element_present(By.ID, "collection_title"))
29         except AssertionError as e: self.verificationErrors.append(str(e))
30         driver.find_element_by_id("collection_title").send_keys("Test Collection")
31         try: self.assertTrue(self.is_element_present(By.ID, "collection_description"))
32         except AssertionError as e: self.verificationErrors.append(str(e))
33         driver.find_element_by_id("collection_description").clear()
34         driver.find_element_by_id("collection_description").send_keys("This is a test of the collections")
35         try: self.assertTrue(self.is_element_present(By.ID, "note"))
36         except AssertionError as e: self.verificationErrors.append(str(e))
37         driver.find_element_by_id("note").clear()
38         driver.find_element_by_id("note").send_keys("This is a note")
39         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
40         driver.find_element_by_css_selector("input.button_form").click()
41         try: self.assertEqual("\"Gavroche Test\" added to collection \"Test Collection\"", driver.find_element_by_css_selector("li.message_success").text)
42         except AssertionError as e: self.verificationErrors.append(str(e))
43     
44     def is_element_present(self, how, what):
45         try: self.driver.find_element(by=how, value=what)
46         except NoSuchElementException, e: return False
47         return True
48     
49     def is_alert_present(self):
50         try: self.driver.switch_to_alert()
51         except NoAlertPresentException, e: return False
52         return True
53     
54     def close_alert_and_get_its_text(self):
55         try:
56             alert = self.driver.switch_to_alert()
57             alert_text = alert.text
58             if self.accept_next_alert:
59                 alert.accept()
60             else:
61                 alert.dismiss()
62             return alert_text
63         finally: self.accept_next_alert = True
64     
65     def tearDown(self):
66         self.driver.quit()
67         self.assertEqual([], self.verificationErrors)
68
69 if __name__ == "__main__":
70     unittest.main()