This repository has been archived by the owner on Oct 12, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSeleniumProxy
84 lines (67 loc) · 2.5 KB
/
SeleniumProxy
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
Here's a little tidbit that we use to add selenium to the test suite for our CP apps.
{{{
#!python
import os
localDir = os.path.dirname(__file__)
class SeleniumProxy(object):
jarfile = os.path.join(localDir, 'selenium-server.jar')
def __init__(self):
self.started = False
self.cmd = None
def start(self):
if not self.started:
self.cmd = os.popen('java -jar "%s" -interactive' % self.jarfile, 'w')
try:
from cherrypy import _cpserver
_cpserver.wait_for_occupied_port('127.0.0.1', 4444)
self.started = True
except:
self.stop()
def stop(self):
if self.cmd:
self.cmd.write('quit\n')
self.cmd.close()
self.cmd = None
self.started = False
proxy = SeleniumProxy()
def use_selenium(test_method):
"""Decorator for test methods to use selenium."""
def wrapper(self):
# First, start up the Selenium proxy server
proxy.start()
self.verificationErrors = []
try:
return test_method(self)
finally:
proxy.stop()
self.assertEqual([], self.verificationErrors)
return wrapper
browsers = ("*firefox", "*iexplore")
}}}
Here's an example of its use:
{{{
#!python
from endue.tests.selenium import selenium
from cherrypy.test import helper
from endue.tests import test
class InterestTests(helper.CPWebCase):
@test.use_selenium
def test_InterestsInterface(self):
for browser in test.browsers:
try:
sel = selenium("localhost", 4444, browser, "http://127.0.0.1:8080")
sel.start()
# search for directory ID 1
sel.open("/firststone/nav/")
sel.click("Directory")
sel.select_window("Opsdyn")
sel.wait_for_condition('selenium.isElementPresent("Criteria3")', '10000')
sel.type("Criteria0", "1")
sel.click("//input[@value='SHOW']")
sel.select_window("Opsdyn")
# wait for the directory page to load...
sel.wait_for_condition('selenium.isElementPresent("//div[4]/div/h3")', '10000')
sel.wait_for_condition('selenium.getText("//div[4]/div/h3") == "Stated Interests"', '10000')
finally:
sel.stop()
}}}