3 Copyright 2013 Emily O'Leary
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
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
25 def create_by_adding(self, data):
26 '''Creates a collection by adding a media item to it.
28 The data dictionary contains the following keys:
29 username, password, mediatitle, collectiontitle, description, note
32 self.driver = webdriver.Firefox()
33 self.driver.implicitly_wait(30)
34 self.base_url = "http://127.0.0.1:6543"
35 self.verificationErrors = []
36 self.accept_next_alert = True
39 tLogin = login.Login()
40 tLogin.log_in(self, data)
41 testharness = unittest.FunctionTestCase(self)
43 driver.get(self.base_url + "/")
45 testharness.assertTrue(self.is_element_present(By.LINK_TEXT, data["mediatitle"]))
46 driver.find_element_by_link_text("Gavroche Test").click()
47 testharness.assertTrue(self.is_element_present(By.LINK_TEXT, "Add to a collection"))
48 driver.find_element_by_link_text("Add to a collection").click()
49 testharness.assertTrue(self.is_element_present(By.ID, "button_addcollection"))
50 driver.find_element_by_id("button_addcollection").click()
51 try: testharness.assertTrue(self.is_element_present(By.ID, "collection_title"))
52 except AssertionError as e: self.verificationErrors.append(str(e))
53 driver.find_element_by_id("collection_title").send_keys(data["collectiontitle"])
54 try: testharness.assertTrue(self.is_element_present(By.ID, "collection_description"))
55 except AssertionError as e: self.verificationErrors.append(str(e))
56 driver.find_element_by_id("collection_description").clear()
57 driver.find_element_by_id("collection_description").send_keys(data["description"])
58 try: testharness.assertTrue(self.is_element_present(By.ID, "note"))
59 except AssertionError as e: self.verificationErrors.append(str(e))
60 driver.find_element_by_id("note").clear()
61 driver.find_element_by_id("note").send_keys(data["note"])
62 testharness.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
63 driver.find_element_by_css_selector("input.button_form").click()
64 try: testharness.assertEqual("\""+ data["mediatitle"] +"\" added to collection \"" + data["collectiontitle"] + "\"", driver.find_element_by_css_selector("li.message_success").text)
65 except AssertionError as e: self.verificationErrors.append(str(e))