Changed the util structure.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / util / login.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 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
24
25 class Login():
26     def log_in(self, external, data):
27         self.driver = external.driver
28         self.driver.implicitly_wait(30)
29         self.base_url = external.base_url
30         self.verificationErrors = []
31         self.accept_next_alert = True
32         testharness = unittest.FunctionTestCase(self)
33         driver = self.driver
34         driver.get(self.base_url + "/")
35         driver.find_element_by_link_text("Log in").click()
36         driver.find_element_by_id("username").clear()
37         driver.find_element_by_id("username").send_keys(data["username"])
38         driver.find_element_by_id("password").clear()
39         driver.find_element_by_id("password").send_keys(data["password"])
40         # Warning: verifyTextPresent may require manual changes
41         try: testharness.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Log in[\s\S]*$")
42         except AssertionError as e: self.verificationErrors.append(str(e))
43         testharness.assertTrue(helper.is_element_present(self,By.ID, "username"))
44         testharness.assertTrue(helper.is_element_present(self,By.ID, "password"))
45         driver.find_element_by_css_selector("input.button_form").click()
46         driver.find_element_by_link_text(u"▼").click()
47         testharness.assertTrue(helper.is_element_present(self,By.LINK_TEXT, data["username"]))
48