Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some initial draft code of SauceLabs driver
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |