Reverted changes to upload and collection. Issue existed in login/logout. Fixed.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_UploadGIF.py
1 #!/usr/bin/env python
2 '''
3    Copyright 2013 Emily O'Leary
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 '''
17 from util import login
18 from selenium import webdriver
19 from selenium.webdriver.common.by import By
20 from selenium.webdriver.support.ui import Select
21 from selenium.common.exceptions import NoSuchElementException
22 import unittest, time, re
23
24 class UploadAnimatedGIF(unittest.TestCase):
25     def setUp(self):
26         self.driver = webdriver.Firefox()
27         self.driver.implicitly_wait(30)
28         self.base_url = "http://127.0.0.1:6543"
29         self.verificationErrors = []
30         self.accept_next_alert = True
31     
32     def test_upload_animated_g_i_f(self):
33         driver = self.driver
34         driver.get(self.base_url + "/")
35         tLogin = login.Login()
36         data = {"username" : "testuploader", "password" : "GreatTestingPassword!5"}
37         tLogin.log_in(self, data)
38         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
39         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Add media"))
40         driver.find_element_by_link_text("Add media").click()
41         # Warning: verifyTextPresent may require manual changes
42         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
43         except AssertionError as e: self.verificationErrors.append(str(e))
44         self.assertTrue(self.is_element_present(By.ID, "file"))
45         driver.find_element_by_id("file").clear()
46         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/PD_Penrose_triangle.gif")
47         self.assertTrue(self.is_element_present(By.ID, "title"))
48         driver.find_element_by_id("title").clear()
49         driver.find_element_by_id("title").send_keys("Penrose Triangle")
50         driver.find_element_by_id("description").clear()
51         driver.find_element_by_id("description").send_keys("This is automatically uploaded by the Selenium scripts")
52         driver.find_element_by_id("tags").clear()
53         driver.find_element_by_id("tags").send_keys("selenium,testing,animated,geometry")
54         select = Select(driver.find_element_by_id("license"))
55         select.select_by_visible_text("Public Domain")
56         self.assertTrue(self.is_element_present(By.ID, "license"))
57         self.assertTrue(self.is_element_present(By.ID, "tags"))
58         self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
59         driver.find_element_by_css_selector("input.button_form").click()
60         self.assertTrue(self.is_element_present(By.LINK_TEXT, "Penrose Triangle"))
61     
62     def is_element_present(self, how, what):
63         try: self.driver.find_element(by=how, value=what)
64         except NoSuchElementException, e: return False
65         return True
66     
67     def is_alert_present(self):
68         try: self.driver.switch_to_alert()
69         except NoAlertPresentException, e: return False
70         return True
71     
72     def close_alert_and_get_its_text(self):
73         try:
74             alert = self.driver.switch_to_alert()
75             alert_text = alert.text
76             if self.accept_next_alert:
77                 alert.accept()
78             else:
79                 alert.dismiss()
80             return alert_text
81         finally: self.accept_next_alert = True
82     
83     def tearDown(self):
84         self.driver.quit()
85         self.assertEqual([], self.verificationErrors)
86
87 if __name__ == "__main__":
88     unittest.main()