Skip to content

Commit

Permalink
Some initial draft code of SauceLabs driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Jan 11, 2011
1 parent 96bc3ed commit 5f1b91b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions saucelabs.py
@@ -0,0 +1,35 @@
from selenium import selenium as SeleniumBase

import subprocess
import urlparse

class Selenium(SeleniumBase):
"""
Drop-in replacement for selenium driver. Connects directly to sauce labs
and requires no browser or selenium rc install.
You will need Sauce Connect available on PATH, or specified via ``sauceConnect``
on init.
For more information, see http://saucelabs.com/docs/sauce-connect
"""

def __init__(self, host, port, browserStartCommand, browserURL, sauceUsername,
sauceApiKey, sauceConnect=None, ):
super(Selenium, self).__init__(host, port, browserStartCommand, browserURL)
self.sauceConnect = sauceConnect

def start_sauce_tunnel(self):
"Starts the SauceLabs tunnel with sauce-connect."
domain = urlparse.urlparse(self.browserURL).domain

p = subprocess.Popen([self.sauceConnect, '-u', self.sauceUsername, '-k', self.sauceApiKey,
'-s', self.host, '-p', self.port, '-d', domain],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)

def start(self, *args, **kwargs):
"Initiates a sauce tunnel followed by a selenium instance"
self.start_sauce_tunnel()
return super(Selenium, self).start(*args, **kwargs)
selenium = Selenium

0 comments on commit 5f1b91b

Please sign in to comment.