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
24 class DeleteCollection(unittest.TestCase):
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
32 def test_delete_collection(self):
34 driver.get(self.base_url + "/")
35 tLogin = login.Login()
36 data = {"username" : "theeraser", "password" : "Icanseeforever"}
37 tLogin.log_in(self, data)
38 try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.button_action.header_dropdown_down"))
39 except AssertionError as e: self.verificationErrors.append(str(e))
40 driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
41 self.assertTrue(self.is_element_present(By.LINK_TEXT, "theeraser"))
42 driver.find_element_by_link_text("testuser").click()
43 self.assertTrue(self.is_element_present(By.LINK_TEXT, "Browse collections"))
44 driver.find_element_by_link_text("Browse collections").click()
45 self.assertTrue(self.is_element_present(By.LINK_TEXT, "Test Collection Delete"))
46 driver.find_element_by_link_text("Test Collection Delete").click()
47 self.assertTrue(self.is_element_present(By.LINK_TEXT, "Delete"))
48 driver.find_element_by_link_text("Delete").click()
49 self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "label"))
50 driver.find_element_by_id("confirm").click()
51 self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "input.button_form"))
52 driver.find_element_by_css_selector("input.button_form").click()
53 try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "li.message_success"))
54 except AssertionError as e: self.verificationErrors.append(str(e))
56 def is_element_present(self, how, what):
57 try: self.driver.find_element(by=how, value=what)
58 except NoSuchElementException, e: return False
61 def is_alert_present(self):
62 try: self.driver.switch_to_alert()
63 except NoAlertPresentException, e: return False
66 def close_alert_and_get_its_text(self):
68 alert = self.driver.switch_to_alert()
69 alert_text = alert.text
70 if self.accept_next_alert:
75 finally: self.accept_next_alert = True
79 self.assertEqual([], self.verificationErrors)
81 if __name__ == "__main__":