Added basic exported Python webdriver scripts from HTML.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_EditMediaItem.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 EditMediaItem(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_media_item(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Penrose Triangle"))
19         driver.find_element_by_link_text("Penrose Triangle").click()
20         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Edit"))
21         driver.find_element_by_link_text("Edit").click()
22         driver.find_element_by_id("title").send_keys("Penrose Triangle Edit")
23         # ERROR: Caught exception [ReferenceError: selectLocator is not defined]
24         driver.find_element_by_css_selector("input.button_form").click()
25         try: self.assertEqual("Penrose Triangle Edit", driver.find_element_by_css_selector("h2.media_title").text)
26         except AssertionError as e: self.verificationErrors.append(str(e))
27         try: self.assertEqual("CC0 1.0", driver.find_element_by_link_text("CC0 1.0").text)
28         except AssertionError as e: self.verificationErrors.append(str(e))
29     
30     def is_element_present(self, how, what):
31         try: self.driver.find_element(by=how, value=what)
32         except NoSuchElementException, e: return False
33         return True
34     
35     def is_alert_present(self):
36         try: self.driver.switch_to_alert()
37         except NoAlertPresentException, e: return False
38         return True
39     
40     def close_alert_and_get_its_text(self):
41         try:
42             alert = self.driver.switch_to_alert()
43             alert_text = alert.text
44             if self.accept_next_alert:
45                 alert.accept()
46             else:
47                 alert.dismiss()
48             return alert_text
49         finally: self.accept_next_alert = True
50     
51     def tearDown(self):
52         self.driver.quit()
53         self.assertEqual([], self.verificationErrors)
54
55 if __name__ == "__main__":
56     unittest.main()