Updated documentation / scripts / compiled selenium scripts.
[mediagoblin-automation:mediagoblin-selenium.git] / tests / test_LogIn.py
1 from selenium import webdriver
2 from selenium.webdriver.common.by import By
3 from selenium.webdriver.support.ui import Select
4 from selenium.common.exceptions import NoSuchElementException
5 import unittest, time, re
6
7 class LogIn(unittest.TestCase):
8     def setUp(self):
9         self.driver = webdriver.Firefox()
10         self.driver.implicitly_wait(30)
11         self.base_url = "http://127.0.0.1:6543"
12         self.verificationErrors = []
13         self.accept_next_alert = True
14     
15     def test_log_in(self):
16         driver = self.driver
17         driver.get(self.base_url + "/")
18         driver.find_element_by_link_text("Log in").click()
19         driver.find_element_by_id("username").clear()
20         driver.find_element_by_id("username").send_keys("testuser")
21         driver.find_element_by_id("password").clear()
22         driver.find_element_by_id("password").send_keys("TestPassword!1")
23         # Warning: verifyTextPresent may require manual changes
24         try: self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[\s\S]*Log in[\s\S]*$")
25         except AssertionError as e: self.verificationErrors.append(str(e))
26         self.assertTrue(self.is_element_present(By.ID, "username"))
27         self.assertTrue(self.is_element_present(By.ID, "password"))
28         driver.find_element_by_css_selector("input.button_form").click()
29         driver.find_element_by_css_selector("div.button_action.header_dropdown_down").click()
30         self.assertTrue(self.is_element_present(By.LINK_TEXT, "testuser"))
31     
32     def is_element_present(self, how, what):
33         try: self.driver.find_element(by=how, value=what)
34         except NoSuchElementException, e: return False
35         return True
36     
37     def is_alert_present(self):
38         try: self.driver.switch_to_alert()
39         except NoAlertPresentException, e: return False
40         return True
41     
42     def close_alert_and_get_its_text(self):
43         try:
44             alert = self.driver.switch_to_alert()
45             alert_text = alert.text
46             if self.accept_next_alert:
47                 alert.accept()
48             else:
49                 alert.dismiss()
50             return alert_text
51         finally: self.accept_next_alert = True
52     
53     def tearDown(self):
54         self.driver.quit()
55         self.assertEqual([], self.verificationErrors)
56
57 if __name__ == "__main__":
58     unittest.main()
59