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