Created
November 17, 2011 08:59
-
-
Save tomchristie/1372740 to your computer and use it in GitHub Desktop.
Don't attempt to connect to the Selenium server at import; Wait until the first test is run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SeleniumTestCase(LiveServerTestCase): | |
_selenium_server_running = None | |
@property | |
def selenium_server_running(self): | |
""" | |
Determine if we can connect to the Selenium RC server. | |
Only evaluated once for performance reasons. | |
""" | |
if SeleniumTestCase._selenium_server_running is not None: | |
return SeleniumTestCase._selenium_server_running | |
try: | |
conn = httplib.HTTPConnection(settings.SELENIUM_SERVER_HOST, | |
settings.SELENIUM_SERVER_PORT) | |
try: | |
conn.request("GET", "/selenium-server/driver/", '', {}) | |
finally: | |
conn.close() | |
SeleniumTestCase._selenium_server_running = True | |
except socket.error: | |
SeleniumTestCase._selenium_server_running = False | |
return SeleniumTestCase._selenium_server_running | |
def setUp(self): | |
if not self.selenium_server_running: | |
message = ("Can't connect to the Selenium server using address" | |
" %s and port %s" % (settings.SELENIUM_SERVER_HOST, | |
settings.SELENIUM_SERVER_PORT)) | |
raise SkipTest(message) | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment