|
48 | 48 |
|
49 | 49 |
|
50 | 50 | 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') |
58 | 60 |
|
59 | 61 |
|
60 | 62 | def pytest_ignore_collect(path, config):
|
@@ -93,40 +95,52 @@ def fin():
|
93 | 95 | yield
|
94 | 96 | return
|
95 | 97 |
|
| 98 | + driver_path = request.config.option.executable |
| 99 | + options = None |
| 100 | + |
96 | 101 | global driver_instance
|
97 | 102 | if driver_instance is None:
|
98 | 103 | if driver_class == 'BlackBerry':
|
99 | 104 | kwargs.update({'device_password': 'password'})
|
100 | 105 | if driver_class == 'Firefox':
|
101 | 106 | kwargs.update({'capabilities': {'marionette': False}})
|
| 107 | + options = get_options(driver_class, request.config) |
102 | 108 | if driver_class == 'Marionette':
|
103 | 109 | driver_class = 'Firefox'
|
| 110 | + options = get_options(driver_class, request.config) |
104 | 111 | if driver_class == 'Remote':
|
105 | 112 | capabilities = DesiredCapabilities.FIREFOX.copy()
|
106 | 113 | capabilities['marionette'] = False
|
107 | 114 | kwargs.update({'desired_capabilities': capabilities})
|
| 115 | + options = get_options('Firefox', request.config) |
108 | 116 | 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 |
124 | 122 | driver_instance = getattr(webdriver, driver_class)(**kwargs)
|
125 | 123 | yield driver_instance
|
126 | 124 | if MarkEvaluator(request.node, 'no_driver_after_test').istrue():
|
127 | 125 | driver_instance = None
|
128 | 126 |
|
129 | 127 |
|
| 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 | + |
130 | 144 | @pytest.fixture(scope='session', autouse=True)
|
131 | 145 | def stop_driver(request):
|
132 | 146 | def fin():
|
|
0 commit comments