Added method to batch upload at the start of the
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / upload.py
1 #!/usr/bin/env python
2
3 # GNU MediaGoblin Selenium Automation
4 # Copyright (C) 2013 Emily O'Leary
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # This file is a modified version of the Log In test case for re-use throughout
20 # test cases. See ContributingTests.txt
21 import util
22 from selenium import webdriver
23 from selenium.webdriver.common.by import By
24 from selenium.webdriver.support.ui import Select
25 from selenium.common.exceptions import NoSuchElementException
26 import unittest, time, re
27
28 class UploadFile():  
29     def upload(self,data):
30         '''Uploads a given file.
31
32             The data dictionary contains the following keys:
33             username, password, uri, title, description, tags, license
34
35         '''
36         driver = self.driver
37         tLogin = login.Login()
38         testharness = unittest.FunctionTestCase(self)
39
40         tLogin.log_in(self, data)
41         driver.get(self.base_url + "/")
42         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
43         testharness.assertTrue(util.is_element_present(self,By.LINK_TEXT, "Add media"))
44         driver.find_element_by_link_text("Add media").click()
45         # Warning: verifyTextPresent may require manual changes
46         try: testharness.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Add your media[\s\S]*$")
47         except AssertionError as e: self.verificationErrors.append(str(e))
48         testharness.assertTrue(util.is_element_present(self,By.ID, "file"))
49         driver.find_element_by_id("file").clear()
50         driver.find_element_by_id("file").send_keys("WORKING_DIRECTORY/resources/" + data["uri"])
51         testharness.assertTrue(util.is_element_present(self,By.ID, "title"))
52         driver.find_element_by_id("title").clear()
53         driver.find_element_by_id("title").send_keys(data["title"])
54         driver.find_element_by_id("description").clear()
55         driver.find_element_by_id("description").send_keys(data["description"])
56         driver.find_element_by_id("tags").clear()
57         driver.find_element_by_id("tags").send_keys(data["tags"])
58         select = Select(driver.find_element_by_id("license"))
59         select.select_by_visible_text(data["license"])
60         testharness.assertTrue(util.is_element_present(self,By.ID, "license"))
61         testharness.assertTrue(util.is_element_present(self,By.ID, "tags"))
62         testharness.assertTrue(util.is_element_present(self,By.CSS_SELECTOR, "input.button_form"))
63         driver.find_element_by_css_selector("input.button_form").click()
64         testharness.assertTrue(util.is_element_present(self,By.LINK_TEXT, data["title"]))