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/lib/actions.js CHANGED
@@ -15,38 +15,35 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- 'use strict';
19
-
20
- const command = require('./command');
21
- const error = require('./error');
22
- const input = require('./input');
18
+ 'use strict'
23
19
 
20
+ const command = require('./command')
21
+ const error = require('./error')
22
+ const input = require('./input')
24
23
 
25
24
  /**
26
25
  * @param {!IArrayLike} args .
27
26
  * @return {!Array} .
28
27
  */
29
28
  function flatten(args) {
30
- let result = [];
29
+ let result = []
31
30
  for (let i = 0; i < args.length; i++) {
32
- let element = args[i];
31
+ let element = args[i]
33
32
  if (Array.isArray(element)) {
34
- result.push.apply(result, flatten(element));
33
+ result.push.apply(result, flatten(element))
35
34
  } else {
36
- result.push(element);
35
+ result.push(element)
37
36
  }
38
37
  }
39
- return result;
38
+ return result
40
39
  }
41
40
 
42
-
43
41
  const MODIFIER_KEYS = new Set([
44
42
  input.Key.ALT,
45
43
  input.Key.CONTROL,
46
44
  input.Key.SHIFT,
47
- input.Key.COMMAND
48
- ]);
49
-
45
+ input.Key.COMMAND,
46
+ ])
50
47
 
51
48
  /**
52
49
  * Checks that a key is a modifier key.
@@ -56,11 +53,10 @@ const MODIFIER_KEYS = new Set([
56
53
  */
57
54
  function checkModifierKey(key) {
58
55
  if (!MODIFIER_KEYS.has(key)) {
59
- throw new error.InvalidArgumentError('Not a modifier key');
56
+ throw new error.InvalidArgumentError('Not a modifier key')
60
57
  }
61
58
  }
62
59
 
63
-
64
60
  /**
65
61
  * Class for defining sequences of complex user interactions. Each sequence
66
62
  * will not be executed until {@link #perform} is called.
@@ -92,10 +88,10 @@ class LegacyActionSequence {
92
88
  */
93
89
  constructor(driver) {
94
90
  /** @private {!./webdriver.WebDriver} */
95
- this.driver_ = driver;
91
+ this.driver_ = driver
96
92
 
97
93
  /** @private {!Array<{description: string, command: !command.Command}>} */
98
- this.actions_ = [];
94
+ this.actions_ = []
99
95
  }
100
96
 
101
97
  /**
@@ -109,8 +105,8 @@ class LegacyActionSequence {
109
105
  schedule_(description, command) {
110
106
  this.actions_.push({
111
107
  description: description,
112
- command: command
113
- });
108
+ command: command,
109
+ })
114
110
  }
115
111
 
116
112
  /**
@@ -123,9 +119,9 @@ class LegacyActionSequence {
123
119
  // Make a protected copy of the scheduled actions. This will protect against
124
120
  // users defining additional commands before this sequence is actually
125
121
  // executed.
126
- let actions = this.actions_.concat();
122
+ let actions = this.actions_.concat()
127
123
  for (let action of actions) {
128
- await this.driver_.execute(action.command);
124
+ await this.driver_.execute(action.command)
129
125
  }
130
126
  }
131
127
 
@@ -145,24 +141,24 @@ class LegacyActionSequence {
145
141
  * @return {!LegacyActionSequence} A self reference.
146
142
  */
147
143
  mouseMove(location, opt_offset) {
148
- let cmd = new command.Command(command.Name.LEGACY_ACTION_MOUSE_MOVE);
144
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_MOUSE_MOVE)
149
145
 
150
146
  if (typeof location.x === 'number') {
151
- setOffset(/** @type {{x: number, y: number}} */(location));
147
+ setOffset(/** @type {{x: number, y: number}} */ (location))
152
148
  } else {
153
- cmd.setParameter('element', location.getId());
149
+ cmd.setParameter('element', location.getId())
154
150
  if (opt_offset) {
155
- setOffset(opt_offset);
151
+ setOffset(opt_offset)
156
152
  }
157
153
  }
158
154
 
159
- this.schedule_('mouseMove', cmd);
160
- return this;
155
+ this.schedule_('mouseMove', cmd)
156
+ return this
161
157
 
162
158
  /** @param {{x: number, y: number}} offset The offset to use. */
163
159
  function setOffset(offset) {
164
- cmd.setParameter('xoffset', offset.x || 0);
165
- cmd.setParameter('yoffset', offset.y || 0);
160
+ cmd.setParameter('xoffset', offset.x || 0)
161
+ cmd.setParameter('yoffset', offset.y || 0)
166
162
  }
167
163
  }
168
164
 
@@ -182,22 +178,26 @@ class LegacyActionSequence {
182
178
  * @private
183
179
  */
184
180
  scheduleMouseAction_(
185
- description, commandName, opt_elementOrButton, opt_button) {
186
- let button;
181
+ description,
182
+ commandName,
183
+ opt_elementOrButton,
184
+ opt_button
185
+ ) {
186
+ let button
187
187
  if (typeof opt_elementOrButton === 'number') {
188
- button = opt_elementOrButton;
188
+ button = opt_elementOrButton
189
189
  } else {
190
190
  if (opt_elementOrButton) {
191
191
  this.mouseMove(
192
- /** @type {!./webdriver.WebElement} */ (opt_elementOrButton));
192
+ /** @type {!./webdriver.WebElement} */ (opt_elementOrButton)
193
+ )
193
194
  }
194
- button = opt_button !== void(0) ? opt_button : input.Button.LEFT;
195
+ button = opt_button !== void 0 ? opt_button : input.Button.LEFT
195
196
  }
196
197
 
197
- let cmd = new command.Command(commandName).
198
- setParameter('button', button);
199
- this.schedule_(description, cmd);
200
- return this;
198
+ let cmd = new command.Command(commandName).setParameter('button', button)
199
+ this.schedule_(description, cmd)
200
+ return this
201
201
  }
202
202
 
203
203
  /**
@@ -224,8 +224,12 @@ class LegacyActionSequence {
224
224
  * @return {!LegacyActionSequence} A self reference.
225
225
  */
226
226
  mouseDown(opt_elementOrButton, opt_button) {
227
- return this.scheduleMouseAction_('mouseDown',
228
- command.Name.LEGACY_ACTION_MOUSE_DOWN, opt_elementOrButton, opt_button);
227
+ return this.scheduleMouseAction_(
228
+ 'mouseDown',
229
+ command.Name.LEGACY_ACTION_MOUSE_DOWN,
230
+ opt_elementOrButton,
231
+ opt_button
232
+ )
229
233
  }
230
234
 
231
235
  /**
@@ -250,12 +254,16 @@ class LegacyActionSequence {
250
254
  * @return {!LegacyActionSequence} A self reference.
251
255
  */
252
256
  mouseUp(opt_elementOrButton, opt_button) {
253
- return this.scheduleMouseAction_('mouseUp',
254
- command.Name.LEGACY_ACTION_MOUSE_UP, opt_elementOrButton, opt_button);
257
+ return this.scheduleMouseAction_(
258
+ 'mouseUp',
259
+ command.Name.LEGACY_ACTION_MOUSE_UP,
260
+ opt_elementOrButton,
261
+ opt_button
262
+ )
255
263
  }
256
264
 
257
265
  /**
258
- * Convenience function for performing a "drag and drop" manuever. The target
266
+ * Convenience function for performing a "drag and drop" maneuver. The target
259
267
  * element may be moved to the location of another element, or by an offset (in
260
268
  * pixels).
261
269
  *
@@ -266,7 +274,7 @@ class LegacyActionSequence {
266
274
  * @return {!LegacyActionSequence} A self reference.
267
275
  */
268
276
  dragAndDrop(element, location) {
269
- return this.mouseDown(element).mouseMove(location).mouseUp();
277
+ return this.mouseDown(element).mouseMove(location).mouseUp()
270
278
  }
271
279
 
272
280
  /**
@@ -287,8 +295,12 @@ class LegacyActionSequence {
287
295
  * @return {!LegacyActionSequence} A self reference.
288
296
  */
289
297
  click(opt_elementOrButton, opt_button) {
290
- return this.scheduleMouseAction_('click',
291
- command.Name.LEGACY_ACTION_CLICK, opt_elementOrButton, opt_button);
298
+ return this.scheduleMouseAction_(
299
+ 'click',
300
+ command.Name.LEGACY_ACTION_CLICK,
301
+ opt_elementOrButton,
302
+ opt_button
303
+ )
292
304
  }
293
305
 
294
306
  /**
@@ -312,9 +324,12 @@ class LegacyActionSequence {
312
324
  * @return {!LegacyActionSequence} A self reference.
313
325
  */
314
326
  doubleClick(opt_elementOrButton, opt_button) {
315
- return this.scheduleMouseAction_('doubleClick',
316
- command.Name.LEGACY_ACTION_DOUBLE_CLICK, opt_elementOrButton,
317
- opt_button);
327
+ return this.scheduleMouseAction_(
328
+ 'doubleClick',
329
+ command.Name.LEGACY_ACTION_DOUBLE_CLICK,
330
+ opt_elementOrButton,
331
+ opt_button
332
+ )
318
333
  }
319
334
 
320
335
  /**
@@ -327,10 +342,11 @@ class LegacyActionSequence {
327
342
  * @private
328
343
  */
329
344
  scheduleKeyboardAction_(description, keys) {
330
- let cmd = new command.Command(command.Name.LEGACY_ACTION_SEND_KEYS)
331
- .setParameter('value', keys);
332
- this.schedule_(description, cmd);
333
- return this;
345
+ let cmd = new command.Command(
346
+ command.Name.LEGACY_ACTION_SEND_KEYS
347
+ ).setParameter('value', keys)
348
+ this.schedule_(description, cmd)
349
+ return this
334
350
  }
335
351
 
336
352
  /**
@@ -345,8 +361,8 @@ class LegacyActionSequence {
345
361
  * key.
346
362
  */
347
363
  keyDown(key) {
348
- checkModifierKey(key);
349
- return this.scheduleKeyboardAction_('keyDown', [key]);
364
+ checkModifierKey(key)
365
+ return this.scheduleKeyboardAction_('keyDown', [key])
350
366
  }
351
367
 
352
368
  /**
@@ -359,8 +375,8 @@ class LegacyActionSequence {
359
375
  * key.
360
376
  */
361
377
  keyUp(key) {
362
- checkModifierKey(key);
363
- return this.scheduleKeyboardAction_('keyUp', [key]);
378
+ checkModifierKey(key)
379
+ return this.scheduleKeyboardAction_('keyUp', [key])
364
380
  }
365
381
 
366
382
  /**
@@ -373,13 +389,12 @@ class LegacyActionSequence {
373
389
  * @return {!LegacyActionSequence} A self reference.
374
390
  * @throws {Error} If the key is not a valid modifier key.
375
391
  */
376
- sendKeys(var_args) {
377
- let keys = flatten(arguments);
378
- return this.scheduleKeyboardAction_('sendKeys', keys);
392
+ sendKeys(var_args) { // eslint-disable-line
393
+ let keys = flatten(arguments)
394
+ return this.scheduleKeyboardAction_('sendKeys', keys)
379
395
  }
380
396
  }
381
397
 
382
-
383
398
  /**
384
399
  * Class for defining sequences of user touch interactions. Each sequence
385
400
  * will not be executed until {@link #perform} is called.
@@ -409,10 +424,10 @@ class LegacyTouchSequence {
409
424
  */
410
425
  constructor(driver) {
411
426
  /** @private {!./webdriver.WebDriver} */
412
- this.driver_ = driver;
427
+ this.driver_ = driver
413
428
 
414
429
  /** @private {!Array<{description: string, command: !command.Command}>} */
415
- this.actions_ = [];
430
+ this.actions_ = []
416
431
  }
417
432
 
418
433
  /**
@@ -425,8 +440,8 @@ class LegacyTouchSequence {
425
440
  schedule_(description, command) {
426
441
  this.actions_.push({
427
442
  description: description,
428
- command: command
429
- });
443
+ command: command,
444
+ })
430
445
  }
431
446
 
432
447
  /**
@@ -438,9 +453,9 @@ class LegacyTouchSequence {
438
453
  // Make a protected copy of the scheduled actions. This will protect against
439
454
  // users defining additional commands before this sequence is actually
440
455
  // executed.
441
- let actions = this.actions_.concat();
456
+ let actions = this.actions_.concat()
442
457
  for (let action of actions) {
443
- await this.driver_.execute(action.command);
458
+ await this.driver_.execute(action.command)
444
459
  }
445
460
  }
446
461
 
@@ -451,11 +466,12 @@ class LegacyTouchSequence {
451
466
  * @return {!LegacyTouchSequence} A self reference.
452
467
  */
453
468
  tap(elem) {
454
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SINGLE_TAP).
455
- setParameter('element', elem.getId());
469
+ let cmd = new command.Command(
470
+ command.Name.LEGACY_ACTION_TOUCH_SINGLE_TAP
471
+ ).setParameter('element', elem.getId())
456
472
 
457
- this.schedule_('tap', cmd);
458
- return this;
473
+ this.schedule_('tap', cmd)
474
+ return this
459
475
  }
460
476
 
461
477
  /**
@@ -465,11 +481,12 @@ class LegacyTouchSequence {
465
481
  * @return {!LegacyTouchSequence} A self reference.
466
482
  */
467
483
  doubleTap(elem) {
468
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_DOUBLE_TAP).
469
- setParameter('element', elem.getId());
484
+ let cmd = new command.Command(
485
+ command.Name.LEGACY_ACTION_TOUCH_DOUBLE_TAP
486
+ ).setParameter('element', elem.getId())
470
487
 
471
- this.schedule_('doubleTap', cmd);
472
- return this;
488
+ this.schedule_('doubleTap', cmd)
489
+ return this
473
490
  }
474
491
 
475
492
  /**
@@ -479,11 +496,12 @@ class LegacyTouchSequence {
479
496
  * @return {!LegacyTouchSequence} A self reference.
480
497
  */
481
498
  longPress(elem) {
482
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_LONG_PRESS).
483
- setParameter('element', elem.getId());
499
+ let cmd = new command.Command(
500
+ command.Name.LEGACY_ACTION_TOUCH_LONG_PRESS
501
+ ).setParameter('element', elem.getId())
484
502
 
485
- this.schedule_('longPress', cmd);
486
- return this;
503
+ this.schedule_('longPress', cmd)
504
+ return this
487
505
  }
488
506
 
489
507
  /**
@@ -493,12 +511,12 @@ class LegacyTouchSequence {
493
511
  * @return {!LegacyTouchSequence} A self reference.
494
512
  */
495
513
  tapAndHold(location) {
496
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_DOWN).
497
- setParameter('x', location.x).
498
- setParameter('y', location.y);
514
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_DOWN)
515
+ .setParameter('x', location.x)
516
+ .setParameter('y', location.y)
499
517
 
500
- this.schedule_('tapAndHold', cmd);
501
- return this;
518
+ this.schedule_('tapAndHold', cmd)
519
+ return this
502
520
  }
503
521
 
504
522
  /**
@@ -508,12 +526,12 @@ class LegacyTouchSequence {
508
526
  * @return {!LegacyTouchSequence} A self reference.
509
527
  */
510
528
  move(location) {
511
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_MOVE).
512
- setParameter('x', location.x).
513
- setParameter('y', location.y);
529
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_MOVE)
530
+ .setParameter('x', location.x)
531
+ .setParameter('y', location.y)
514
532
 
515
- this.schedule_('move', cmd);
516
- return this;
533
+ this.schedule_('move', cmd)
534
+ return this
517
535
  }
518
536
 
519
537
  /**
@@ -523,12 +541,12 @@ class LegacyTouchSequence {
523
541
  * @return {!LegacyTouchSequence} A self reference.
524
542
  */
525
543
  release(location) {
526
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_UP).
527
- setParameter('x', location.x).
528
- setParameter('y', location.y);
544
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_UP)
545
+ .setParameter('x', location.x)
546
+ .setParameter('y', location.y)
529
547
 
530
- this.schedule_('release', cmd);
531
- return this;
548
+ this.schedule_('release', cmd)
549
+ return this
532
550
  }
533
551
 
534
552
  /**
@@ -538,12 +556,12 @@ class LegacyTouchSequence {
538
556
  * @return {!LegacyTouchSequence} A self reference.
539
557
  */
540
558
  scroll(offset) {
541
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL).
542
- setParameter('xoffset', offset.x).
543
- setParameter('yoffset', offset.y);
559
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL)
560
+ .setParameter('xoffset', offset.x)
561
+ .setParameter('yoffset', offset.y)
544
562
 
545
- this.schedule_('scroll', cmd);
546
- return this;
563
+ this.schedule_('scroll', cmd)
564
+ return this
547
565
  }
548
566
 
549
567
  /**
@@ -555,13 +573,13 @@ class LegacyTouchSequence {
555
573
  * @return {!LegacyTouchSequence} A self reference.
556
574
  */
557
575
  scrollFromElement(elem, offset) {
558
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL).
559
- setParameter('element', elem.getId()).
560
- setParameter('xoffset', offset.x).
561
- setParameter('yoffset', offset.y);
576
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL)
577
+ .setParameter('element', elem.getId())
578
+ .setParameter('xoffset', offset.x)
579
+ .setParameter('yoffset', offset.y)
562
580
 
563
- this.schedule_('scrollFromElement', cmd);
564
- return this;
581
+ this.schedule_('scrollFromElement', cmd)
582
+ return this
565
583
  }
566
584
 
567
585
  /**
@@ -572,12 +590,12 @@ class LegacyTouchSequence {
572
590
  * @return {!LegacyTouchSequence} A self reference.
573
591
  */
574
592
  flick(speed) {
575
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK).
576
- setParameter('xspeed', speed.xspeed).
577
- setParameter('yspeed', speed.yspeed);
593
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK)
594
+ .setParameter('xspeed', speed.xspeed)
595
+ .setParameter('yspeed', speed.yspeed)
578
596
 
579
- this.schedule_('flick', cmd);
580
- return this;
597
+ this.schedule_('flick', cmd)
598
+ return this
581
599
  }
582
600
 
583
601
  /**
@@ -589,21 +607,20 @@ class LegacyTouchSequence {
589
607
  * @return {!LegacyTouchSequence} A self reference.
590
608
  */
591
609
  flickElement(elem, offset, speed) {
592
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK).
593
- setParameter('element', elem.getId()).
594
- setParameter('xoffset', offset.x).
595
- setParameter('yoffset', offset.y).
596
- setParameter('speed', speed);
597
-
598
- this.schedule_('flickElement', cmd);
599
- return this;
610
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK)
611
+ .setParameter('element', elem.getId())
612
+ .setParameter('xoffset', offset.x)
613
+ .setParameter('yoffset', offset.y)
614
+ .setParameter('speed', speed)
615
+
616
+ this.schedule_('flickElement', cmd)
617
+ return this
600
618
  }
601
619
  }
602
620
 
603
-
604
621
  // PUBLIC API
605
622
 
606
623
  module.exports = {
607
624
  LegacyActionSequence,
608
625
  LegacyTouchSequence,
609
- };
626
+ }