Skip to content

Commit

Permalink
[py] add ability to specify browser binary, browser args, and driver …
Browse files Browse the repository at this point in the history
…executable binary in test suite

this also updates WebKitGTK options to be consistent with other Options classes
  • Loading branch information
lmtierney committed Dec 13, 2017
1 parent 403d796 commit 2e5358a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
58 changes: 36 additions & 22 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@


def pytest_addoption(parser):
parser.addoption(
'--driver',
action='append',
choices=drivers,
dest='drivers',
metavar='DRIVER',
help='driver to run tests against ({0})'.format(', '.join(drivers)))
parser.addoption('--driver', action='append', choices=drivers, dest='drivers',
metavar='DRIVER',
help='driver to run tests against ({})'.format(', '.join(drivers)))
parser.addoption('--browser-binary', action='store', dest='binary',
help='location of the browser binary')
parser.addoption('--driver-binary', action='store', dest='executable',
help='location of the service executable binary')
parser.addoption('--browser-args', action='store', dest='args',
help='arguments to start the browser with')


def pytest_ignore_collect(path, config):
Expand Down Expand Up @@ -93,40 +95,52 @@ def fin():
yield
return

driver_path = request.config.option.executable
options = None

global driver_instance
if driver_instance is None:
if driver_class == 'BlackBerry':
kwargs.update({'device_password': 'password'})
if driver_class == 'Firefox':
kwargs.update({'capabilities': {'marionette': False}})
options = get_options(driver_class, request.config)
if driver_class == 'Marionette':
driver_class = 'Firefox'
options = get_options(driver_class, request.config)
if driver_class == 'Remote':
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['marionette'] = False
kwargs.update({'desired_capabilities': capabilities})
options = get_options('Firefox', request.config)
if driver_class == 'WebKitGTK':
additional_args = {}
options = webdriver.WebKitGTKOptions()
options.overlay_scrollbars_enabled = False
browser_path = os.environ.get('WD_BROWSER_PATH')
if browser_path is not None:
options.browser_executable_path = browser_path
browser_args = os.environ.get('WD_BROWSER_ARGS')
if browser_args is not None:
for arg in browser_args.split():
options.add_browser_argument(arg)
additional_args['options'] = options
driver_path = os.environ.get('WD_DRIVER_PATH')
if driver_path is not None:
additional_args['executable_path'] = driver_path
kwargs.update(additional_args)
options = get_options(driver_class, request.config)
if driver_path is not None:
kwargs['executable_path'] = driver_path
if options is not None:
kwargs['options'] = options
driver_instance = getattr(webdriver, driver_class)(**kwargs)
yield driver_instance
if MarkEvaluator(request.node, 'no_driver_after_test').istrue():
driver_instance = None


def get_options(driver_class, config):
browser_path = config.option.binary
browser_args = config.option.args
options = None
if browser_path or browser_args:
options = getattr(webdriver, '{}Options'.format(driver_class))()
if driver_class == 'WebKitGTK':
options.overlay_scrollbars_enabled = False
if browser_path is not None:
options.binary_location = browser_path
if browser_args is not None:
for arg in browser_args.split():
options.add_argument(arg)
return options


@pytest.fixture(scope='session', autouse=True)
def stop_driver(request):
def fin():
Expand Down
30 changes: 15 additions & 15 deletions py/selenium/webdriver/webkitgtk/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,43 @@ class Options(object):
KEY = 'webkitgtk:browserOptions'

def __init__(self):
self._browser_executable_path = ''
self._browser_arguments = []
self._binary_location = ''
self._arguments = []
self._overlay_scrollbars_enabled = True

@property
def browser_executable_path(self):
def binary_location(self):
"""
Returns the location of the browser binary otherwise an empty string
"""
return self._browser_executable_path
return self._binary_location

@browser_executable_path.setter
def browser_executable_path(self, value):
@binary_location.setter
def binary_location(self, value):
"""
Allows you to set the browser binary to launch
:Args:
- value : path to the browser binary
"""
self._browser_executable_path = value
self._binary_location = value

@property
def browser_arguments(self):
def arguments(self):
"""
Returns a list of arguments needed for the browser
"""
return self._browser_arguments
return self._arguments

def add_browser_argument(self, argument):
def add_argument(self, argument):
"""
Adds an argument to the list
:Args:
- Sets the arguments
"""
if argument:
self._browser_arguments.append(argument)
self._arguments.append(argument)
else:
raise ValueError("argument can not be null")

Expand Down Expand Up @@ -87,10 +87,10 @@ def to_capabilities(self):
webkitgtk = DesiredCapabilities.WEBKITGTK.copy()

browser_options = {}
if self.browser_executable_path:
browser_options["binary"] = self.browser_executable_path
if self.browser_arguments:
browser_options["args"] = self.browser_arguments
if self.binary_location:
browser_options["binary"] = self.binary_location
if self.arguments:
browser_options["args"] = self.arguments
browser_options["useOverlayScrollbars"] = self.overlay_scrollbars_enabled

webkitgtk[Options.KEY] = browser_options
Expand Down

0 comments on commit 2e5358a

Please sign in to comment.