More script cleanup
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / login.py
1 '''
2    Copyright 2013 Emily O'Leary
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 '''
16 import util
17 from selenium import webdriver
18 from selenium.webdriver.common.by import By
19 from selenium.webdriver.support.ui import Select
20 from selenium.common.exceptions import NoSuchElementException
21 import unittest, time, re
22
23 class Login():
24     def log_in(self, external, data):
25         self.driver = external.driver
26         self.driver.implicitly_wait(30)
27         self.base_url = external.base_url
28         self.verificationErrors = []
29         self.accept_next_alert = True
30         driver = self.driver
31         driver.get(self.base_url + "/")
32         driver.find_element_by_link_text("Log in").click()
33         driver.find_element_by_id("username").clear()
34         driver.find_element_by_id("username").send_keys(data["username"])
35         driver.find_element_by_id("password").clear()
36         driver.find_element_by_id("password").send_keys(data["password"])
37         # Warning: verifyTextPresent may require manual changes
38         try: external.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Log in[\s\S]*$")
39         except AssertionError as e: self.verificationErrors.append(str(e))
40         external.assertTrue(util.is_element_present(self,By.ID, "username"))
41         external.assertTrue(util.is_element_present(self,By.ID, "password"))
42         driver.find_element_by_css_selector("input.button_form").click()
43         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
44         external.assertTrue(util.is_element_present(self,By.LINK_TEXT, data["username"]))
45