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