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/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
+ const result = []
31
30
  for (let i = 0; i < args.length; i++) {
32
- let element = args[i];
31
+ const 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();
127
- for (let action of actions) {
128
- await this.driver_.execute(action.command);
122
+ const actions = this.actions_.concat()
123
+ for (const action of actions) {
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
+ const 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,8 +254,12 @@ 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
  /**
@@ -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,13 @@ 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) {
393
+ // eslint-disable-line
394
+ const keys = flatten(arguments)
395
+ return this.scheduleKeyboardAction_('sendKeys', keys)
379
396
  }
380
397
  }
381
398
 
382
-
383
399
  /**
384
400
  * Class for defining sequences of user touch interactions. Each sequence
385
401
  * will not be executed until {@link #perform} is called.
@@ -409,10 +425,10 @@ class LegacyTouchSequence {
409
425
  */
410
426
  constructor(driver) {
411
427
  /** @private {!./webdriver.WebDriver} */
412
- this.driver_ = driver;
428
+ this.driver_ = driver
413
429
 
414
430
  /** @private {!Array<{description: string, command: !command.Command}>} */
415
- this.actions_ = [];
431
+ this.actions_ = []
416
432
  }
417
433
 
418
434
  /**
@@ -425,8 +441,8 @@ class LegacyTouchSequence {
425
441
  schedule_(description, command) {
426
442
  this.actions_.push({
427
443
  description: description,
428
- command: command
429
- });
444
+ command: command,
445
+ })
430
446
  }
431
447
 
432
448
  /**
@@ -438,9 +454,9 @@ class LegacyTouchSequence {
438
454
  // Make a protected copy of the scheduled actions. This will protect against
439
455
  // users defining additional commands before this sequence is actually
440
456
  // executed.
441
- let actions = this.actions_.concat();
457
+ let actions = this.actions_.concat()
442
458
  for (let action of actions) {
443
- await this.driver_.execute(action.command);
459
+ await this.driver_.execute(action.command)
444
460
  }
445
461
  }
446
462
 
@@ -451,11 +467,12 @@ class LegacyTouchSequence {
451
467
  * @return {!LegacyTouchSequence} A self reference.
452
468
  */
453
469
  tap(elem) {
454
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SINGLE_TAP).
455
- setParameter('element', elem.getId());
470
+ let cmd = new command.Command(
471
+ command.Name.LEGACY_ACTION_TOUCH_SINGLE_TAP
472
+ ).setParameter('element', elem.getId())
456
473
 
457
- this.schedule_('tap', cmd);
458
- return this;
474
+ this.schedule_('tap', cmd)
475
+ return this
459
476
  }
460
477
 
461
478
  /**
@@ -465,11 +482,12 @@ class LegacyTouchSequence {
465
482
  * @return {!LegacyTouchSequence} A self reference.
466
483
  */
467
484
  doubleTap(elem) {
468
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_DOUBLE_TAP).
469
- setParameter('element', elem.getId());
485
+ const cmd = new command.Command(
486
+ command.Name.LEGACY_ACTION_TOUCH_DOUBLE_TAP
487
+ ).setParameter('element', elem.getId())
470
488
 
471
- this.schedule_('doubleTap', cmd);
472
- return this;
489
+ this.schedule_('doubleTap', cmd)
490
+ return this
473
491
  }
474
492
 
475
493
  /**
@@ -479,11 +497,12 @@ class LegacyTouchSequence {
479
497
  * @return {!LegacyTouchSequence} A self reference.
480
498
  */
481
499
  longPress(elem) {
482
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_LONG_PRESS).
483
- setParameter('element', elem.getId());
500
+ const cmd = new command.Command(
501
+ command.Name.LEGACY_ACTION_TOUCH_LONG_PRESS
502
+ ).setParameter('element', elem.getId())
484
503
 
485
- this.schedule_('longPress', cmd);
486
- return this;
504
+ this.schedule_('longPress', cmd)
505
+ return this
487
506
  }
488
507
 
489
508
  /**
@@ -493,12 +512,12 @@ class LegacyTouchSequence {
493
512
  * @return {!LegacyTouchSequence} A self reference.
494
513
  */
495
514
  tapAndHold(location) {
496
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_DOWN).
497
- setParameter('x', location.x).
498
- setParameter('y', location.y);
515
+ const cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_DOWN)
516
+ .setParameter('x', location.x)
517
+ .setParameter('y', location.y)
499
518
 
500
- this.schedule_('tapAndHold', cmd);
501
- return this;
519
+ this.schedule_('tapAndHold', cmd)
520
+ return this
502
521
  }
503
522
 
504
523
  /**
@@ -508,12 +527,12 @@ class LegacyTouchSequence {
508
527
  * @return {!LegacyTouchSequence} A self reference.
509
528
  */
510
529
  move(location) {
511
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_MOVE).
512
- setParameter('x', location.x).
513
- setParameter('y', location.y);
530
+ const cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_MOVE)
531
+ .setParameter('x', location.x)
532
+ .setParameter('y', location.y)
514
533
 
515
- this.schedule_('move', cmd);
516
- return this;
534
+ this.schedule_('move', cmd)
535
+ return this
517
536
  }
518
537
 
519
538
  /**
@@ -523,12 +542,12 @@ class LegacyTouchSequence {
523
542
  * @return {!LegacyTouchSequence} A self reference.
524
543
  */
525
544
  release(location) {
526
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_UP).
527
- setParameter('x', location.x).
528
- setParameter('y', location.y);
545
+ let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_UP)
546
+ .setParameter('x', location.x)
547
+ .setParameter('y', location.y)
529
548
 
530
- this.schedule_('release', cmd);
531
- return this;
549
+ this.schedule_('release', cmd)
550
+ return this
532
551
  }
533
552
 
534
553
  /**
@@ -538,12 +557,12 @@ class LegacyTouchSequence {
538
557
  * @return {!LegacyTouchSequence} A self reference.
539
558
  */
540
559
  scroll(offset) {
541
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL).
542
- setParameter('xoffset', offset.x).
543
- setParameter('yoffset', offset.y);
560
+ const cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL)
561
+ .setParameter('xoffset', offset.x)
562
+ .setParameter('yoffset', offset.y)
544
563
 
545
- this.schedule_('scroll', cmd);
546
- return this;
564
+ this.schedule_('scroll', cmd)
565
+ return this
547
566
  }
548
567
 
549
568
  /**
@@ -555,13 +574,13 @@ class LegacyTouchSequence {
555
574
  * @return {!LegacyTouchSequence} A self reference.
556
575
  */
557
576
  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);
577
+ const cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_SCROLL)
578
+ .setParameter('element', elem.getId())
579
+ .setParameter('xoffset', offset.x)
580
+ .setParameter('yoffset', offset.y)
562
581
 
563
- this.schedule_('scrollFromElement', cmd);
564
- return this;
582
+ this.schedule_('scrollFromElement', cmd)
583
+ return this
565
584
  }
566
585
 
567
586
  /**
@@ -572,12 +591,12 @@ class LegacyTouchSequence {
572
591
  * @return {!LegacyTouchSequence} A self reference.
573
592
  */
574
593
  flick(speed) {
575
- let cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK).
576
- setParameter('xspeed', speed.xspeed).
577
- setParameter('yspeed', speed.yspeed);
594
+ const cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK)
595
+ .setParameter('xspeed', speed.xspeed)
596
+ .setParameter('yspeed', speed.yspeed)
578
597
 
579
- this.schedule_('flick', cmd);
580
- return this;
598
+ this.schedule_('flick', cmd)
599
+ return this
581
600
  }
582
601
 
583
602
  /**
@@ -589,21 +608,20 @@ class LegacyTouchSequence {
589
608
  * @return {!LegacyTouchSequence} A self reference.
590
609
  */
591
610
  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;
611
+ const cmd = new command.Command(command.Name.LEGACY_ACTION_TOUCH_FLICK)
612
+ .setParameter('element', elem.getId())
613
+ .setParameter('xoffset', offset.x)
614
+ .setParameter('yoffset', offset.y)
615
+ .setParameter('speed', speed)
616
+
617
+ this.schedule_('flickElement', cmd)
618
+ return this
600
619
  }
601
620
  }
602
621
 
603
-
604
622
  // PUBLIC API
605
623
 
606
624
  module.exports = {
607
625
  LegacyActionSequence,
608
626
  LegacyTouchSequence,
609
- };
627
+ }