selenium-webdriver 4.0.0-alpha.4 → 4.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.eslintrc.js +27 -0
  2. package/.prettierrc +4 -0
  3. package/CHANGES.md +22 -1
  4. package/README.md +4 -4
  5. package/chrome.js +72 -590
  6. package/chromium.js +1024 -0
  7. package/devtools/CDPConnection.js +37 -0
  8. package/devtools/generator/protocol-dts-generator.js +429 -0
  9. package/edge.js +124 -86
  10. package/firefox.js +201 -202
  11. package/http/index.js +131 -115
  12. package/http/util.js +56 -64
  13. package/ie.js +180 -104
  14. package/index.js +246 -199
  15. package/io/exec.js +34 -39
  16. package/io/index.js +141 -151
  17. package/io/zip.js +75 -65
  18. package/lib/README +5 -0
  19. package/lib/actions.js +138 -121
  20. package/lib/atoms/find-elements.js +123 -0
  21. package/lib/atoms/get-attribute.js +79 -60
  22. package/lib/atoms/is-displayed.js +72 -73
  23. package/{example/chrome_mobile_emulation.js → lib/atoms/make-atoms-module.js} +16 -23
  24. package/lib/by.js +192 -65
  25. package/lib/capabilities.js +82 -78
  26. package/lib/command.js +18 -20
  27. package/lib/error.js +134 -168
  28. package/lib/http.js +324 -230
  29. package/lib/input.js +325 -302
  30. package/lib/logging.js +127 -138
  31. package/lib/promise.js +60 -66
  32. package/lib/proxy.js +31 -41
  33. package/lib/session.js +12 -15
  34. package/lib/symbols.js +3 -4
  35. package/lib/until.js +162 -162
  36. package/lib/webdriver.js +733 -522
  37. package/net/index.js +30 -36
  38. package/net/portprober.js +31 -144
  39. package/opera.js +406 -0
  40. package/package.json +18 -11
  41. package/proxy.js +2 -2
  42. package/remote/index.js +190 -187
  43. package/safari.js +40 -49
  44. package/LICENSE +0 -202
  45. package/NOTICE +0 -2
  46. package/example/chrome_android.js +0 -42
  47. package/example/firefox_channels.js +0 -77
  48. package/example/google_search.js +0 -50
  49. package/example/google_search_test.js +0 -72
  50. package/example/headless.js +0 -55
  51. package/example/logging.js +0 -68
  52. package/testing/index.js +0 -498
package/chrome.js CHANGED
@@ -118,30 +118,18 @@
118
118
  * [Refer to the ChromeDriver site] for more information on using the
119
119
  * [ChromeDriver with Android][android].
120
120
  *
121
- * [ChromeDriver]: https://sites.google.com/a/chromium.org/chromedriver/
121
+ * [ChromeDriver]: https://chromedriver.chromium.org/
122
122
  * [ChromeDriver release]: http://chromedriver.storage.googleapis.com/index.html
123
123
  * [PATH]: http://en.wikipedia.org/wiki/PATH_%28variable%29
124
- * [android]: https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android
124
+ * [android]: https://chromedriver.chromium.org/getting-started/getting-started---android
125
125
  * [webview]: https://developer.chrome.com/multidevice/webview/overview
126
126
  */
127
127
 
128
- 'use strict';
129
-
130
- const fs = require('fs');
131
- const util = require('util');
132
-
133
- const http = require('./http');
134
- const io = require('./io');
135
- const {Browser, Capabilities, Capability} = require('./lib/capabilities');
136
- const command = require('./lib/command');
137
- const error = require('./lib/error');
138
- const logging = require('./lib/logging');
139
- const promise = require('./lib/promise');
140
- const Symbols = require('./lib/symbols');
141
- const webdriver = require('./lib/webdriver');
142
- const portprober = require('./net/portprober');
143
- const remote = require('./remote');
128
+ 'use strict'
144
129
 
130
+ const io = require('./io')
131
+ const { Browser } = require('./lib/capabilities')
132
+ const chromium = require('./chromium')
145
133
 
146
134
  /**
147
135
  * Name of the ChromeDriver executable.
@@ -149,76 +137,17 @@ const remote = require('./remote');
149
137
  * @const
150
138
  */
151
139
  const CHROMEDRIVER_EXE =
152
- process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver';
153
-
154
-
155
- /**
156
- * Custom command names supported by ChromeDriver.
157
- * @enum {string}
158
- */
159
- const Command = {
160
- LAUNCH_APP: 'launchApp',
161
- GET_NETWORK_CONDITIONS: 'getNetworkConditions',
162
- SET_NETWORK_CONDITIONS: 'setNetworkConditions',
163
- SEND_DEVTOOLS_COMMAND: 'sendDevToolsCommand',
164
- };
165
-
166
-
167
- /**
168
- * Creates a command executor with support for ChromeDriver's custom commands.
169
- * @param {!Promise<string>} url The server's URL.
170
- * @return {!command.Executor} The new command executor.
171
- */
172
- function createExecutor(url) {
173
- let agent = new http.Agent({ keepAlive: true });
174
- let client = url.then(url => new http.HttpClient(url, agent));
175
- let executor = new http.Executor(client);
176
- configureExecutor(executor);
177
- return executor;
178
- }
179
-
180
-
181
- /**
182
- * Configures the given executor with Chrome-specific commands.
183
- * @param {!http.Executor} executor the executor to configure.
184
- */
185
- function configureExecutor(executor) {
186
- executor.defineCommand(
187
- Command.LAUNCH_APP,
188
- 'POST',
189
- '/session/:sessionId/chromium/launch_app');
190
- executor.defineCommand(
191
- Command.GET_NETWORK_CONDITIONS,
192
- 'GET',
193
- '/session/:sessionId/chromium/network_conditions');
194
- executor.defineCommand(
195
- Command.SET_NETWORK_CONDITIONS,
196
- 'POST',
197
- '/session/:sessionId/chromium/network_conditions');
198
- executor.defineCommand(
199
- Command.SEND_DEVTOOLS_COMMAND,
200
- 'POST',
201
- '/session/:sessionId/chromium/send_command');
202
- }
203
-
204
-
205
- /**
206
- * _Synchronously_ attempts to locate the chromedriver executable on the current
207
- * system.
208
- *
209
- * @return {?string} the located executable, or `null`.
210
- */
211
- function locateSynchronously() {
212
- return io.findInPath(CHROMEDRIVER_EXE, true);
213
- }
140
+ process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver'
214
141
 
142
+ /** @type {remote.DriverService} */
143
+ let defaultService = null
215
144
 
216
145
  /**
217
146
  * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
218
- * a [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/)
147
+ * a [ChromeDriver](https://chromedriver.chromium.org/)
219
148
  * server in a child process.
220
149
  */
221
- class ServiceBuilder extends remote.DriverService.Builder {
150
+ class ServiceBuilder extends chromium.ServiceBuilder {
222
151
  /**
223
152
  * @param {string=} opt_exe Path to the server executable to use. If omitted,
224
153
  * the builder will attempt to locate the chromedriver on the current
@@ -227,208 +156,23 @@ class ServiceBuilder extends remote.DriverService.Builder {
227
156
  * cannot be found on the PATH.
228
157
  */
229
158
  constructor(opt_exe) {
230
- let exe = opt_exe || locateSynchronously();
159
+ let exe = opt_exe || locateSynchronously()
231
160
  if (!exe) {
232
161
  throw Error(
233
- 'The ChromeDriver could not be found on the current PATH. Please ' +
234
- 'download the latest version of the ChromeDriver from ' +
235
- 'http://chromedriver.storage.googleapis.com/index.html and ensure ' +
236
- 'it can be found on your PATH.');
162
+ `The ChromeDriver could not be found on the current PATH. Please ` +
163
+ `download the latest version of the ChromeDriver from ` +
164
+ `http://chromedriver.storage.googleapis.com/index.html and ensure ` +
165
+ `it can be found on your PATH.`
166
+ )
237
167
  }
238
-
239
- super(exe);
240
- this.setLoopback(true); // Required
241
- }
242
-
243
- /**
244
- * Sets which port adb is listening to. _The ChromeDriver will connect to adb
245
- * if an {@linkplain Options#androidPackage Android session} is requested, but
246
- * adb **must** be started beforehand._
247
- *
248
- * @param {number} port Which port adb is running on.
249
- * @return {!ServiceBuilder} A self reference.
250
- */
251
- setAdbPort(port) {
252
- return this.addArguments('--adb-port=' + port);
253
- }
254
-
255
- /**
256
- * Sets the path of the log file the driver should log to. If a log file is
257
- * not specified, the driver will log to stderr.
258
- * @param {string} path Path of the log file to use.
259
- * @return {!ServiceBuilder} A self reference.
260
- */
261
- loggingTo(path) {
262
- return this.addArguments('--log-path=' + path);
263
- }
264
-
265
- /**
266
- * Enables verbose logging.
267
- * @return {!ServiceBuilder} A self reference.
268
- */
269
- enableVerboseLogging() {
270
- return this.addArguments('--verbose');
271
- }
272
-
273
- /**
274
- * Sets the number of threads the driver should use to manage HTTP requests.
275
- * By default, the driver will use 4 threads.
276
- * @param {number} n The number of threads to use.
277
- * @return {!ServiceBuilder} A self reference.
278
- */
279
- setNumHttpThreads(n) {
280
- return this.addArguments('--http-threads=' + n);
281
- }
282
-
283
- /**
284
- * @override
285
- */
286
- setPath(path) {
287
- super.setPath(path);
288
- return this.addArguments('--url-base=' + path);
168
+ super(exe)
289
169
  }
290
170
  }
291
171
 
292
-
293
-
294
- /** @type {remote.DriverService} */
295
- let defaultService = null;
296
-
297
-
298
- /**
299
- * Sets the default service to use for new ChromeDriver instances.
300
- * @param {!remote.DriverService} service The service to use.
301
- * @throws {Error} If the default service is currently running.
302
- */
303
- function setDefaultService(service) {
304
- if (defaultService && defaultService.isRunning()) {
305
- throw Error(
306
- 'The previously configured ChromeDriver service is still running. ' +
307
- 'You must shut it down before you may adjust its configuration.');
308
- }
309
- defaultService = service;
310
- }
311
-
312
-
313
- /**
314
- * Returns the default ChromeDriver service. If such a service has not been
315
- * configured, one will be constructed using the default configuration for
316
- * a ChromeDriver executable found on the system PATH.
317
- * @return {!remote.DriverService} The default ChromeDriver service.
318
- */
319
- function getDefaultService() {
320
- if (!defaultService) {
321
- defaultService = new ServiceBuilder().build();
322
- }
323
- return defaultService;
324
- }
325
-
326
-
327
- const OPTIONS_CAPABILITY_KEY = 'goog:chromeOptions';
328
-
329
-
330
172
  /**
331
173
  * Class for managing ChromeDriver specific options.
332
174
  */
333
- class Options extends Capabilities {
334
- /**
335
- * @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
336
- * capabilities to initialize this instance from.
337
- */
338
- constructor(other = undefined) {
339
- super(other);
340
-
341
- /** @private {!Object} */
342
- this.options_ = this.get(OPTIONS_CAPABILITY_KEY) || {};
343
-
344
- this.setBrowserName(Browser.CHROME);
345
- this.set(OPTIONS_CAPABILITY_KEY, this.options_);
346
- }
347
-
348
- /**
349
- * Add additional command line arguments to use when launching the Chrome
350
- * browser. Each argument may be specified with or without the "--" prefix
351
- * (e.g. "--foo" and "foo"). Arguments with an associated value should be
352
- * delimited by an "=": "foo=bar".
353
- *
354
- * @param {...(string|!Array<string>)} args The arguments to add.
355
- * @return {!Options} A self reference.
356
- */
357
- addArguments(...args) {
358
- let newArgs = (this.options_.args || []).concat(...args);
359
- if (newArgs.length) {
360
- this.options_.args = newArgs;
361
- }
362
- return this;
363
- }
364
-
365
- /**
366
- * Configures the chromedriver to start Chrome in headless mode.
367
- *
368
- * > __NOTE:__ Resizing the browser window in headless mode is only supported
369
- * > in Chrome 60. Users are encouraged to set an initial window size with
370
- * > the {@link #windowSize windowSize({width, height})} option.
371
- *
372
- * > __NOTE__: For security, Chrome disables downloads by default when
373
- * > in headless mode (to prevent sites from silently downloading files to
374
- * > your machine). After creating a session, you may call
375
- * > {@link ./chrome.Driver#setDownloadPath setDownloadPath} to re-enable
376
- * > downloads, saving files in the specified directory.
377
- *
378
- * @return {!Options} A self reference.
379
- */
380
- headless() {
381
- return this.addArguments('headless');
382
- }
383
-
384
- /**
385
- * Sets the initial window size.
386
- *
387
- * @param {{width: number, height: number}} size The desired window size.
388
- * @return {!Options} A self reference.
389
- * @throws {TypeError} if width or height is unspecified, not a number, or
390
- * less than or equal to 0.
391
- */
392
- windowSize({width, height}) {
393
- function checkArg(arg) {
394
- if (typeof arg !== 'number' || arg <= 0) {
395
- throw TypeError('Arguments must be {width, height} with numbers > 0');
396
- }
397
- }
398
- checkArg(width);
399
- checkArg(height);
400
- return this.addArguments(`window-size=${width},${height}`);
401
- }
402
-
403
- /**
404
- * List of Chrome command line switches to exclude that ChromeDriver by default
405
- * passes when starting Chrome. Do not prefix switches with "--".
406
- *
407
- * @param {...(string|!Array<string>)} args The switches to exclude.
408
- * @return {!Options} A self reference.
409
- */
410
- excludeSwitches(...args) {
411
- let switches = (this.options_.excludeSwitches || []).concat(...args);
412
- if (switches.length) {
413
- this.options_.excludeSwitches = switches;
414
- }
415
- return this;
416
- }
417
-
418
- /**
419
- * Add additional extensions to install when launching Chrome. Each extension
420
- * should be specified as the path to the packed CRX file, or a Buffer for an
421
- * extension.
422
- * @param {...(string|!Buffer|!Array<(string|!Buffer)>)} args The
423
- * extensions to add.
424
- * @return {!Options} A self reference.
425
- */
426
- addExtensions(...args) {
427
- let current = this.options_.extensions || [];
428
- this.options_.extensions = current.concat(...args);
429
- return this;
430
- }
431
-
175
+ class Options extends chromium.Options {
432
176
  /**
433
177
  * Sets the path to the Chrome binary to use. On Mac OS X, this path should
434
178
  * reference the actual Chrome executable, not just the application binary
@@ -441,98 +185,7 @@ class Options extends Capabilities {
441
185
  * @return {!Options} A self reference.
442
186
  */
443
187
  setChromeBinaryPath(path) {
444
- this.options_.binary = path;
445
- return this;
446
- }
447
-
448
- /**
449
- * Sets whether to leave the started Chrome browser running if the controlling
450
- * ChromeDriver service is killed before {@link webdriver.WebDriver#quit()} is
451
- * called.
452
- * @param {boolean} detach Whether to leave the browser running if the
453
- * chromedriver service is killed before the session.
454
- * @return {!Options} A self reference.
455
- */
456
- detachDriver(detach) {
457
- this.options_.detach = detach;
458
- return this;
459
- }
460
-
461
- /**
462
- * Sets the user preferences for Chrome's user profile. See the "Preferences"
463
- * file in Chrome's user data directory for examples.
464
- * @param {!Object} prefs Dictionary of user preferences to use.
465
- * @return {!Options} A self reference.
466
- */
467
- setUserPreferences(prefs) {
468
- this.options_.prefs = prefs;
469
- return this;
470
- }
471
-
472
- /**
473
- * Sets the performance logging preferences. Options include:
474
- *
475
- * - `enableNetwork`: Whether or not to collect events from Network domain.
476
- * - `enablePage`: Whether or not to collect events from Page domain.
477
- * - `enableTimeline`: Whether or not to collect events from Timeline domain.
478
- * Note: when tracing is enabled, Timeline domain is implicitly disabled,
479
- * unless `enableTimeline` is explicitly set to true.
480
- * - `tracingCategories`: A comma-separated string of Chrome tracing
481
- * categories for which trace events should be collected. An unspecified
482
- * or empty string disables tracing.
483
- * - `bufferUsageReportingInterval`: The requested number of milliseconds
484
- * between DevTools trace buffer usage events. For example, if 1000, then
485
- * once per second, DevTools will report how full the trace buffer is. If
486
- * a report indicates the buffer usage is 100%, a warning will be issued.
487
- *
488
- * @param {{enableNetwork: boolean,
489
- * enablePage: boolean,
490
- * enableTimeline: boolean,
491
- * tracingCategories: string,
492
- * bufferUsageReportingInterval: number}} prefs The performance
493
- * logging preferences.
494
- * @return {!Options} A self reference.
495
- */
496
- setPerfLoggingPrefs(prefs) {
497
- this.options_.perfLoggingPrefs = prefs;
498
- return this;
499
- }
500
-
501
- /**
502
- * Sets preferences for the "Local State" file in Chrome's user data
503
- * directory.
504
- * @param {!Object} state Dictionary of local state preferences.
505
- * @return {!Options} A self reference.
506
- */
507
- setLocalState(state) {
508
- this.options_.localState = state;
509
- return this;
510
- }
511
-
512
- /**
513
- * Sets the name of the activity hosting a Chrome-based Android WebView. This
514
- * option must be set to connect to an [Android WebView](
515
- * https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android)
516
- *
517
- * @param {string} name The activity name.
518
- * @return {!Options} A self reference.
519
- */
520
- androidActivity(name) {
521
- this.options_.androidActivity = name;
522
- return this;
523
- }
524
-
525
- /**
526
- * Sets the device serial number to connect to via ADB. If not specified, the
527
- * ChromeDriver will select an unused device at random. An error will be
528
- * returned if all devices already have active sessions.
529
- *
530
- * @param {string} serial The device serial number to connect to.
531
- * @return {!Options} A self reference.
532
- */
533
- androidDeviceSerial(serial) {
534
- this.options_.androidDeviceSerial = serial;
535
- return this;
188
+ return this.setBinaryPath(path)
536
189
  }
537
190
 
538
191
  /**
@@ -542,45 +195,7 @@ class Options extends Capabilities {
542
195
  * @return {!Options} A self reference.
543
196
  */
544
197
  androidChrome() {
545
- return this.androidPackage('com.android.chrome');
546
- }
547
-
548
- /**
549
- * Sets the package name of the Chrome or WebView app.
550
- *
551
- * @param {?string} pkg The package to connect to, or `null` to disable Android
552
- * and switch back to using desktop Chrome.
553
- * @return {!Options} A self reference.
554
- */
555
- androidPackage(pkg) {
556
- this.options_.androidPackage = pkg;
557
- return this;
558
- }
559
-
560
- /**
561
- * Sets the process name of the Activity hosting the WebView (as given by
562
- * `ps`). If not specified, the process name is assumed to be the same as
563
- * {@link #androidPackage}.
564
- *
565
- * @param {string} processName The main activity name.
566
- * @return {!Options} A self reference.
567
- */
568
- androidProcess(processName) {
569
- this.options_.androidProcess = processName;
570
- return this;
571
- }
572
-
573
- /**
574
- * Sets whether to connect to an already-running instead of the specified
575
- * {@linkplain #androidProcess app} instead of launching the app with a clean
576
- * data directory.
577
- *
578
- * @param {boolean} useRunning Whether to connect to a running instance.
579
- * @return {!Options} A self reference.
580
- */
581
- androidUseRunningApp(useRunning) {
582
- this.options_.androidUseRunningApp = useRunning;
583
- return this;
198
+ return this.androidPackage('com.android.chrome')
584
199
  }
585
200
 
586
201
  /**
@@ -590,8 +205,7 @@ class Options extends Capabilities {
590
205
  * @return {!Options} A self reference.
591
206
  */
592
207
  setChromeLogFile(path) {
593
- this.options_.logPath = path;
594
- return this;
208
+ return this.setBrowserLogFile(path)
595
209
  }
596
210
 
597
211
  /**
@@ -601,79 +215,14 @@ class Options extends Capabilities {
601
215
  * @return {!Options} A self reference.
602
216
  */
603
217
  setChromeMinidumpPath(path) {
604
- this.options_.minidumpPath = path;
605
- return this;
606
- }
607
-
608
- /**
609
- * Configures Chrome to emulate a mobile device. For more information, refer
610
- * to the ChromeDriver project page on [mobile emulation][em]. Configuration
611
- * options include:
612
- *
613
- * - `deviceName`: The name of a pre-configured [emulated device][devem]
614
- * - `width`: screen width, in pixels
615
- * - `height`: screen height, in pixels
616
- * - `pixelRatio`: screen pixel ratio
617
- *
618
- * __Example 1: Using a Pre-configured Device__
619
- *
620
- * let options = new chrome.Options().setMobileEmulation(
621
- * {deviceName: 'Google Nexus 5'});
622
- *
623
- * let driver = chrome.Driver.createSession(options);
624
- *
625
- * __Example 2: Using Custom Screen Configuration__
626
- *
627
- * let options = new chrome.Options().setMobileEmulation({
628
- * width: 360,
629
- * height: 640,
630
- * pixelRatio: 3.0
631
- * });
632
- *
633
- * let driver = chrome.Driver.createSession(options);
634
- *
635
- *
636
- * [em]: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
637
- * [devem]: https://developer.chrome.com/devtools/docs/device-mode
638
- *
639
- * @param {?({deviceName: string}|
640
- * {width: number, height: number, pixelRatio: number})} config The
641
- * mobile emulation configuration, or `null` to disable emulation.
642
- * @return {!Options} A self reference.
643
- */
644
- setMobileEmulation(config) {
645
- this.options_.mobileEmulation = config;
646
- return this;
647
- }
648
-
649
- /**
650
- * Converts this instance to its JSON wire protocol representation. Note this
651
- * function is an implementation not intended for general use.
652
- *
653
- * @return {!Object} The JSON wire protocol representation of this instance.
654
- * @suppress {checkTypes} Suppress [] access on a struct.
655
- */
656
- [Symbols.serialize]() {
657
- if (this.options_.extensions && this.options_.extensions.length) {
658
- this.options_.extensions =
659
- this.options_.extensions.map(function(extension) {
660
- if (Buffer.isBuffer(extension)) {
661
- return extension.toString('base64');
662
- }
663
- return io.read(/** @type {string} */(extension))
664
- .then(buffer => buffer.toString('base64'));
665
- });
666
- }
667
- return super[Symbols.serialize]();
218
+ return this.setBrowserMinidumpPath(path)
668
219
  }
669
220
  }
670
221
 
671
-
672
222
  /**
673
223
  * Creates a new WebDriver client for Chrome.
674
224
  */
675
- class Driver extends webdriver.WebDriver {
676
-
225
+ class Driver extends chromium.Driver {
677
226
  /**
678
227
  * Creates a new session with the ChromeDriver.
679
228
  *
@@ -686,128 +235,61 @@ class Driver extends webdriver.WebDriver {
686
235
  * @return {!Driver} A new driver instance.
687
236
  */
688
237
  static createSession(opt_config, opt_serviceExecutor) {
689
- let executor;
690
- if (opt_serviceExecutor instanceof http.Executor) {
691
- executor = opt_serviceExecutor;
692
- configureExecutor(executor);
693
- } else {
694
- let service = opt_serviceExecutor || getDefaultService();
695
- executor = createExecutor(service.start());
696
- }
697
-
698
- let caps = opt_config || Capabilities.chrome();
699
-
700
- // W3C spec requires noProxy value to be an array of strings, but Chrome
701
- // expects a single host as a string.
702
- let proxy = caps.get(Capability.PROXY);
703
- if (proxy && Array.isArray(proxy.noProxy)) {
704
- proxy.noProxy = proxy.noProxy[0];
705
- if (!proxy.noProxy) {
706
- proxy.noProxy = undefined;
707
- }
708
- }
709
-
710
- return /** @type {!Driver} */(super.createSession(executor, caps));
711
- }
712
-
713
- /**
714
- * This function is a no-op as file detectors are not supported by this
715
- * implementation.
716
- * @override
717
- */
718
- setFileDetector() {}
719
-
720
- /**
721
- * Schedules a command to launch Chrome App with given ID.
722
- * @param {string} id ID of the App to launch.
723
- * @return {!Promise<void>} A promise that will be resolved
724
- * when app is launched.
725
- */
726
- launchApp(id) {
727
- return this.execute(
728
- new command.Command(Command.LAUNCH_APP).setParameter('id', id));
729
- }
730
-
731
- /**
732
- * Schedules a command to get Chrome network emulation settings.
733
- * @return {!Promise} A promise that will be resolved when network
734
- * emulation settings are retrievied.
735
- */
736
- getNetworkConditions() {
737
- return this.execute(new command.Command(Command.GET_NETWORK_CONDITIONS));
238
+ let caps = opt_config || new Options()
239
+ return /** @type {!Driver} */ (super.createSession(
240
+ caps,
241
+ opt_serviceExecutor
242
+ ))
738
243
  }
244
+ }
739
245
 
740
- /**
741
- * Schedules a command to set Chrome network emulation settings.
742
- *
743
- * __Sample Usage:__
744
- *
745
- * driver.setNetworkConditions({
746
- * offline: false,
747
- * latency: 5, // Additional latency (ms).
748
- * download_throughput: 500 * 1024, // Maximal aggregated download throughput.
749
- * upload_throughput: 500 * 1024 // Maximal aggregated upload throughput.
750
- * });
751
- *
752
- * @param {Object} spec Defines the network conditions to set
753
- * @return {!Promise<void>} A promise that will be resolved when network
754
- * emulation settings are set.
755
- */
756
- setNetworkConditions(spec) {
757
- if (!spec || typeof spec !== 'object') {
758
- throw TypeError('setNetworkConditions called with non-network-conditions parameter');
759
- }
760
- return this.execute(
761
- new command.Command(Command.SET_NETWORK_CONDITIONS)
762
- .setParameter('network_conditions', spec));
763
- }
246
+ /**
247
+ * _Synchronously_ attempts to locate the chromedriver executable on the current
248
+ * system.
249
+ *
250
+ * @return {?string} the located executable, or `null`.
251
+ */
252
+ function locateSynchronously() {
253
+ return io.findInPath(CHROMEDRIVER_EXE, true)
254
+ }
764
255
 
765
- /**
766
- * Sends an arbitrary devtools command to the browser.
767
- *
768
- * @param {string} cmd The name of the command to send.
769
- * @param {Object=} params The command parameters.
770
- * @return {!Promise<void>} A promise that will be resolved when the command
771
- * has finished.
772
- * @see <https://chromedevtools.github.io/devtools-protocol/>
773
- */
774
- sendDevToolsCommand(cmd, params = {}) {
775
- return this.execute(
776
- new command.Command(Command.SEND_DEVTOOLS_COMMAND)
777
- .setParameter('cmd', cmd)
778
- .setParameter('params', params));
256
+ /**
257
+ * Sets the default service to use for new ChromeDriver instances.
258
+ * @param {!remote.DriverService} service The service to use.
259
+ * @throws {Error} If the default service is currently running.
260
+ */
261
+ function setDefaultService(service) {
262
+ if (defaultService && defaultService.isRunning()) {
263
+ throw Error(
264
+ `The previously configured ChromeDriver service is still running. ` +
265
+ `You must shut it down before you may adjust its configuration.`
266
+ )
779
267
  }
268
+ defaultService = service
269
+ }
780
270
 
781
- /**
782
- * Sends a DevTools command to change Chrome's download directory.
783
- *
784
- * @param {string} path The desired download directory.
785
- * @return {!Promise<void>} A promise that will be resolved when the command
786
- * has finished.
787
- * @see #sendDevToolsCommand
788
- */
789
- async setDownloadPath(path) {
790
- if (!path || typeof path !== 'string') {
791
- throw new error.InvalidArgumentError('invalid download path');
792
- }
793
- const stat = await io.stat(path);
794
- if (!stat.isDirectory()) {
795
- throw new error.InvalidArgumentError('not a directory: ' + path);
796
- }
797
- return this.sendDevToolsCommand('Page.setDownloadBehavior', {
798
- 'behavior': 'allow',
799
- 'downloadPath': path
800
- });
271
+ /**
272
+ * Returns the default ChromeDriver service. If such a service has not been
273
+ * configured, one will be constructed using the default configuration for
274
+ * a ChromeDriver executable found on the system PATH.
275
+ * @return {!remote.DriverService} The default ChromeDriver service.
276
+ */
277
+ function getDefaultService() {
278
+ if (!defaultService) {
279
+ defaultService = new ServiceBuilder().build()
801
280
  }
281
+ return defaultService
802
282
  }
803
283
 
284
+ Options.prototype.CAPABILITY_KEY = 'goog:chromeOptions'
285
+ Options.prototype.BROWSER_NAME_VALUE = Browser.CHROME
286
+ Driver.getDefaultService = getDefaultService
287
+ Driver.prototype.VENDOR_COMMAND_PREFIX = 'goog'
804
288
 
805
289
  // PUBLIC API
806
-
807
-
808
- exports.Driver = Driver;
809
- exports.Options = Options;
810
- exports.ServiceBuilder = ServiceBuilder;
811
- exports.getDefaultService = getDefaultService;
812
- exports.setDefaultService = setDefaultService;
813
- exports.locateSynchronously = locateSynchronously;
290
+ exports.Driver = Driver
291
+ exports.Options = Options
292
+ exports.ServiceBuilder = ServiceBuilder
293
+ exports.getDefaultService = getDefaultService
294
+ exports.setDefaultService = setDefaultService
295
+ exports.locateSynchronously = locateSynchronously