Added basic exported Python webdriver scripts from HTML.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_EditCollection.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 EditCollection(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_edit_collection(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.button_action.header_dropdown_down"))
19         except AssertionError as e: self.verificationErrors.append(str(e))
20         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
21         self.assertTrue(self.is_element_present(By.LINK_TEXT, "testuser"))
22         driver.find_element_by_link_text("testuser").click()
23         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Browse collections"))
24         driver.find_element_by_link_text("Browse collections").click()
25         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Edit Collection"))
26         driver.find_element_by_link_text("Edit Collection").click()
27         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Edit"))
28         driver.find_element_by_link_text("Edit").click()
29         driver.find_element_by_id("title").send_keys("Edited Collection")
30         driver.find_element_by_id("description").clear()
31         driver.find_element_by_id("description").send_keys("This has been edited.")
32         driver.find_element_by_id("slug").send_keys("edited-collection")
33         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
34         driver.find_element_by_css_selector("input.button_form").click()
35         try: self.assertEqual("This has been edited.", driver.find_element_by_xpath("//p[2]").text)
36         except AssertionError as e: self.verificationErrors.append(str(e))
37         try: self.assertEqual("Edited Collection by testuser", driver.find_element_by_css_selector("h1").text)
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()