selenium-webdriver 4.0.0-alpha.5 → 4.0.0-beta.1

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 (49) hide show
  1. package/CHANGES.md +35 -1
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/README.md +4 -4
  5. package/chrome.js +72 -592
  6. package/chromium.js +829 -0
  7. package/devtools/CDPConnection.js +37 -0
  8. package/edge.js +124 -86
  9. package/example/chrome_android.js +16 -13
  10. package/example/chrome_mobile_emulation.js +18 -14
  11. package/example/firefox_channels.js +35 -28
  12. package/example/google_search.js +9 -9
  13. package/example/google_search_test.js +20 -22
  14. package/example/headless.js +27 -19
  15. package/example/logging.js +34 -38
  16. package/firefox.js +200 -200
  17. package/http/index.js +131 -115
  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 +140 -122
  25. package/lib/atoms/find-elements.js +124 -0
  26. package/lib/atoms/get-attribute.js +79 -59
  27. package/lib/atoms/is-displayed.js +72 -73
  28. package/lib/atoms/mutation-listener.js +38 -0
  29. package/lib/by.js +192 -65
  30. package/lib/capabilities.js +82 -78
  31. package/lib/command.js +20 -20
  32. package/lib/error.js +134 -168
  33. package/lib/http.js +337 -230
  34. package/lib/input.js +325 -302
  35. package/lib/logging.js +127 -138
  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 +1024 -541
  42. package/net/index.js +30 -36
  43. package/net/portprober.js +31 -144
  44. package/opera.js +406 -0
  45. package/package.json +19 -12
  46. package/proxy.js +2 -2
  47. package/remote/index.js +190 -187
  48. package/safari.js +40 -49
  49. package/testing/index.js +166 -155
@@ -15,16 +15,14 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- 'use strict';
18
+ 'use strict'
19
19
 
20
20
  /**
21
21
  * @fileoverview Defines types related to describing the capabilities of a
22
22
  * WebDriver session.
23
23
  */
24
24
 
25
- const proxy = require('./proxy');
26
- const Symbols = require('./symbols');
27
-
25
+ const Symbols = require('./symbols')
28
26
 
29
27
  /**
30
28
  * Recognized browser names.
@@ -37,8 +35,8 @@ const Browser = {
37
35
  IE: 'internet explorer',
38
36
  INTERNET_EXPLORER: 'internet explorer',
39
37
  SAFARI: 'safari',
40
- };
41
-
38
+ OPERA: 'opera',
39
+ }
42
40
 
43
41
  /**
44
42
  * Strategies for waiting for [document readiness] after a navigation
@@ -65,9 +63,8 @@ const PageLoadStrategy = {
65
63
  * Indicates WebDriver should wait for the document readiness state to
66
64
  * be "complete" after navigation. This is the default page loading strategy.
67
65
  */
68
- NORMAL: 'normal'
69
- };
70
-
66
+ NORMAL: 'normal',
67
+ }
71
68
 
72
69
  /**
73
70
  * Common platform names. These platforms are not explicitly defined by the
@@ -79,39 +76,37 @@ const PageLoadStrategy = {
79
76
  const Platform = {
80
77
  LINUX: 'linux',
81
78
  MAC: 'mac',
82
- WINDOWS: 'windows'
83
- };
84
-
79
+ WINDOWS: 'windows',
80
+ }
85
81
 
86
82
  /**
87
83
  * Record object defining the timeouts that apply to certain WebDriver actions.
88
84
  *
89
85
  * @record
90
86
  */
91
- function Timeouts() {}
87
+ function Timeouts() { }
92
88
 
93
89
  /**
94
- * Defines when, in milliseconds, to interupt a script that is being
90
+ * Defines when, in milliseconds, to interrupt a script that is being
95
91
  * {@linkplain ./webdriver.IWebDriver#executeScript evaluated}.
96
92
  * @type {number}
97
93
  */
98
- Timeouts.prototype.script;
94
+ Timeouts.prototype.script
99
95
 
100
96
  /**
101
97
  * The timeout, in milliseconds, to apply to navigation events along with the
102
98
  * {@link PageLoadStrategy}.
103
99
  * @type {number}
104
100
  */
105
- Timeouts.prototype.pageLoad;
101
+ Timeouts.prototype.pageLoad
106
102
 
107
103
  /**
108
- * The maximimum amount of time, in milliseconds, to spend attempting to
104
+ * The maximum amount of time, in milliseconds, to spend attempting to
109
105
  * {@linkplain ./webdriver.IWebDriver#findElement locate} an element on the
110
106
  * current page.
111
107
  * @type {number}
112
108
  */
113
- Timeouts.prototype.implicit;
114
-
109
+ Timeouts.prototype.implicit
115
110
 
116
111
  /**
117
112
  * The possible default actions a WebDriver session can take to respond to
@@ -136,9 +131,8 @@ const UserPromptHandler = {
136
131
  */
137
132
  DISMISS_AND_NOTIFY: 'dismiss and notify',
138
133
  /** All prompts should be left unhandled. */
139
- IGNORE: 'ignore'
140
- };
141
-
134
+ IGNORE: 'ignore',
135
+ }
142
136
 
143
137
  /**
144
138
  * The standard WebDriver capability keys.
@@ -147,9 +141,8 @@ const UserPromptHandler = {
147
141
  * @see <https://w3c.github.io/webdriver/webdriver-spec.html#capabilities>
148
142
  */
149
143
  const Capability = {
150
-
151
144
  /**
152
- * Indicates whether a WebDriver session implicity trusts otherwise untrusted
145
+ * Indicates whether a WebDriver session implicitly trusts otherwise untrusted
153
146
  * and self-signed TLS certificates during navigation.
154
147
  */
155
148
  ACCEPT_INSECURE_TLS_CERTS: 'acceptInsecureCerts',
@@ -212,8 +205,13 @@ const Capability = {
212
205
  * prompts.
213
206
  */
214
207
  UNHANDLED_PROMPT_BEHAVIOR: 'unhandledPromptBehavior',
215
- };
216
208
 
209
+ /**
210
+ * Defines the current session’s strict file interactability.
211
+ * Used to upload a file when strict file interactability is on
212
+ */
213
+ STRICT_FILE_INTERACTABILITY: 'strictFileInteractability',
214
+ }
217
215
 
218
216
  /**
219
217
  * Converts a generic hash object to a map.
@@ -221,16 +219,15 @@ const Capability = {
221
219
  * @return {!Map<string, ?>} The converted map.
222
220
  */
223
221
  function toMap(hash) {
224
- let m = new Map;
222
+ let m = new Map()
225
223
  for (let key in hash) {
226
- if (hash.hasOwnProperty(key)) {
227
- m.set(key, hash[key]);
224
+ if (Object.prototype.hasOwnProperty.call(hash, key)) {
225
+ m.set(key, hash[key])
228
226
  }
229
227
  }
230
- return m;
228
+ return m
231
229
  }
232
230
 
233
-
234
231
  /**
235
232
  * Describes a set of capabilities for a WebDriver session.
236
233
  */
@@ -241,47 +238,47 @@ class Capabilities {
241
238
  */
242
239
  constructor(other = undefined) {
243
240
  if (other instanceof Capabilities) {
244
- other = other.map_;
241
+ other = other.map_
245
242
  } else if (other && !(other instanceof Map)) {
246
- other = toMap(other);
243
+ other = toMap(other)
247
244
  }
248
245
  /** @private @const {!Map<string, ?>} */
249
- this.map_ = new Map(other);
246
+ this.map_ = new Map(other)
250
247
  }
251
248
 
252
249
  /**
253
250
  * @return {!Capabilities} A basic set of capabilities for Chrome.
254
251
  */
255
252
  static chrome() {
256
- return new Capabilities().setBrowserName(Browser.CHROME);
253
+ return new Capabilities().setBrowserName(Browser.CHROME)
257
254
  }
258
255
 
259
256
  /**
260
257
  * @return {!Capabilities} A basic set of capabilities for Microsoft Edge.
261
258
  */
262
259
  static edge() {
263
- return new Capabilities().setBrowserName(Browser.EDGE);
260
+ return new Capabilities().setBrowserName(Browser.EDGE)
264
261
  }
265
262
 
266
263
  /**
267
264
  * @return {!Capabilities} A basic set of capabilities for Firefox.
268
265
  */
269
266
  static firefox() {
270
- return new Capabilities().setBrowserName(Browser.FIREFOX);
267
+ return new Capabilities().setBrowserName(Browser.FIREFOX).set("moz:debuggerAddress", true)
271
268
  }
272
269
 
273
270
  /**
274
271
  * @return {!Capabilities} A basic set of capabilities for Internet Explorer.
275
272
  */
276
273
  static ie() {
277
- return new Capabilities().setBrowserName(Browser.INTERNET_EXPLORER);
274
+ return new Capabilities().setBrowserName(Browser.INTERNET_EXPLORER)
278
275
  }
279
276
 
280
277
  /**
281
278
  * @return {!Capabilities} A basic set of capabilities for Safari.
282
279
  */
283
280
  static safari() {
284
- return new Capabilities().setBrowserName(Browser.SAFARI);
281
+ return new Capabilities().setBrowserName(Browser.SAFARI)
285
282
  }
286
283
 
287
284
  /**
@@ -291,7 +288,7 @@ class Capabilities {
291
288
  * Map).
292
289
  */
293
290
  [Symbols.serialize]() {
294
- return serialize(this);
291
+ return serialize(this)
295
292
  }
296
293
 
297
294
  /**
@@ -300,7 +297,7 @@ class Capabilities {
300
297
  * @template T
301
298
  */
302
299
  get(key) {
303
- return this.map_.get(key);
300
+ return this.map_.get(key)
304
301
  }
305
302
 
306
303
  /**
@@ -308,19 +305,19 @@ class Capabilities {
308
305
  * @return {boolean} whether this capability set has the specified key.
309
306
  */
310
307
  has(key) {
311
- return this.map_.has(key);
308
+ return this.map_.has(key)
312
309
  }
313
310
 
314
311
  /**
315
312
  * @return {!Iterator<string>} an iterator of the keys set.
316
313
  */
317
314
  keys() {
318
- return this.map_.keys();
315
+ return this.map_.keys()
319
316
  }
320
317
 
321
318
  /** @return {number} The number of capabilities set. */
322
319
  get size() {
323
- return this.map_.size;
320
+ return this.map_.size
324
321
  }
325
322
 
326
323
  /**
@@ -331,20 +328,20 @@ class Capabilities {
331
328
  */
332
329
  merge(other) {
333
330
  if (other) {
334
- let otherMap;
331
+ let otherMap
335
332
  if (other instanceof Capabilities) {
336
- otherMap = other.map_;
333
+ otherMap = other.map_
337
334
  } else if (other instanceof Map) {
338
- otherMap = other;
335
+ otherMap = other
339
336
  } else {
340
- otherMap = toMap(other);
337
+ otherMap = toMap(other)
341
338
  }
342
339
  otherMap.forEach((value, key) => {
343
- this.set(key, value);
344
- });
345
- return this;
340
+ this.set(key, value)
341
+ })
342
+ return this
346
343
  } else {
347
- throw new TypeError('no capabilities provided for merge');
344
+ throw new TypeError('no capabilities provided for merge')
348
345
  }
349
346
  }
350
347
 
@@ -354,7 +351,7 @@ class Capabilities {
354
351
  * @param {string} key the capability key to delete.
355
352
  */
356
353
  delete(key) {
357
- this.map_.delete(key);
354
+ this.map_.delete(key)
358
355
  }
359
356
 
360
357
  /**
@@ -365,10 +362,10 @@ class Capabilities {
365
362
  */
366
363
  set(key, value) {
367
364
  if (typeof key !== 'string') {
368
- throw new TypeError('Capability keys must be strings: ' + typeof key);
365
+ throw new TypeError('Capability keys must be strings: ' + typeof key)
369
366
  }
370
- this.map_.set(key, value);
371
- return this;
367
+ this.map_.set(key, value)
368
+ return this
372
369
  }
373
370
 
374
371
  /**
@@ -379,7 +376,7 @@ class Capabilities {
379
376
  * @return {!Capabilities} a self reference.
380
377
  */
381
378
  setAcceptInsecureCerts(accept) {
382
- return this.set(Capability.ACCEPT_INSECURE_TLS_CERTS, accept);
379
+ return this.set(Capability.ACCEPT_INSECURE_TLS_CERTS, accept)
383
380
  }
384
381
 
385
382
  /**
@@ -387,7 +384,7 @@ class Capabilities {
387
384
  * TLS certificates.
388
385
  */
389
386
  getAcceptInsecureCerts() {
390
- return this.get(Capability.ACCEPT_INSECURE_TLS_CERTS);
387
+ return this.get(Capability.ACCEPT_INSECURE_TLS_CERTS)
391
388
  }
392
389
 
393
390
  /**
@@ -397,7 +394,7 @@ class Capabilities {
397
394
  * @return {!Capabilities} a self reference.
398
395
  */
399
396
  setBrowserName(name) {
400
- return this.set(Capability.BROWSER_NAME, name);
397
+ return this.set(Capability.BROWSER_NAME, name)
401
398
  }
402
399
 
403
400
  /**
@@ -405,7 +402,7 @@ class Capabilities {
405
402
  * not set.
406
403
  */
407
404
  getBrowserName() {
408
- return this.get(Capability.BROWSER_NAME);
405
+ return this.get(Capability.BROWSER_NAME)
409
406
  }
410
407
 
411
408
  /**
@@ -415,7 +412,7 @@ class Capabilities {
415
412
  * @return {!Capabilities} a self reference.
416
413
  */
417
414
  setBrowserVersion(version) {
418
- return this.set(Capability.BROWSER_VERSION, version);
415
+ return this.set(Capability.BROWSER_VERSION, version)
419
416
  }
420
417
 
421
418
  /**
@@ -423,7 +420,7 @@ class Capabilities {
423
420
  * if not set.
424
421
  */
425
422
  getBrowserVersion() {
426
- return this.get(Capability.BROWSER_VERSION);
423
+ return this.get(Capability.BROWSER_VERSION)
427
424
  }
428
425
 
429
426
  /**
@@ -433,7 +430,7 @@ class Capabilities {
433
430
  * @return {!Capabilities} a self reference.
434
431
  */
435
432
  setPageLoadStrategy(strategy) {
436
- return this.set(Capability.PAGE_LOAD_STRATEGY, strategy);
433
+ return this.set(Capability.PAGE_LOAD_STRATEGY, strategy)
437
434
  }
438
435
 
439
436
  /**
@@ -442,7 +439,7 @@ class Capabilities {
442
439
  * @return {(string|undefined)} the page load strategy.
443
440
  */
444
441
  getPageLoadStrategy() {
445
- return this.get(Capability.PAGE_LOAD_STRATEGY);
442
+ return this.get(Capability.PAGE_LOAD_STRATEGY)
446
443
  }
447
444
 
448
445
  /**
@@ -452,7 +449,7 @@ class Capabilities {
452
449
  * @return {!Capabilities} a self reference.
453
450
  */
454
451
  setPlatform(platform) {
455
- return this.set(Capability.PLATFORM_NAME, platform);
452
+ return this.set(Capability.PLATFORM_NAME, platform)
456
453
  }
457
454
 
458
455
  /**
@@ -460,7 +457,7 @@ class Capabilities {
460
457
  * set.
461
458
  */
462
459
  getPlatform() {
463
- return this.get(Capability.PLATFORM_NAME);
460
+ return this.get(Capability.PLATFORM_NAME)
464
461
  }
465
462
 
466
463
  /**
@@ -472,7 +469,7 @@ class Capabilities {
472
469
  * @return {!Capabilities} A self reference.
473
470
  */
474
471
  setLoggingPrefs(prefs) {
475
- return this.set(Capability.LOGGING_PREFS, prefs);
472
+ return this.set(Capability.LOGGING_PREFS, prefs)
476
473
  }
477
474
 
478
475
  /**
@@ -481,7 +478,7 @@ class Capabilities {
481
478
  * @return {!Capabilities} A self reference.
482
479
  */
483
480
  setProxy(proxy) {
484
- return this.set(Capability.PROXY, proxy);
481
+ return this.set(Capability.PROXY, proxy)
485
482
  }
486
483
 
487
484
  /**
@@ -489,7 +486,7 @@ class Capabilities {
489
486
  * undefined if not set.
490
487
  */
491
488
  getProxy() {
492
- return this.get(Capability.PROXY);
489
+ return this.get(Capability.PROXY)
493
490
  }
494
491
 
495
492
  /**
@@ -502,7 +499,7 @@ class Capabilities {
502
499
  * @return {!Capabilities} A self reference.
503
500
  */
504
501
  setAlertBehavior(behavior) {
505
- return this.set(Capability.UNHANDLED_PROMPT_BEHAVIOR, behavior);
502
+ return this.set(Capability.UNHANDLED_PROMPT_BEHAVIOR, behavior)
506
503
  }
507
504
 
508
505
  /**
@@ -510,10 +507,19 @@ class Capabilities {
510
507
  * to unhandled user prompts, or undefined if not set.
511
508
  */
512
509
  getAlertBehavior() {
513
- return this.get(Capability.UNHANDLED_PROMPT_BEHAVIOR);
510
+ return this.get(Capability.UNHANDLED_PROMPT_BEHAVIOR)
514
511
  }
515
- }
516
512
 
513
+ /**
514
+ * Sets the boolean flag configuration for this instance.
515
+ */
516
+ setStrictFileInteractability(strictFileInteractability) {
517
+ return this.set(
518
+ Capability.STRICT_FILE_INTERACTABILITY,
519
+ strictFileInteractability
520
+ )
521
+ }
522
+ }
517
523
 
518
524
  /**
519
525
  * Serializes a capabilities object. This is defined as a standalone function
@@ -525,20 +531,18 @@ class Capabilities {
525
531
  * Note, the returned object may contain nested promised values.
526
532
  */
527
533
  function serialize(caps) {
528
- let ret = {};
534
+ let ret = {}
529
535
  for (let key of caps.keys()) {
530
- let cap = caps.get(key);
536
+ let cap = caps.get(key)
531
537
  if (cap !== undefined && cap !== null) {
532
- ret[key] = cap;
538
+ ret[key] = cap
533
539
  }
534
540
  }
535
- return ret;
541
+ return ret
536
542
  }
537
543
 
538
-
539
544
  // PUBLIC API
540
545
 
541
-
542
546
  module.exports = {
543
547
  Browser,
544
548
  Capabilities,
@@ -547,4 +551,4 @@ module.exports = {
547
551
  Platform,
548
552
  Timeouts,
549
553
  UserPromptHandler,
550
- };
554
+ }
package/lib/command.js CHANGED
@@ -19,7 +19,7 @@
19
19
  * @fileoverview Contains several classes for handling commands.
20
20
  */
21
21
 
22
- 'use strict';
22
+ 'use strict'
23
23
 
24
24
  /**
25
25
  * Describes a command to execute.
@@ -29,15 +29,15 @@ class Command {
29
29
  /** @param {string} name The name of this command. */
30
30
  constructor(name) {
31
31
  /** @private {string} */
32
- this.name_ = name;
32
+ this.name_ = name
33
33
 
34
34
  /** @private {!Object<*>} */
35
- this.parameters_ = {};
35
+ this.parameters_ = {}
36
36
  }
37
37
 
38
38
  /** @return {string} This command's name. */
39
39
  getName() {
40
- return this.name_;
40
+ return this.name_
41
41
  }
42
42
 
43
43
  /**
@@ -47,8 +47,8 @@ class Command {
47
47
  * @return {!Command} A self reference.
48
48
  */
49
49
  setParameter(name, value) {
50
- this.parameters_[name] = value;
51
- return this;
50
+ this.parameters_[name] = value
51
+ return this
52
52
  }
53
53
 
54
54
  /**
@@ -57,8 +57,8 @@ class Command {
57
57
  * @return {!Command} A self reference.
58
58
  */
59
59
  setParameters(parameters) {
60
- this.parameters_ = parameters;
61
- return this;
60
+ this.parameters_ = parameters
61
+ return this
62
62
  }
63
63
 
64
64
  /**
@@ -67,18 +67,17 @@ class Command {
67
67
  * @return {*} The parameter value, or undefined if it has not been set.
68
68
  */
69
69
  getParameter(key) {
70
- return this.parameters_[key];
70
+ return this.parameters_[key]
71
71
  }
72
72
 
73
73
  /**
74
74
  * @return {!Object<*>} The parameters to send with this command.
75
75
  */
76
76
  getParameters() {
77
- return this.parameters_;
77
+ return this.parameters_
78
78
  }
79
79
  }
80
80
 
81
-
82
81
  /**
83
82
  * Enumeration of predefined names command names that all command processors
84
83
  * will support.
@@ -109,6 +108,7 @@ const Name = {
109
108
  GET_ACTIVE_ELEMENT: 'getActiveElement',
110
109
  FIND_ELEMENT: 'findElement',
111
110
  FIND_ELEMENTS: 'findElements',
111
+ FIND_ELEMENTS_RELATIVE: 'findElementsRelative',
112
112
  FIND_CHILD_ELEMENT: 'findChildElement',
113
113
  FIND_CHILD_ELEMENTS: 'findChildElements',
114
114
 
@@ -140,6 +140,8 @@ const Name = {
140
140
  EXECUTE_ASYNC_SCRIPT: 'executeAsyncScript',
141
141
 
142
142
  GET_ELEMENT_TEXT: 'getElementText',
143
+ GET_COMPUTED_ROLE: 'getAriaRole',
144
+ GET_COMPUTED_LABEL: 'getAccessibleName',
143
145
  GET_ELEMENT_TAG_NAME: 'getElementTagName',
144
146
  IS_ELEMENT_SELECTED: 'isElementSelected',
145
147
  IS_ELEMENT_ENABLED: 'isElementEnabled',
@@ -150,11 +152,14 @@ const Name = {
150
152
  GET_ELEMENT_SIZE: 'getElementSize',
151
153
  GET_ELEMENT_ATTRIBUTE: 'getElementAttribute',
152
154
  GET_ELEMENT_VALUE_OF_CSS_PROPERTY: 'getElementValueOfCssProperty',
155
+ GET_ELEMENT_PROPERTY: 'getElementProperty',
153
156
 
154
157
  SCREENSHOT: 'screenshot',
155
158
  TAKE_ELEMENT_SCREENSHOT: 'takeElementScreenshot',
156
159
  SET_SCRIPT_TIMEOUT: 'setScriptTimeout',
157
160
 
161
+ PRINT_PAGE: 'printPage',
162
+
158
163
  GET_TIMEOUT: 'getTimeout',
159
164
  SET_TIMEOUT: 'setTimeout',
160
165
 
@@ -187,9 +192,7 @@ const Name = {
187
192
  LEGACY_ACTION_TOUCH_FLICK: 'legacyAction:touchFlick',
188
193
  LEGACY_ACTION_TOUCH_SINGLE_TAP: 'legacyAction:singleTap',
189
194
  LEGACY_ACTION_TOUCH_DOUBLE_TAP: 'legacyAction:doubleTap',
190
- };
191
-
192
-
195
+ }
193
196
 
194
197
  /**
195
198
  * Handles the execution of WebDriver {@link Command commands}.
@@ -206,16 +209,13 @@ class Executor {
206
209
  * @return {!Promise<?>} A promise that will be fulfilled with the command
207
210
  * result.
208
211
  */
209
- execute(command) {}
212
+ execute(command) {} // eslint-disable-line
210
213
  }
211
214
 
212
-
213
-
214
215
  // PUBLIC API
215
216
 
216
-
217
217
  module.exports = {
218
218
  Command: Command,
219
219
  Name: Name,
220
- Executor: Executor
221
- };
220
+ Executor: Executor,
221
+ }