Skip to content

Commit

Permalink
It should be possible to use a custom safaridriver executable to run …
Browse files Browse the repository at this point in the history
…Selenium's test suite.

Add the 'use_existing' argument to the safari.WebDriver class initializer. This
argument causes the driver to not launch its own instance of safaridriver. Instead,
it connects via port to an externally-launched service. This can speed up testing
and is also useful when debugging problems with safaridriver itself.
  • Loading branch information
burg authored and AutomatedTester committed Feb 12, 2018
1 parent 7ec54a7 commit 5710a32
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ class WebDriver(RemoteWebDriver):
"""

def __init__(self, port=0, executable_path="/usr/bin/safaridriver",
def __init__(self, port=0, executable_path="/usr/bin/safaridriver", reuse_service=False,
desired_capabilities=DesiredCapabilities.SAFARI, quiet=False):
"""
Creates a new instance of the Safari driver.
Starts the service and then creates new instance of Safari Driver.
Creates a new Safari driver instance and launches or finds a running safaridriver service.
:Args:
- port - port you would like the service to run, if left as 0, a free port will be found.
- port - The port on which the safaridriver service should listen for new connections. If zero, a free port will be found.
- quiet - If True, the driver's stdout and stderr is suppressed.
- executable_path - Path to a custom safaridriver executable to be used. If absent, /usr/bin/safaridriver is used.
- desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
- quiet - set to True to suppress stdout and stderr of the driver
- reuse_service - If True, do not spawn a safaridriver instance; instead, connect to an already-running service that was launched externally.
"""
self.service = Service(executable_path, port=port, quiet=quiet)
self.service.start()

self._reuse_service = reuse_service
if not reuse_service:
self.service.start()

RemoteWebDriver.__init__(
self,
Expand All @@ -62,4 +65,5 @@ def quit(self):
except http_client.BadStatusLine:
pass
finally:
self.service.stop()
if not self._reuse_service:
self.service.stop()

0 comments on commit 5710a32

Please sign in to comment.