selenium-webdriver 4.0.0-alpha.6 → 4.0.0-beta.2

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 (50) hide show
  1. package/CHANGES.md +46 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +2 -0
  5. package/chrome.js +69 -80
  6. package/chromium.js +231 -164
  7. package/{lib/atoms/make-atoms-module.js → devtools/CDPConnection.js} +15 -9
  8. package/edge.js +104 -146
  9. package/example/chrome_android.js +45 -0
  10. package/example/chrome_mobile_emulation.js +46 -0
  11. package/example/firefox_channels.js +84 -0
  12. package/example/google_search.js +50 -0
  13. package/example/google_search_test.js +70 -0
  14. package/example/headless.js +63 -0
  15. package/example/logging.js +64 -0
  16. package/firefox.js +199 -200
  17. package/http/index.js +128 -116
  18. package/http/util.js +56 -64
  19. package/ie.js +180 -104
  20. package/index.js +246 -199
  21. package/io/exec.js +34 -39
  22. package/io/index.js +142 -152
  23. package/io/zip.js +75 -65
  24. package/lib/actions.js +139 -121
  25. package/lib/atoms/find-elements.js +123 -0
  26. package/lib/atoms/get-attribute.js +75 -59
  27. package/lib/atoms/is-displayed.js +72 -72
  28. package/lib/atoms/mutation-listener.js +55 -0
  29. package/lib/by.js +192 -65
  30. package/lib/capabilities.js +76 -86
  31. package/lib/command.js +19 -20
  32. package/lib/error.js +134 -168
  33. package/lib/http.js +337 -232
  34. package/lib/input.js +319 -296
  35. package/lib/logging.js +126 -137
  36. package/lib/promise.js +60 -66
  37. package/lib/proxy.js +31 -41
  38. package/lib/session.js +12 -15
  39. package/lib/symbols.js +3 -4
  40. package/lib/until.js +162 -160
  41. package/lib/webdriver.js +1014 -549
  42. package/net/index.js +30 -36
  43. package/net/portprober.js +30 -143
  44. package/opera.js +406 -0
  45. package/package.json +15 -7
  46. package/proxy.js +2 -2
  47. package/remote/index.js +190 -187
  48. package/safari.js +40 -49
  49. package/testing/index.js +504 -0
  50. package/lib/README +0 -5
package/chromium.js CHANGED
@@ -73,18 +73,16 @@
73
73
  * let driver = chrome.Driver.createSession(options, service);
74
74
  */
75
75
 
76
- 'use strict';
77
-
78
- const http = require('./http');
79
- const io = require('./io');
80
- const {Capabilities, Capability} = require('./lib/capabilities');
81
- const command = require('./lib/command');
82
- const error = require('./lib/error');
83
- const promise = require('./lib/promise');
84
- const Symbols = require('./lib/symbols');
85
- const webdriver = require('./lib/webdriver');
86
- const remote = require('./remote');
76
+ 'use strict'
87
77
 
78
+ const http = require('./http')
79
+ const io = require('./io')
80
+ const { Capabilities, Capability } = require('./lib/capabilities')
81
+ const command = require('./lib/command')
82
+ const error = require('./lib/error')
83
+ const Symbols = require('./lib/symbols')
84
+ const webdriver = require('./lib/webdriver')
85
+ const remote = require('./remote')
88
86
 
89
87
  /**
90
88
  * Custom command names supported by Chromium WebDriver.
@@ -95,13 +93,14 @@ const Command = {
95
93
  GET_NETWORK_CONDITIONS: 'getNetworkConditions',
96
94
  SET_NETWORK_CONDITIONS: 'setNetworkConditions',
97
95
  SEND_DEVTOOLS_COMMAND: 'sendDevToolsCommand',
96
+ SEND_AND_GET_DEVTOOLS_COMMAND: 'sendAndGetDevToolsCommand',
97
+ SET_PERMISSION: 'setPermission',
98
98
  GET_CAST_SINKS: 'getCastSinks',
99
99
  SET_CAST_SINK_TO_USE: 'setCastSinkToUse',
100
100
  START_CAST_TAB_MIRRORING: 'setCastTabMirroring',
101
101
  GET_CAST_ISSUE_MESSAGE: 'getCastIssueMessage',
102
102
  STOP_CASTING: 'stopCasting',
103
- };
104
-
103
+ }
105
104
 
106
105
  /**
107
106
  * Creates a command executor with support for Chromium's custom commands.
@@ -109,58 +108,75 @@ const Command = {
109
108
  * @return {!command.Executor} The new command executor.
110
109
  */
111
110
  function createExecutor(url, vendorPrefix) {
112
- let agent = new http.Agent({ keepAlive: true });
113
- let client = url.then(url => new http.HttpClient(url, agent));
114
- let executor = new http.Executor(client);
115
- configureExecutor(executor, vendorPrefix);
116
- return executor;
111
+ const agent = new http.Agent({ keepAlive: true })
112
+ const client = url.then((url) => new http.HttpClient(url, agent))
113
+ const executor = new http.Executor(client)
114
+ configureExecutor(executor, vendorPrefix)
115
+ return executor
117
116
  }
118
117
 
119
-
120
118
  /**
121
119
  * Configures the given executor with Chromium-specific commands.
122
120
  * @param {!http.Executor} executor the executor to configure.
123
121
  */
124
122
  function configureExecutor(executor, vendorPrefix) {
125
123
  executor.defineCommand(
126
- Command.LAUNCH_APP,
127
- 'POST',
128
- '/session/:sessionId/chromium/launch_app');
124
+ Command.LAUNCH_APP,
125
+ 'POST',
126
+ '/session/:sessionId/chromium/launch_app'
127
+ )
129
128
  executor.defineCommand(
130
- Command.GET_NETWORK_CONDITIONS,
131
- 'GET',
132
- '/session/:sessionId/chromium/network_conditions');
129
+ Command.GET_NETWORK_CONDITIONS,
130
+ 'GET',
131
+ '/session/:sessionId/chromium/network_conditions'
132
+ )
133
133
  executor.defineCommand(
134
- Command.SET_NETWORK_CONDITIONS,
135
- 'POST',
136
- '/session/:sessionId/chromium/network_conditions');
134
+ Command.SET_NETWORK_CONDITIONS,
135
+ 'POST',
136
+ '/session/:sessionId/chromium/network_conditions'
137
+ )
137
138
  executor.defineCommand(
138
- Command.SEND_DEVTOOLS_COMMAND,
139
- 'POST',
140
- '/session/:sessionId/chromium/send_command');
139
+ Command.SEND_DEVTOOLS_COMMAND,
140
+ 'POST',
141
+ '/session/:sessionId/chromium/send_command'
142
+ )
141
143
  executor.defineCommand(
142
- Command.GET_CAST_SINKS,
143
- 'GET',
144
- `/session/:sessionId/${vendorPrefix}/cast/get_sinks`);
144
+ Command.SEND_AND_GET_DEVTOOLS_COMMAND,
145
+ 'POST',
146
+ '/session/:sessionId/chromium/send_command_and_get_result'
147
+ )
145
148
  executor.defineCommand(
146
- Command.SET_CAST_SINK_TO_USE,
147
- 'POST',
148
- `/session/:sessionId/${vendorPrefix}/cast/set_sink_to_use`);
149
+ Command.SET_PERMISSION,
150
+ 'POST',
151
+ '/session/:sessionId/permissions'
152
+ )
149
153
  executor.defineCommand(
150
- Command.START_CAST_TAB_MIRRORING,
151
- 'POST',
152
- `/session/:sessionId/${vendorPrefix}/cast/start_tab_mirroring`);
154
+ Command.GET_CAST_SINKS,
155
+ 'GET',
156
+ `/session/:sessionId/${vendorPrefix}/cast/get_sinks`
157
+ )
153
158
  executor.defineCommand(
154
- Command.GET_CAST_ISSUE_MESSAGE,
155
- 'GET',
156
- `/session/:sessionId/${vendorPrefix}/cast/get_issue_message`);
159
+ Command.SET_CAST_SINK_TO_USE,
160
+ 'POST',
161
+ `/session/:sessionId/${vendorPrefix}/cast/set_sink_to_use`
162
+ )
157
163
  executor.defineCommand(
158
- Command.STOP_CASTING,
159
- 'POST',
160
- `/session/:sessionId/${vendorPrefix}/cast/stop_casting`);
164
+ Command.START_CAST_TAB_MIRRORING,
165
+ 'POST',
166
+ `/session/:sessionId/${vendorPrefix}/cast/start_tab_mirroring`
167
+ )
168
+ executor.defineCommand(
169
+ Command.GET_CAST_ISSUE_MESSAGE,
170
+ 'GET',
171
+ `/session/:sessionId/${vendorPrefix}/cast/get_issue_message`
172
+ )
173
+ executor.defineCommand(
174
+ Command.STOP_CASTING,
175
+ 'POST',
176
+ `/session/:sessionId/${vendorPrefix}/cast/stop_casting`
177
+ )
161
178
  }
162
179
 
163
-
164
180
  /**
165
181
  * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
166
182
  * a WebDriver server in a child process.
@@ -171,8 +187,8 @@ class ServiceBuilder extends remote.DriverService.Builder {
171
187
  * should ensure a valid path to the appropriate exe is provided.
172
188
  */
173
189
  constructor(exe) {
174
- super(exe);
175
- this.setLoopback(true); // Required
190
+ super(exe)
191
+ this.setLoopback(true) // Required
176
192
  }
177
193
 
178
194
  /**
@@ -184,7 +200,7 @@ class ServiceBuilder extends remote.DriverService.Builder {
184
200
  * @return {!ServiceBuilder} A self reference.
185
201
  */
186
202
  setAdbPort(port) {
187
- return this.addArguments('--adb-port=' + port);
203
+ return this.addArguments('--adb-port=' + port)
188
204
  }
189
205
 
190
206
  /**
@@ -194,7 +210,7 @@ class ServiceBuilder extends remote.DriverService.Builder {
194
210
  * @return {!ServiceBuilder} A self reference.
195
211
  */
196
212
  loggingTo(path) {
197
- return this.addArguments('--log-path=' + path);
213
+ return this.addArguments('--log-path=' + path)
198
214
  }
199
215
 
200
216
  /**
@@ -202,7 +218,7 @@ class ServiceBuilder extends remote.DriverService.Builder {
202
218
  * @return {!ServiceBuilder} A self reference.
203
219
  */
204
220
  enableVerboseLogging() {
205
- return this.addArguments('--verbose');
221
+ return this.addArguments('--verbose')
206
222
  }
207
223
 
208
224
  /**
@@ -212,19 +228,18 @@ class ServiceBuilder extends remote.DriverService.Builder {
212
228
  * @return {!ServiceBuilder} A self reference.
213
229
  */
214
230
  setNumHttpThreads(n) {
215
- return this.addArguments('--http-threads=' + n);
231
+ return this.addArguments('--http-threads=' + n)
216
232
  }
217
233
 
218
234
  /**
219
235
  * @override
220
236
  */
221
237
  setPath(path) {
222
- super.setPath(path);
223
- return this.addArguments('--url-base=' + path);
238
+ super.setPath(path)
239
+ return this.addArguments('--url-base=' + path)
224
240
  }
225
241
  }
226
242
 
227
-
228
243
  /**
229
244
  * Class for managing WebDriver options specific to a Chromium-based browser.
230
245
  */
@@ -234,13 +249,13 @@ class Options extends Capabilities {
234
249
  * capabilities to initialize this instance from.
235
250
  */
236
251
  constructor(other = undefined) {
237
- super(other);
252
+ super(other)
238
253
 
239
254
  /** @private {!Object} */
240
- this.options_ = this.get(this.CAPABILITY_KEY) || {};
255
+ this.options_ = this.get(this.CAPABILITY_KEY) || {}
241
256
 
242
- this.setBrowserName(this.BROWSER_NAME_VALUE);
243
- this.set(this.CAPABILITY_KEY, this.options_);
257
+ this.setBrowserName(this.BROWSER_NAME_VALUE)
258
+ this.set(this.CAPABILITY_KEY, this.options_)
244
259
  }
245
260
 
246
261
  /**
@@ -253,11 +268,11 @@ class Options extends Capabilities {
253
268
  * @return {!Options} A self reference.
254
269
  */
255
270
  addArguments(...args) {
256
- let newArgs = (this.options_.args || []).concat(...args);
271
+ let newArgs = (this.options_.args || []).concat(...args)
257
272
  if (newArgs.length) {
258
- this.options_.args = newArgs;
273
+ this.options_.args = newArgs
259
274
  }
260
- return this;
275
+ return this
261
276
  }
262
277
 
263
278
  /**
@@ -276,7 +291,7 @@ class Options extends Capabilities {
276
291
  * @return {!Options} A self reference.
277
292
  */
278
293
  headless() {
279
- return this.addArguments('headless');
294
+ return this.addArguments('headless')
280
295
  }
281
296
 
282
297
  /**
@@ -287,15 +302,15 @@ class Options extends Capabilities {
287
302
  * @throws {TypeError} if width or height is unspecified, not a number, or
288
303
  * less than or equal to 0.
289
304
  */
290
- windowSize({width, height}) {
305
+ windowSize({ width, height }) {
291
306
  function checkArg(arg) {
292
307
  if (typeof arg !== 'number' || arg <= 0) {
293
- throw TypeError('Arguments must be {width, height} with numbers > 0');
308
+ throw TypeError('Arguments must be {width, height} with numbers > 0')
294
309
  }
295
310
  }
296
- checkArg(width);
297
- checkArg(height);
298
- return this.addArguments(`window-size=${width},${height}`);
311
+ checkArg(width)
312
+ checkArg(height)
313
+ return this.addArguments(`window-size=${width},${height}`)
299
314
  }
300
315
 
301
316
  /**
@@ -306,11 +321,11 @@ class Options extends Capabilities {
306
321
  * @return {!Options} A self reference.
307
322
  */
308
323
  excludeSwitches(...args) {
309
- let switches = (this.options_.excludeSwitches || []).concat(...args);
324
+ let switches = (this.options_.excludeSwitches || []).concat(...args)
310
325
  if (switches.length) {
311
- this.options_.excludeSwitches = switches;
326
+ this.options_.excludeSwitches = switches
312
327
  }
313
- return this;
328
+ return this
314
329
  }
315
330
 
316
331
  /**
@@ -322,9 +337,9 @@ class Options extends Capabilities {
322
337
  * @return {!Options} A self reference.
323
338
  */
324
339
  addExtensions(...args) {
325
- let current = this.options_.extensions || [];
326
- this.options_.extensions = current.concat(...args);
327
- return this;
340
+ let current = this.options_.extensions || []
341
+ this.options_.extensions = current.concat(...args)
342
+ return this
328
343
  }
329
344
 
330
345
  /**
@@ -339,8 +354,8 @@ class Options extends Capabilities {
339
354
  * @return {!Options} A self reference.
340
355
  */
341
356
  setBinaryPath(path) {
342
- this.options_.binary = path;
343
- return this;
357
+ this.options_.binary = path
358
+ return this
344
359
  }
345
360
 
346
361
  /**
@@ -352,8 +367,8 @@ class Options extends Capabilities {
352
367
  * @return {!Options} A self reference.
353
368
  */
354
369
  detachDriver(detach) {
355
- this.options_.detach = detach;
356
- return this;
370
+ this.options_.detach = detach
371
+ return this
357
372
  }
358
373
 
359
374
  /**
@@ -363,8 +378,8 @@ class Options extends Capabilities {
363
378
  * @return {!Options} A self reference.
364
379
  */
365
380
  setUserPreferences(prefs) {
366
- this.options_.prefs = prefs;
367
- return this;
381
+ this.options_.prefs = prefs
382
+ return this
368
383
  }
369
384
 
370
385
  /**
@@ -375,7 +390,7 @@ class Options extends Capabilities {
375
390
  * - `enableTimeline`: Whether or not to collect events from Timeline domain.
376
391
  * Note: when tracing is enabled, Timeline domain is implicitly disabled,
377
392
  * unless `enableTimeline` is explicitly set to true.
378
- * - `tracingCategories`: A comma-separated string of Chromium tracing
393
+ * - `traceCategories`: A comma-separated string of Chromium tracing
379
394
  * categories for which trace events should be collected. An unspecified
380
395
  * or empty string disables tracing.
381
396
  * - `bufferUsageReportingInterval`: The requested number of milliseconds
@@ -386,14 +401,14 @@ class Options extends Capabilities {
386
401
  * @param {{enableNetwork: boolean,
387
402
  * enablePage: boolean,
388
403
  * enableTimeline: boolean,
389
- * tracingCategories: string,
404
+ * traceCategories: string,
390
405
  * bufferUsageReportingInterval: number}} prefs The performance
391
406
  * logging preferences.
392
407
  * @return {!Options} A self reference.
393
408
  */
394
409
  setPerfLoggingPrefs(prefs) {
395
- this.options_.perfLoggingPrefs = prefs;
396
- return this;
410
+ this.options_.perfLoggingPrefs = prefs
411
+ return this
397
412
  }
398
413
 
399
414
  /**
@@ -403,8 +418,8 @@ class Options extends Capabilities {
403
418
  * @return {!Options} A self reference.
404
419
  */
405
420
  setLocalState(state) {
406
- this.options_.localState = state;
407
- return this;
421
+ this.options_.localState = state
422
+ return this
408
423
  }
409
424
 
410
425
  /**
@@ -416,8 +431,8 @@ class Options extends Capabilities {
416
431
  * @return {!Options} A self reference.
417
432
  */
418
433
  androidActivity(name) {
419
- this.options_.androidActivity = name;
420
- return this;
434
+ this.options_.androidActivity = name
435
+ return this
421
436
  }
422
437
 
423
438
  /**
@@ -429,8 +444,8 @@ class Options extends Capabilities {
429
444
  * @return {!Options} A self reference.
430
445
  */
431
446
  androidDeviceSerial(serial) {
432
- this.options_.androidDeviceSerial = serial;
433
- return this;
447
+ this.options_.androidDeviceSerial = serial
448
+ return this
434
449
  }
435
450
 
436
451
  /**
@@ -441,8 +456,8 @@ class Options extends Capabilities {
441
456
  * @return {!Options} A self reference.
442
457
  */
443
458
  androidPackage(pkg) {
444
- this.options_.androidPackage = pkg;
445
- return this;
459
+ this.options_.androidPackage = pkg
460
+ return this
446
461
  }
447
462
 
448
463
  /**
@@ -454,8 +469,8 @@ class Options extends Capabilities {
454
469
  * @return {!Options} A self reference.
455
470
  */
456
471
  androidProcess(processName) {
457
- this.options_.androidProcess = processName;
458
- return this;
472
+ this.options_.androidProcess = processName
473
+ return this
459
474
  }
460
475
 
461
476
  /**
@@ -467,8 +482,8 @@ class Options extends Capabilities {
467
482
  * @return {!Options} A self reference.
468
483
  */
469
484
  androidUseRunningApp(useRunning) {
470
- this.options_.androidUseRunningApp = useRunning;
471
- return this;
485
+ this.options_.androidUseRunningApp = useRunning
486
+ return this
472
487
  }
473
488
 
474
489
  /**
@@ -478,8 +493,8 @@ class Options extends Capabilities {
478
493
  * @return {!Options} A self reference.
479
494
  */
480
495
  setBrowserLogFile(path) {
481
- this.options_.logPath = path;
482
- return this;
496
+ this.options_.logPath = path
497
+ return this
483
498
  }
484
499
 
485
500
  /**
@@ -489,8 +504,8 @@ class Options extends Capabilities {
489
504
  * @return {!Options} A self reference.
490
505
  */
491
506
  setBrowserMinidumpPath(path) {
492
- this.options_.minidumpPath = path;
493
- return this;
507
+ this.options_.minidumpPath = path
508
+ return this
494
509
  }
495
510
 
496
511
  /**
@@ -512,11 +527,11 @@ class Options extends Capabilities {
512
527
  *
513
528
  * __Example 2: Using Custom Screen Configuration__
514
529
  *
515
- * let options = new chrome.Options().setMobileEmulation({
530
+ * let options = new chrome.Options().setMobileEmulation({deviceMetrics: {
516
531
  * width: 360,
517
532
  * height: 640,
518
533
  * pixelRatio: 3.0
519
- * });
534
+ * }});
520
535
  *
521
536
  * let driver = chrome.Driver.createSession(options);
522
537
  *
@@ -530,8 +545,8 @@ class Options extends Capabilities {
530
545
  * @return {!Options} A self reference.
531
546
  */
532
547
  setMobileEmulation(config) {
533
- this.options_.mobileEmulation = config;
534
- return this;
548
+ this.options_.mobileEmulation = config
549
+ return this
535
550
  }
536
551
 
537
552
  /**
@@ -542,21 +557,22 @@ class Options extends Capabilities {
542
557
  * @suppress {checkTypes} Suppress [] access on a struct.
543
558
  */
544
559
  [Symbols.serialize]() {
545
- if (this.options_.extensions && this.options_.extensions.length) {
546
- this.options_.extensions =
547
- this.options_.extensions.map(function(extension) {
548
- if (Buffer.isBuffer(extension)) {
549
- return extension.toString('base64');
550
- }
551
- return io.read(/** @type {string} */(extension))
552
- .then(buffer => buffer.toString('base64'));
553
- });
560
+ if (this.options_.extensions && this.options_.extensions.length) {
561
+ this.options_.extensions = this.options_.extensions.map(function (
562
+ extension
563
+ ) {
564
+ if (Buffer.isBuffer(extension)) {
565
+ return extension.toString('base64')
566
+ }
567
+ return io
568
+ .read(/** @type {string} */(extension))
569
+ .then((buffer) => buffer.toString('base64'))
570
+ })
554
571
  }
555
- return super[Symbols.serialize]();
572
+ return super[Symbols.serialize]()
556
573
  }
557
574
  }
558
575
 
559
-
560
576
  /**
561
577
  * Creates a new WebDriver client for Chromium-based browsers.
562
578
  */
@@ -573,28 +589,28 @@ class Driver extends webdriver.WebDriver {
573
589
  * @return {!Driver} A new driver instance.
574
590
  */
575
591
  static createSession(caps, opt_serviceExecutor) {
576
- let executor;
577
- let onQuit;
592
+ let executor
593
+ let onQuit
578
594
  if (opt_serviceExecutor instanceof http.Executor) {
579
- executor = opt_serviceExecutor;
580
- configureExecutor(executor, this.VENDOR_COMMAND_PREFIX);
595
+ executor = opt_serviceExecutor
596
+ configureExecutor(executor, this.VENDOR_COMMAND_PREFIX)
581
597
  } else {
582
- let service = opt_serviceExecutor || this.getDefaultService();
583
- executor = createExecutor(service.start(), this.VENDOR_COMMAND_PREFIX);
584
- onQuit = () => service.kill();
598
+ let service = opt_serviceExecutor || this.getDefaultService()
599
+ executor = createExecutor(service.start(), this.VENDOR_COMMAND_PREFIX)
600
+ onQuit = () => service.kill()
585
601
  }
586
602
 
587
603
  // W3C spec requires noProxy value to be an array of strings, but Chromium
588
604
  // expects a single host as a string.
589
- let proxy = caps.get(Capability.PROXY);
605
+ let proxy = caps.get(Capability.PROXY)
590
606
  if (proxy && Array.isArray(proxy.noProxy)) {
591
- proxy.noProxy = proxy.noProxy[0];
607
+ proxy.noProxy = proxy.noProxy[0]
592
608
  if (!proxy.noProxy) {
593
- proxy.noProxy = undefined;
609
+ proxy.noProxy = undefined
594
610
  }
595
611
  }
596
612
 
597
- return /** @type {!Driver} */(super.createSession(executor, caps, onQuit));
613
+ return /** @type {!Driver} */ (super.createSession(executor, caps, onQuit))
598
614
  }
599
615
 
600
616
  /**
@@ -602,7 +618,7 @@ class Driver extends webdriver.WebDriver {
602
618
  * implementation.
603
619
  * @override
604
620
  */
605
- setFileDetector() {}
621
+ setFileDetector() { }
606
622
 
607
623
  /**
608
624
  * Schedules a command to launch Chrome App with given ID.
@@ -612,7 +628,8 @@ class Driver extends webdriver.WebDriver {
612
628
  */
613
629
  launchApp(id) {
614
630
  return this.execute(
615
- new command.Command(Command.LAUNCH_APP).setParameter('id', id));
631
+ new command.Command(Command.LAUNCH_APP).setParameter('id', id)
632
+ )
616
633
  }
617
634
 
618
635
  /**
@@ -621,7 +638,7 @@ class Driver extends webdriver.WebDriver {
621
638
  * emulation settings are retrievied.
622
639
  */
623
640
  getNetworkConditions() {
624
- return this.execute(new command.Command(Command.GET_NETWORK_CONDITIONS));
641
+ return this.execute(new command.Command(Command.GET_NETWORK_CONDITIONS))
625
642
  }
626
643
 
627
644
  /**
@@ -642,11 +659,16 @@ class Driver extends webdriver.WebDriver {
642
659
  */
643
660
  setNetworkConditions(spec) {
644
661
  if (!spec || typeof spec !== 'object') {
645
- throw TypeError('setNetworkConditions called with non-network-conditions parameter');
662
+ throw TypeError(
663
+ 'setNetworkConditions called with non-network-conditions parameter'
664
+ )
646
665
  }
647
666
  return this.execute(
648
- new command.Command(Command.SET_NETWORK_CONDITIONS)
649
- .setParameter('network_conditions', spec));
667
+ new command.Command(Command.SET_NETWORK_CONDITIONS).setParameter(
668
+ 'network_conditions',
669
+ spec
670
+ )
671
+ )
650
672
  }
651
673
 
652
674
  /**
@@ -660,9 +682,45 @@ class Driver extends webdriver.WebDriver {
660
682
  */
661
683
  sendDevToolsCommand(cmd, params = {}) {
662
684
  return this.execute(
663
- new command.Command(Command.SEND_DEVTOOLS_COMMAND)
664
- .setParameter('cmd', cmd)
665
- .setParameter('params', params));
685
+ new command.Command(Command.SEND_DEVTOOLS_COMMAND)
686
+ .setParameter('cmd', cmd)
687
+ .setParameter('params', params)
688
+ )
689
+ }
690
+
691
+ /**
692
+ * ends an arbitrary devtools command to the browser and get the result.
693
+ *
694
+ * @param {string} cmd The name of the command to send.
695
+ * @param {Object=} params The command parameters.
696
+ * @return {!Promise<void>} A promise that will be resolved when the command
697
+ * has finished.
698
+ * @see <https://chromedevtools.github.io/devtools-protocol/>
699
+ */
700
+ sendAndGetDevToolsCommand(cmd, params = {}) {
701
+ return this.execute(
702
+ new command.Command(Command.SEND_AND_GET_DEVTOOLS_COMMAND)
703
+ .setParameter('cmd', cmd)
704
+ .setParameter('params', params)
705
+ )
706
+ }
707
+
708
+ /**
709
+ * Set a permission state to the given value.
710
+ *
711
+ * @param {string} name A name of the permission to update.
712
+ * @param {('granted'|'denied'|'prompt')} state State to set permission to.
713
+ * @returns {!Promise<Object>} A promise that will be resolved when the
714
+ * command has finished.
715
+ * @see <https://w3c.github.io/permissions/#permission-registry> for valid
716
+ * names
717
+ */
718
+ setPermission(name, state) {
719
+ return this.execute(
720
+ new command.Command(Command.SET_PERMISSION)
721
+ .setParameter('descriptor', { name })
722
+ .setParameter('state', state)
723
+ )
666
724
  }
667
725
 
668
726
  /**
@@ -675,19 +733,18 @@ class Driver extends webdriver.WebDriver {
675
733
  */
676
734
  async setDownloadPath(path) {
677
735
  if (!path || typeof path !== 'string') {
678
- throw new error.InvalidArgumentError('invalid download path');
736
+ throw new error.InvalidArgumentError('invalid download path')
679
737
  }
680
- const stat = await io.stat(path);
738
+ const stat = await io.stat(path)
681
739
  if (!stat.isDirectory()) {
682
- throw new error.InvalidArgumentError('not a directory: ' + path);
740
+ throw new error.InvalidArgumentError('not a directory: ' + path)
683
741
  }
684
742
  return this.sendDevToolsCommand('Page.setDownloadBehavior', {
685
- 'behavior': 'allow',
686
- 'downloadPath': path
687
- });
743
+ behavior: 'allow',
744
+ downloadPath: path,
745
+ })
688
746
  }
689
747
 
690
-
691
748
  /**
692
749
  * Returns the list of cast sinks (Cast devices) available to the Chrome media router.
693
750
  *
@@ -696,67 +753,77 @@ class Driver extends webdriver.WebDriver {
696
753
  */
697
754
  getCastSinks() {
698
755
  return this.schedule(
699
- new command.Command(Command.GET_CAST_SINKS),
700
- 'Driver.getCastSinks()');
756
+ new command.Command(Command.GET_CAST_SINKS),
757
+ 'Driver.getCastSinks()'
758
+ )
701
759
  }
702
760
 
703
761
  /**
704
762
  * Selects a cast sink (Cast device) as the recipient of media router intents (connect or play).
705
763
  *
706
- * @param {String} Friendly name of the target device.
764
+ * @param {String} deviceName name of the target device.
707
765
  * @return {!promise.Thenable<void>} A promise that will be resolved
708
766
  * when the target device has been selected to respond further webdriver commands.
709
767
  */
710
768
  setCastSinkToUse(deviceName) {
711
769
  return this.schedule(
712
- new command.Command(Command.SET_CAST_SINK_TO_USE).setParameter('sinkName', deviceName),
713
- 'Driver.setCastSinkToUse(' + deviceName + ')');
770
+ new command.Command(Command.SET_CAST_SINK_TO_USE).setParameter(
771
+ 'sinkName',
772
+ deviceName
773
+ ),
774
+ 'Driver.setCastSinkToUse(' + deviceName + ')'
775
+ )
714
776
  }
715
777
 
716
778
  /**
717
779
  * Initiates tab mirroring for the current browser tab on the specified device.
718
780
  *
719
- * @param {String} Friendly name of the target device.
781
+ * @param {String} deviceName name of the target device.
720
782
  * @return {!promise.Thenable<void>} A promise that will be resolved
721
783
  * when the mirror command has been issued to the device.
722
784
  */
723
785
  startCastTabMirroring(deviceName) {
724
786
  return this.schedule(
725
- new command.Command(Command.START_CAST_TAB_MIRRORING).setParameter('sinkName', deviceName),
726
- 'Driver.startCastTabMirroring(' + deviceName + ')');
787
+ new command.Command(Command.START_CAST_TAB_MIRRORING).setParameter(
788
+ 'sinkName',
789
+ deviceName
790
+ ),
791
+ 'Driver.startCastTabMirroring(' + deviceName + ')'
792
+ )
727
793
  }
728
794
 
729
795
  /**
730
- * a
731
- *
732
- * @param {String} Friendly name of the target device.
796
+ * Returns an error message when there is any issue in a Cast session.
733
797
  * @return {!promise.Thenable<void>} A promise that will be resolved
734
798
  * when the mirror command has been issued to the device.
735
799
  */
736
800
  getCastIssueMessage() {
737
801
  return this.schedule(
738
- new command.Command(Command.GET_CAST_ISSUE_MESSAGE),
739
- 'Driver.getCastIssueMessage()');
802
+ new command.Command(Command.GET_CAST_ISSUE_MESSAGE),
803
+ 'Driver.getCastIssueMessage()'
804
+ )
740
805
  }
741
806
 
742
807
  /**
743
808
  * Stops casting from media router to the specified device, if connected.
744
809
  *
745
- * @param {String} Friendly name of the target device.
810
+ * @param {String} deviceName name of the target device.
746
811
  * @return {!promise.Thenable<void>} A promise that will be resolved
747
812
  * when the stop command has been issued to the device.
748
813
  */
749
814
  stopCasting(deviceName) {
750
815
  return this.schedule(
751
- new command.Command(Command.STOP_CASTING).setParameter('sinkName', deviceName),
752
- 'Driver.stopCasting(' + deviceName + ')');
816
+ new command.Command(Command.STOP_CASTING).setParameter(
817
+ 'sinkName',
818
+ deviceName
819
+ ),
820
+ 'Driver.stopCasting(' + deviceName + ')'
821
+ )
753
822
  }
754
823
  }
755
824
 
756
-
757
825
  // PUBLIC API
758
826
 
759
-
760
- exports.Driver = Driver;
761
- exports.Options = Options;
762
- exports.ServiceBuilder = ServiceBuilder;
827
+ exports.Driver = Driver
828
+ exports.Options = Options
829
+ exports.ServiceBuilder = ServiceBuilder