Added login call to each file. (Some still need users added to data.ini).
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_UploadGIF.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 UploadAnimatedGIF(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_upload_animated_g_i_f(self):
17         driver = self.driver
18         driver.get(self.base_url + "/")
19         tLogin = login.Login()
20         data = {"username" : "testuploader", "password" : "GreatTestingPassword!5"}
21         tLogin.log_in(self, data)
22         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
23         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Add media"))
24         driver.find_element_by_link_text("Add media").click()
25         # Warning: verifyTextPresent may require manual changes
26         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
27         except AssertionError as e: self.verificationErrors.append(str(e))
28         self.assertTrue(self.is_element_present(By.ID, "file"))
29         driver.find_element_by_id("file").clear()
30         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/PD_Penrose_triangle.gif")
31         self.assertTrue(self.is_element_present(By.ID, "title"))
32         driver.find_element_by_id("title").clear()
33         driver.find_element_by_id("title").send_keys("Penrose Triangle")
34         driver.find_element_by_id("description").clear()
35         driver.find_element_by_id("description").send_keys("This is automatically uploaded by the Selenium scripts")
36         driver.find_element_by_id("tags").clear()
37         driver.find_element_by_id("tags").send_keys("selenium,testing,animated,geometry")
38         # ERROR: Caught exception [ReferenceError: selectLocator is not defined]
39         self.assertTrue(self.is_element_present(By.ID, "license"))
40         self.assertTrue(self.is_element_present(By.ID, "tags"))
41         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
42         driver.find_element_by_css_selector("input.button_form").click()
43         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Gavroche Test"))
44     
45     def is_element_present(self, how, what):
46         try: self.driver.find_element(by=how, value=what)
47         except NoSuchElementException, e: return False
48         return True
49     
50     def is_alert_present(self):
51         try: self.driver.switch_to_alert()
52         except NoAlertPresentException, e: return False
53         return True
54     
55     def close_alert_and_get_its_text(self):
56         try:
57             alert = self.driver.switch_to_alert()
58             alert_text = alert.text
59             if self.accept_next_alert:
60                 alert.accept()
61             else:
62                 alert.dismiss()
63             return alert_text
64         finally: self.accept_next_alert = True
65     
66     def tearDown(self):
67         self.driver.quit()
68         self.assertEqual([], self.verificationErrors)
69
70 if __name__ == "__main__":
71     unittest.main()