forked from florentbr/SeleniumBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoke-tests.py
85 lines (64 loc) · 2.19 KB
/
smoke-tests.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
85
"""Basic tests to ensure all the browsers are launchable with the COM server
"""
import sys, os, unittest, threading, time, multiprocessing, BaseHTTPServer
from win32com import client #http://sourceforge.net/projects/pywin32/files/pywin32/
SERVER_ADDRESS = ('127.0.0.1', 9393)
SERVER_PAGE = """
<html>
<head>
<title>Title</title>
</head>
<body>
<a id="link">Test page</a>
</body>
</html>
"""
class Suite(unittest.TestCase):
def test_list(self):
lst = CreateObject("Selenium.List")
for i in range(0, 10):
lst.add(i)
self.assertEqual(10, lst.Count)
def test_firefox(self):
self.assert_browser_display_page("Selenium.FirefoxDriver")
def test_iedriver(self):
self.assert_browser_display_page("Selenium.IEDriver")
def test_chrome(self):
self.assert_browser_display_page("Selenium.ChromeDriver")
def test_opera(self):
self.assert_browser_display_page("Selenium.OperaDriver")
def test_phantomjs(self):
self.assert_browser_display_page("Selenium.PhantomJSDriver")
def assert_browser_display_page(self, progid):
driver = CreateObject(progid)
try:
driver.get("http://%s:%s" % SERVER_ADDRESS)
txt = driver.FindElementById('link').Text
self.assertEqual("Test page", txt)
finally:
driver.quit
def CreateObject(progid):
return client.Dispatch(progid)
def RunHTTPServer():
server = BaseHTTPServer.HTTPServer(SERVER_ADDRESS, HTTPServerHandler)
server.serve_forever()
class HTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def handle(self):
try:
return BaseHTTPServer.BaseHTTPRequestHandler.handle(self)
except: return
def log_message(self, format, *args):
return
def do_GET(s):
s.send_response(200)
s.send_header('Content-type', 'text/html')
s.end_headers()
s.wfile.write(SERVER_PAGE)
if __name__ == '__main__':
print __doc__
print "Start tests ...\n"
server = multiprocessing.Process(target=RunHTTPServer)
server.start()
try:
unittest.main()
except SystemExit: pass