Skip to content

Commit 2e5358a

Browse files
committed
[py] add ability to specify browser binary, browser args, and driver executable binary in test suite
this also updates WebKitGTK options to be consistent with other Options classes
1 parent 403d796 commit 2e5358a

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

py/conftest.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@
4848

4949

5050
def pytest_addoption(parser):
51-
parser.addoption(
52-
'--driver',
53-
action='append',
54-
choices=drivers,
55-
dest='drivers',
56-
metavar='DRIVER',
57-
help='driver to run tests against ({0})'.format(', '.join(drivers)))
51+
parser.addoption('--driver', action='append', choices=drivers, dest='drivers',
52+
metavar='DRIVER',
53+
help='driver to run tests against ({})'.format(', '.join(drivers)))
54+
parser.addoption('--browser-binary', action='store', dest='binary',
55+
help='location of the browser binary')
56+
parser.addoption('--driver-binary', action='store', dest='executable',
57+
help='location of the service executable binary')
58+
parser.addoption('--browser-args', action='store', dest='args',
59+
help='arguments to start the browser with')
5860

5961

6062
def pytest_ignore_collect(path, config):
@@ -93,40 +95,52 @@ def fin():
9395
yield
9496
return
9597

98+
driver_path = request.config.option.executable
99+
options = None
100+
96101
global driver_instance
97102
if driver_instance is None:
98103
if driver_class == 'BlackBerry':
99104
kwargs.update({'device_password': 'password'})
100105
if driver_class == 'Firefox':
101106
kwargs.update({'capabilities': {'marionette': False}})
107+
options = get_options(driver_class, request.config)
102108
if driver_class == 'Marionette':
103109
driver_class = 'Firefox'
110+
options = get_options(driver_class, request.config)
104111
if driver_class == 'Remote':
105112
capabilities = DesiredCapabilities.FIREFOX.copy()
106113
capabilities['marionette'] = False
107114
kwargs.update({'desired_capabilities': capabilities})
115+
options = get_options('Firefox', request.config)
108116
if driver_class == 'WebKitGTK':
109-
additional_args = {}
110-
options = webdriver.WebKitGTKOptions()
111-
options.overlay_scrollbars_enabled = False
112-
browser_path = os.environ.get('WD_BROWSER_PATH')
113-
if browser_path is not None:
114-
options.browser_executable_path = browser_path
115-
browser_args = os.environ.get('WD_BROWSER_ARGS')
116-
if browser_args is not None:
117-
for arg in browser_args.split():
118-
options.add_browser_argument(arg)
119-
additional_args['options'] = options
120-
driver_path = os.environ.get('WD_DRIVER_PATH')
121-
if driver_path is not None:
122-
additional_args['executable_path'] = driver_path
123-
kwargs.update(additional_args)
117+
options = get_options(driver_class, request.config)
118+
if driver_path is not None:
119+
kwargs['executable_path'] = driver_path
120+
if options is not None:
121+
kwargs['options'] = options
124122
driver_instance = getattr(webdriver, driver_class)(**kwargs)
125123
yield driver_instance
126124
if MarkEvaluator(request.node, 'no_driver_after_test').istrue():
127125
driver_instance = None
128126

129127

128+
def get_options(driver_class, config):
129+
browser_path = config.option.binary
130+
browser_args = config.option.args
131+
options = None
132+
if browser_path or browser_args:
133+
options = getattr(webdriver, '{}Options'.format(driver_class))()
134+
if driver_class == 'WebKitGTK':
135+
options.overlay_scrollbars_enabled = False
136+
if browser_path is not None:
137+
options.binary_location = browser_path
138+
if browser_args is not None:
139+
for arg in browser_args.split():
140+
options.add_argument(arg)
141+
return options
142+
143+
130144
@pytest.fixture(scope='session', autouse=True)
131145
def stop_driver(request):
132146
def fin():

py/selenium/webdriver/webkitgtk/options.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,43 @@ class Options(object):
2222
KEY = 'webkitgtk:browserOptions'
2323

2424
def __init__(self):
25-
self._browser_executable_path = ''
26-
self._browser_arguments = []
25+
self._binary_location = ''
26+
self._arguments = []
2727
self._overlay_scrollbars_enabled = True
2828

2929
@property
30-
def browser_executable_path(self):
30+
def binary_location(self):
3131
"""
3232
Returns the location of the browser binary otherwise an empty string
3333
"""
34-
return self._browser_executable_path
34+
return self._binary_location
3535

36-
@browser_executable_path.setter
37-
def browser_executable_path(self, value):
36+
@binary_location.setter
37+
def binary_location(self, value):
3838
"""
3939
Allows you to set the browser binary to launch
4040
4141
:Args:
4242
- value : path to the browser binary
4343
"""
44-
self._browser_executable_path = value
44+
self._binary_location = value
4545

4646
@property
47-
def browser_arguments(self):
47+
def arguments(self):
4848
"""
4949
Returns a list of arguments needed for the browser
5050
"""
51-
return self._browser_arguments
51+
return self._arguments
5252

53-
def add_browser_argument(self, argument):
53+
def add_argument(self, argument):
5454
"""
5555
Adds an argument to the list
5656
5757
:Args:
5858
- Sets the arguments
5959
"""
6060
if argument:
61-
self._browser_arguments.append(argument)
61+
self._arguments.append(argument)
6262
else:
6363
raise ValueError("argument can not be null")
6464

@@ -87,10 +87,10 @@ def to_capabilities(self):
8787
webkitgtk = DesiredCapabilities.WEBKITGTK.copy()
8888

8989
browser_options = {}
90-
if self.browser_executable_path:
91-
browser_options["binary"] = self.browser_executable_path
92-
if self.browser_arguments:
93-
browser_options["args"] = self.browser_arguments
90+
if self.binary_location:
91+
browser_options["binary"] = self.binary_location
92+
if self.arguments:
93+
browser_options["args"] = self.arguments
9494
browser_options["useOverlayScrollbars"] = self.overlay_scrollbars_enabled
9595

9696
webkitgtk[Options.KEY] = browser_options

0 commit comments

Comments
 (0)