@@ -137,35 +137,6 @@ const {Binary, Channel} = require('./binary'),
137
137
remote = require ( '../remote' ) ;
138
138
139
139
140
- /**
141
- * Firefox-specific capability keys. Users should use the {@linkplain Options}
142
- * class instead of referencing these keys directly. _These keys are considered
143
- * implementation details and may be removed or changed at any time._
144
- *
145
- * @enum {string}
146
- */
147
- const Capability = {
148
- /**
149
- * Defines the Firefox binary to use. May be set to either a
150
- * {@linkplain Binary} instance, or a string path to the Firefox executable.
151
- */
152
- BINARY : 'firefox_binary' ,
153
-
154
- /**
155
- * @deprecated This will be removed in a future release. There is no
156
- * replacement.
157
- */
158
- MARIONETTE : 'marionette' ,
159
-
160
- /**
161
- * Defines the Firefox profile to use. May be set to either a
162
- * {@linkplain Profile} instance, or to a base-64 encoded zip of a profile
163
- * directory.
164
- */
165
- PROFILE : 'firefox_profile'
166
- } ;
167
-
168
-
169
140
/**
170
141
* Configuration options for the FirefoxDriver.
171
142
*/
@@ -174,7 +145,7 @@ class Options {
174
145
/** @private {Profile} */
175
146
this . profile_ = null ;
176
147
177
- /** @private {Binary} */
148
+ /** @private {( Binary|Channel|string|null) } */
178
149
this . binary_ = null ;
179
150
180
151
/** @private {logging.Preferences} */
@@ -210,17 +181,14 @@ class Options {
210
181
* @throws {TypeError } If `binary` is an invalid type.
211
182
*/
212
183
setBinary ( binary ) {
213
- if ( typeof binary === 'string' || binary instanceof Channel ) {
214
- binary = new Binary ( binary ) ;
184
+ if ( binary instanceof Binary
185
+ || binary instanceof Channel
186
+ || typeof binary === 'string' ) {
187
+ this . binary_ = binary ;
188
+ return this ;
215
189
}
216
-
217
- if ( ! ( binary instanceof Binary ) ) {
218
- throw TypeError (
219
- 'binary must be a string path, Channel, or Binary object' ) ;
220
- }
221
-
222
- this . binary_ = binary ;
223
- return this ;
190
+ throw TypeError (
191
+ 'binary must be a string path, Channel, or Binary object' ) ;
224
192
}
225
193
226
194
/**
@@ -250,19 +218,54 @@ class Options {
250
218
* @return {!capabilities.Capabilities } A new capabilities object.
251
219
*/
252
220
toCapabilities ( ) {
253
- var caps = capabilities . Capabilities . firefox ( ) ;
221
+ let caps = capabilities . Capabilities . firefox ( ) ;
222
+ let firefoxOptions = { } ;
223
+ caps . set ( 'moz:firefoxOptions' , firefoxOptions ) ;
224
+
254
225
if ( this . logPrefs_ ) {
255
226
caps . set ( capabilities . Capability . LOGGING_PREFS , this . logPrefs_ ) ;
256
227
}
228
+
257
229
if ( this . proxy_ ) {
258
230
caps . set ( capabilities . Capability . PROXY , this . proxy_ ) ;
259
231
}
232
+
260
233
if ( this . binary_ ) {
261
- caps . set ( Capability . BINARY , this . binary_ ) ;
234
+ if ( this . binary_ instanceof Binary ) {
235
+ let exe = this . binary_ . getExe ( ) ;
236
+ if ( exe ) {
237
+ firefoxOptions [ 'binary' ] = exe ;
238
+ }
239
+
240
+ let args = this . binary_ . getArguments ( ) ;
241
+ if ( args . length ) {
242
+ firefoxOptions [ 'args' ] = args ;
243
+ }
244
+ } else if ( this . binary_ instanceof Channel ) {
245
+ firefoxOptions [ 'binary' ] = this . binary_ . locate ( ) ;
246
+
247
+ } else if ( typeof this . binary_ === 'string' ) {
248
+ firefoxOptions [ 'binary' ] = this . binary_ ;
249
+ }
262
250
}
251
+
263
252
if ( this . profile_ ) {
264
- caps . set ( Capability . PROFILE , this . profile_ ) ;
253
+ // If the user specified a template directory or any extensions to
254
+ // install, we need to encode the profile as a base64 string (which
255
+ // requires writing it to disk first). Otherwise, if the user just
256
+ // specified some custom preferences, we can send those directly.
257
+ let profile = this . profile_ ;
258
+ if ( profile . getTemplateDir ( ) || profile . getExtensions ( ) . length ) {
259
+ firefoxOptions [ 'profile' ] = profile . encode ( ) ;
260
+
261
+ } else {
262
+ let prefs = profile . getPreferences ( ) ;
263
+ if ( Object . keys ( prefs ) . length ) {
264
+ firefoxOptions [ 'prefs' ] = prefs ;
265
+ }
266
+ }
265
267
}
268
+
266
269
return caps ;
267
270
}
268
271
}
@@ -401,111 +404,6 @@ class ServiceBuilder extends remote.DriverService.Builder {
401
404
enableVerboseLogging ( opt_trace ) {
402
405
return this . addArguments ( opt_trace ? '-vv' : '-v' ) ;
403
406
}
404
-
405
- /**
406
- * Sets the path to the executable Firefox binary that the geckodriver should
407
- * use. If this method is not called, this builder will attempt to locate
408
- * Firefox in the default installation location for the current platform.
409
- *
410
- * @param {(string|!Binary) } binary Path to the executable Firefox binary to use.
411
- * @return {!ServiceBuilder } A self reference.
412
- * @see Binary#locate()
413
- */
414
- setFirefoxBinary ( binary ) {
415
- let exe = typeof binary === 'string'
416
- ? Promise . resolve ( binary ) : binary . locate ( ) ;
417
- return this . addArguments ( '-b' , exe ) ;
418
- }
419
- }
420
-
421
-
422
- /**
423
- * @typedef {{executor: !command.Executor,
424
- * capabilities: (!capabilities.Capabilities|
425
- * {desired: (capabilities.Capabilities|undefined),
426
- * required: (capabilities.Capabilities|undefined)}),
427
- * onQuit: function(this: void): ? }}
428
- */
429
- var DriverSpec ;
430
-
431
-
432
- /**
433
- * @param {(http.Executor|remote.DriverService|undefined) } executor
434
- * @param {!capabilities.Capabilities } caps
435
- * @param {Profile } profile
436
- * @param {Binary } binary
437
- * @return {DriverSpec }
438
- */
439
- function createGeckoDriver ( executor , caps , profile , binary ) {
440
- let firefoxOptions = caps . get ( 'moz:firefoxOptions' ) || { } ;
441
- caps . set ( 'moz:firefoxOptions' , firefoxOptions ) ;
442
-
443
- if ( binary ) {
444
- if ( binary . getExe ( ) ) {
445
- firefoxOptions [ 'binary' ] = binary . getExe ( ) ;
446
- }
447
-
448
- let args = binary . getArguments ( ) ;
449
- if ( args . length ) {
450
- firefoxOptions [ 'args' ] = args ;
451
- }
452
- }
453
-
454
- if ( profile ) {
455
- // If the user specified a template directory or any extensions to install,
456
- // we need to encode the profile as a base64 string (which requires writing
457
- // it to disk first). Otherwise, if the user just specified some custom
458
- // preferences, we can send those directly.
459
- if ( profile . getTemplateDir ( ) || profile . getExtensions ( ) . length ) {
460
- firefoxOptions [ 'profile' ] = profile . encode ( ) ;
461
-
462
- } else {
463
- let prefs = profile . getPreferences ( ) ;
464
- if ( Object . keys ( prefs ) . length ) {
465
- firefoxOptions [ 'prefs' ] = prefs ;
466
- }
467
- }
468
- }
469
-
470
- let sessionCaps = caps ;
471
- if ( caps . has ( capabilities . Capability . PROXY ) ) {
472
- let proxy = normalizeProxyConfiguration (
473
- caps . get ( capabilities . Capability . PROXY ) ) ;
474
-
475
- // Marionette requires proxy settings to be specified as required
476
- // capabilities. See mozilla/geckodriver#97
477
- let required = new capabilities . Capabilities ( )
478
- . set ( capabilities . Capability . PROXY , proxy ) ;
479
-
480
- caps . delete ( capabilities . Capability . PROXY ) ;
481
- sessionCaps = { required, desired : caps } ;
482
- }
483
-
484
- /** @type {!command.Executor } */
485
- let cmdExecutor ;
486
- let onQuit = function ( ) { } ;
487
-
488
- if ( executor instanceof http . Executor ) {
489
- configureExecutor ( executor ) ;
490
- cmdExecutor = executor ;
491
- } else if ( executor instanceof remote . DriverService ) {
492
- cmdExecutor = createExecutor ( executor . start ( ) ) ;
493
- onQuit = ( ) => executor . kill ( ) ;
494
- } else {
495
- let builder = new ServiceBuilder ( ) ;
496
- if ( binary ) {
497
- builder . setFirefoxBinary ( binary ) ;
498
- }
499
- let service = builder . build ( ) ;
500
- cmdExecutor = createExecutor ( service . start ( ) ) ;
501
- onQuit = ( ) => service . kill ( ) ;
502
- }
503
-
504
- return {
505
- executor : cmdExecutor ,
506
- capabilities : sessionCaps ,
507
- onQuit
508
- } ;
509
407
}
510
408
511
409
@@ -546,21 +444,29 @@ class Driver extends webdriver.WebDriver {
546
444
caps = new capabilities . Capabilities ( opt_config ) ;
547
445
}
548
446
549
- let binary = caps . get ( Capability . BINARY ) || new Binary ( ) ;
550
- caps . delete ( Capability . BINARY ) ;
551
- if ( typeof binary === 'string' ) {
552
- binary = new Binary ( binary ) ;
447
+ if ( caps . has ( capabilities . Capability . PROXY ) ) {
448
+ let proxy =
449
+ normalizeProxyConfiguration ( caps . get ( capabilities . Capability . PROXY ) ) ;
450
+ caps . set ( capabilities . Capability . PROXY , proxy ) ;
553
451
}
554
452
555
- let profile ;
556
- if ( caps . has ( Capability . PROFILE ) ) {
557
- profile = caps . get ( Capability . PROFILE ) ;
558
- caps . delete ( Capability . PROFILE ) ;
453
+ let executor ;
454
+ let onQuit ;
455
+
456
+ if ( opt_executor instanceof http . Executor ) {
457
+ executor = opt_executor ;
458
+ configureExecutor ( executor ) ;
459
+ } else if ( opt_executor instanceof remote . DriverService ) {
460
+ executor = createExecutor ( opt_executor . start ( ) ) ;
461
+ onQuit = ( ) => opt_executor . kill ( ) ;
462
+ } else {
463
+ let service = new ServiceBuilder ( ) . build ( ) ;
464
+ executor = createExecutor ( service . start ( ) ) ;
465
+ onQuit = ( ) => service . kill ( ) ;
559
466
}
560
467
561
- let spec = createGeckoDriver ( opt_executor , caps , profile , binary ) ;
562
468
return /** @type {!Driver } */ ( super . createSession (
563
- spec . executor , spec . capabilities , opt_flow , spec . onQuit ) ) ;
469
+ executor , caps , opt_flow , onQuit ) ) ;
564
470
}
565
471
566
472
/**
0 commit comments