Added login call to each file. (Some still need users added to data.ini).
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_EditCollection.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 EditCollection(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_edit_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, "Edit Collection"))
30         driver.find_element_by_link_text("Edit Collection").click()
31         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Edit"))
32         driver.find_element_by_link_text("Edit").click()
33         driver.find_element_by_id("title").send_keys("Edited Collection")
34         driver.find_element_by_id("description").clear()
35         driver.find_element_by_id("description").send_keys("This has been edited.")
36         driver.find_element_by_id("slug").send_keys("edited-collection")
37         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
38         driver.find_element_by_css_selector("input.button_form").click()
39         try: self.assertEqual("This has been edited.", driver.find_element_by_xpath("//p[2]").text)
40         except AssertionError as e: self.verificationErrors.append(str(e))
41         try: self.assertEqual("Edited Collection by testuser", driver.find_element_by_css_selector("h1").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()