Fixed more typos.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / upload.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, helper
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, os
24
25 class UploadFile():  
26     def upload(self, data, phantomjs):
27         '''Uploads a given file.
28
29             The data dictionary contains the following keys:
30             username, password, uri, title, description, tags, license
31
32         '''
33         self.driver = webdriver.PhantomJS(phantomjs)
34         self.driver.implicitly_wait(30)
35         self.base_url = "http://127.0.0.1:6543"
36         self.accept_next_alert = True
37
38         driver = self.driver
39         tLogin = login.Login()
40         testharness = unittest.FunctionTestCase(self)
41         testharness.verificationErrors = []
42
43         tLogin.log_in(self, data)
44         driver.get(self.base_url + "/")
45         driver.find_element_by_link_text(u"▼").click()
46         testharness.assertTrue(helper.is_element_present(self,By.LINK_TEXT, "Add media"))
47         driver.find_element_by_link_text("Add media").click()
48         # Warning: verifyTextPresent may require manual changes
49         try: testharness.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
50         except AssertionError as e: testharness.verificationErrors.append(str(e))
51         testharness.assertTrue(helper.is_element_present(self,By.ID, "file"))
52         #driver.execute_script("document.getElementById('file').value=" + "WORKING_DIRECTORY/resources/" + data["uri"] +";")
53         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/" + data["uri"])
54         testharness.assertTrue(helper.is_element_present(self,By.ID, "title"))
55         driver.find_element_by_id("title").clear()
56         driver.find_element_by_id("title").send_keys(data["title"])
57         driver.find_element_by_id("description").clear()
58         driver.find_element_by_id("description").send_keys(data["description"])
59         driver.find_element_by_id("tags").clear()
60         driver.find_element_by_id("tags").send_keys(data["tags"])
61         select = Select(driver.find_element_by_id("license"))
62         select.select_by_visible_text(data["license"])
63         testharness.assertTrue(helper.is_element_present(self,By.ID, "license"))
64         testharness.assertTrue(helper.is_element_present(self,By.ID, "tags"))
65         testharness.assertTrue(helper.is_element_present(self,By.CSS_SELECTOR, "input.button_form"))
66         driver.find_element_by_css_selector("input.button_form").click()
67         testharness.assertTrue(helper.is_element_present(self,By.LINK_TEXT, data["title"]))
68         driver.quit()