@@ -186,24 +186,31 @@ def check_for_previous_error
186
186
end
187
187
188
188
def create_remote_driver ( **opts )
189
- options = opts . delete ( :options ) { WebDriver ::Options . send ( browser ) }
190
189
url = ENV . fetch ( 'WD_REMOTE_URL' , remote_server . webdriver_url )
190
+ options = opts . delete ( :options ) { WebDriver ::Options . send ( browser ) }
191
+ method = "create_#{ browser } _options" . to_sym
192
+ options = send method , options if private_methods . include? ( method )
191
193
192
194
WebDriver ::Driver . for ( :remote , url : url , options : options , **opts )
193
195
end
194
196
195
197
def create_firefox_driver ( **opts )
196
- WebDriver ::Firefox . path = ENV . fetch ( 'FIREFOX_BINARY' , nil ) if ENV . key? ( 'FIREFOX_BINARY' )
197
- options = opts . delete ( :options ) { WebDriver ::Options . firefox }
198
- options . web_socket_url = true
199
- options . add_argument ( '--headless' ) if ENV [ 'HEADLESS' ]
198
+ options = create_firefox_options ( opts . delete ( :options ) )
200
199
WebDriver ::Driver . for ( :firefox , options : options , **opts )
201
200
end
202
201
203
202
def create_firefox_nightly_driver ( **opts )
204
- ENV [ 'FIREFOX_BINARY' ] = ENV . fetch ( 'FIREFOX_NIGHTLY_BINARY' , nil )
205
- options = opts . delete ( :options ) { WebDriver ::Options . firefox }
206
- create_firefox_driver ( options : options , **opts )
203
+ options = create_firefox_options ( opts . delete ( :options ) )
204
+ options . binary = ENV [ 'FIREFOX_NIGHTLY_BINARY' ] if ENV . key? ( 'FIREFOX_NIGHTLY_BINARY' )
205
+ WebDriver ::Driver . for ( :firefox , options : options , **opts )
206
+ end
207
+
208
+ def create_firefox_options ( options )
209
+ options ||= WebDriver ::Options . firefox
210
+ options . web_socket_url = true
211
+ options . add_argument ( '--headless' ) if ENV [ 'HEADLESS' ]
212
+ options . binary ||= ENV [ 'FIREFOX_BINARY' ] if ENV . key? ( 'FIREFOX_BINARY' )
213
+ options
207
214
end
208
215
209
216
def create_ie_driver ( **opts )
@@ -212,22 +219,37 @@ def create_ie_driver(**opts)
212
219
WebDriver ::Driver . for ( :ie , options : options , **opts )
213
220
end
214
221
222
+ def create_chrome_beta_driver ( **opts )
223
+ options = create_chrome_options ( opts . delete ( :options ) )
224
+ options . web_socket_url = true
225
+ service_opts = { args : [ '--disable-build-check' ] }
226
+ service_opts [ :path ] = ENV [ 'CHROMEDRIVER_BINARY' ] if ENV . key? ( 'CHROMEDRIVER_BINARY' )
227
+ service = WebDriver ::Service . chrome ( **service_opts )
228
+ WebDriver ::Driver . for ( :chrome , options : options , service : service , **opts )
229
+ end
230
+
215
231
def create_chrome_driver ( **opts )
216
- WebDriver ::Chrome . path = ENV . fetch ( 'CHROME_BINARY' , nil ) if ENV . key? ( 'CHROME_BINARY' )
217
- options = opts . delete ( :options ) { WebDriver ::Options . chrome }
218
- options . headless! if ENV [ 'HEADLESS' ]
232
+ options = create_chrome_options ( opts . delete ( :options ) )
219
233
WebDriver ::Driver . for ( :chrome , options : options , **opts )
220
234
end
221
235
236
+ def create_chrome_options ( options )
237
+ options ||= WebDriver ::Options . chrome
238
+ options . headless! if ENV [ 'HEADLESS' ]
239
+ options . binary ||= ENV [ 'CHROME_BINARY' ] if ENV . key? ( 'CHROME_BINARY' )
240
+ options
241
+ end
242
+
222
243
def create_safari_preview_driver ( **opts )
223
244
WebDriver ::Safari . technology_preview!
224
245
options = opts . delete ( :options ) { WebDriver ::Options . safari }
225
246
WebDriver ::Driver . for ( :safari , options : options , **opts )
226
247
end
227
248
228
249
def create_edge_driver ( **opts )
229
- WebDriver ::Edge . path = ENV . fetch ( 'EDGE_BINARY' , nil ) if ENV . key? ( 'EDGE_BINARY' )
230
250
options = opts . delete ( :options ) { WebDriver ::Options . edge }
251
+ options . headless! if ENV [ 'HEADLESS' ]
252
+ options . binary = ENV . fetch ( 'EDGE_BINARY' , nil ) if ENV . key? ( 'EDGE_BINARY' )
231
253
WebDriver ::Driver . for ( :edge , options : options , **opts )
232
254
end
233
255
0 commit comments