Added /tests/util directory with login/logout scripts.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_UploadPNG.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 UploadPNG(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_upload_p_n_g(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
19         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Add media"))
20         driver.find_element_by_link_text("Add media").click()
21         # Warning: verifyTextPresent may require manual changes
22         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
23         except AssertionError as e: self.verificationErrors.append(str(e))
24         self.assertTrue(self.is_element_present(By.ID, "file"))
25         driver.find_element_by_id("file").clear()
26         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/CC0_home_goblin.png")
27         self.assertTrue(self.is_element_present(By.ID, "title"))
28         driver.find_element_by_id("title").clear()
29         driver.find_element_by_id("title").send_keys("Home Page Gavroche Test")
30         driver.find_element_by_id("description").clear()
31         driver.find_element_by_id("description").send_keys("This is automatically uploaded by the Selenium scripts")
32         driver.find_element_by_id("tags").clear()
33         driver.find_element_by_id("tags").send_keys("selenium testing gavroche homepage")
34         # ERROR: Caught exception [ReferenceError: selectLocator is not defined]
35         self.assertTrue(self.is_element_present(By.ID, "license"))
36         self.assertTrue(self.is_element_present(By.ID, "tags"))
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         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Gavroche Test"))
40     
41     def is_element_present(self, how, what):
42         try: self.driver.find_element(by=how, value=what)
43         except NoSuchElementException, e: return False
44         return True
45     
46     def is_alert_present(self):
47         try: self.driver.switch_to_alert()
48         except NoAlertPresentException, e: return False
49         return True
50     
51     def close_alert_and_get_its_text(self):
52         try:
53             alert = self.driver.switch_to_alert()
54             alert_text = alert.text
55             if self.accept_next_alert:
56                 alert.accept()
57             else:
58                 alert.dismiss()
59             return alert_text
60         finally: self.accept_next_alert = True
61     
62     def tearDown(self):
63         self.driver.quit()
64         self.assertEqual([], self.verificationErrors)
65
66 if __name__ == "__main__":
67     unittest.main()