-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathselenium_test.py
executable file
·84 lines (68 loc) · 1.97 KB
/
selenium_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python2.7
# Install selenium client library:
#
# $ easy_install2.7 selenium
#
# Requires:
#
# $ curl -O http://selenium.googlecode.com/files/selenium-server-standalone-2.0b2.jar
#
# Make sure server is running:
#
# $ java -jar selenium-server-standalone.jar
#
# Docs:
#
# http://code.google.com/p/selenium/wiki/PythonBindings
# http://release.seleniumhq.org/selenium-core/1.0/reference.html
import re
import time
import unittest
from selenium import selenium
class BrowserTestCase(unittest.TestCase):
@classmethod
def get_chrome(cls):
# don't use "*chrome"
browser = selenium("localhost", 4444, "*googlechrome",
"http://localhost:4444")
# this flag is needed to prevent chrome from crapping out for certain
# pages
browser.start('commandLineFlags=--disable-web-security')
return browser
@classmethod
def get_firefox(cls):
browser = selenium("localhost", 4444, "*firefox",
"http://localhost:4444")
browser.start()
return browser
@classmethod
def get_headless(cls):
browser = selenium("localhost", 4444, "*mock",
"http://localhost:4444")
browser.start()
return browser
@classmethod
def setUpClass(cls):
cls.browser = cls.get_chrome()
@classmethod
def tearDownClass(cls):
cls.browser.stop()
class TestGoogleSearchChrome(BrowserTestCase):
def test_vanity_search(self):
b = self.browser
b.open("http://google.com")
b.wait_for_page_to_load("10000")
b.type("name=q", "0xfe")
time.sleep(1)
# browser.click("//input[@value='Search']")
b.click("//input[contains(@value, 'Search')]")
time.sleep(1)
# text = browser.get_html_source()
text = b.get_body_text()
self.assertIsNotNone(re.search("muthanna", text))
class TestGoogleSearchFirefox(TestGoogleSearchChrome):
@classmethod
def setUpClass(cls):
cls.browser = cls.get_firefox()
if __name__ == "__main__":
unittest.main()