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/ie.js CHANGED
@@ -25,23 +25,23 @@
25
25
  * [wiki](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver)
26
26
  */
27
27
 
28
- 'use strict';
29
-
30
- const fs = require('fs');
31
- const util = require('util');
32
-
33
- const http = require('./http');
34
- const io = require('./io');
35
- const portprober = require('./net/portprober');
36
- const promise = require('./lib/promise');
37
- const remote = require('./remote');
38
- const webdriver = require('./lib/webdriver');
39
- const {Browser, Capabilities, Capability} = require('./lib/capabilities');
40
-
41
-
42
- const IEDRIVER_EXE = 'IEDriverServer.exe';
43
-
44
-
28
+ 'use strict'
29
+
30
+ const fs = require('fs')
31
+ const http = require('./http')
32
+ const io = require('./io')
33
+ const portprober = require('./net/portprober')
34
+ const remote = require('./remote')
35
+ const webdriver = require('./lib/webdriver')
36
+ const { Browser, Capabilities } = require('./lib/capabilities')
37
+ const error = require('./lib/error')
38
+
39
+ const IEDRIVER_EXE = 'IEDriverServer.exe'
40
+ const OPTIONS_CAPABILITY_KEY = 'se:ieOptions'
41
+ const SCROLL_BEHAVIOUR = {
42
+ BOTTOM: 1,
43
+ TOP: 0,
44
+ }
45
45
 
46
46
  /**
47
47
  * IEDriverServer logging levels.
@@ -53,10 +53,8 @@ const Level = {
53
53
  WARN: 'WARN',
54
54
  INFO: 'INFO',
55
55
  DEBUG: 'DEBUG',
56
- TRACE: 'TRACE'
57
- };
58
-
59
-
56
+ TRACE: 'TRACE',
57
+ }
60
58
 
61
59
  /**
62
60
  * Option keys:
@@ -69,6 +67,7 @@ const Key = {
69
67
  INITIAL_BROWSER_URL: 'initialBrowserUrl',
70
68
  ENABLE_PERSISTENT_HOVER: 'enablePersistentHover',
71
69
  ENABLE_ELEMENT_CACHE_CLEANUP: 'enableElementCacheCleanup',
70
+ ELEMENT_SCROLL_BEHAVIOR: 'elementScrollBehavior',
72
71
  REQUIRE_WINDOW_FOCUS: 'requireWindowFocus',
73
72
  BROWSER_ATTACH_TIMEOUT: 'browserAttachTimeout',
74
73
  FORCE_CREATE_PROCESS: 'ie.forceCreateProcessApi',
@@ -79,9 +78,11 @@ const Key = {
79
78
  LOG_LEVEL: 'logLevel',
80
79
  HOST: 'host',
81
80
  EXTRACT_PATH: 'extractPath',
82
- SILENT: 'silent'
83
- };
84
-
81
+ SILENT: 'silent',
82
+ FILE_UPLOAD_DIALOG_TIMEOUT: 'ie.fileUploadDialogTimeout',
83
+ ATTACH_TO_EDGE_CHROMIUM: 'ie.edgechromium',
84
+ EDGE_EXECUTABLE_PATH: 'ie.edgepath',
85
+ }
85
86
 
86
87
  /**
87
88
  * Class for managing IEDriver specific options.
@@ -92,13 +93,18 @@ class Options extends Capabilities {
92
93
  * capabilities to initialize this instance from.
93
94
  */
94
95
  constructor(other = undefined) {
95
- super(other);
96
- this.setBrowserName(Browser.IE);
96
+ super(other)
97
+
98
+ /** @private {!Object} */
99
+ this.options_ = this.get(OPTIONS_CAPABILITY_KEY) || {}
100
+
101
+ this.set(OPTIONS_CAPABILITY_KEY, this.options_)
102
+ this.setBrowserName(Browser.INTERNET_EXPLORER)
97
103
  }
98
104
 
99
105
  /**
100
106
  * Whether to disable the protected mode settings check when the session is
101
- * created. Disbling this setting may lead to significant instability as the
107
+ * created. Disabling this setting may lead to significant instability as the
102
108
  * browser may become unresponsive/hang. Only "best effort" support is provided
103
109
  * when using this capability.
104
110
  *
@@ -109,8 +115,8 @@ class Options extends Capabilities {
109
115
  * @return {!Options} A self reference.
110
116
  */
111
117
  introduceFlakinessByIgnoringProtectedModeSettings(ignoreSettings) {
112
- this.set(Key.IGNORE_PROTECTED_MODE_SETTINGS, !!ignoreSettings);
113
- return this;
118
+ this.options_[Key.IGNORE_PROTECTED_MODE_SETTINGS] = !!ignoreSettings
119
+ return this
114
120
  }
115
121
 
116
122
  /**
@@ -121,13 +127,13 @@ class Options extends Capabilities {
121
127
  * @return {!Options} A self reference.
122
128
  */
123
129
  ignoreZoomSetting(ignore) {
124
- this.set(Key.IGNORE_ZOOM_SETTING, !!ignore);
125
- return this;
130
+ this.options_[Key.IGNORE_ZOOM_SETTING] = !!ignore
131
+ return this
126
132
  }
127
133
 
128
134
  /**
129
135
  * Sets the initial URL loaded when IE starts. This is intended to be used with
130
- * {@link #ignoreProtectedModeSettings} to allow the user to initialize IE in
136
+ * {@link #introduceFlakinessByIgnoringProtectedModeSettings} to allow the user to initialize IE in
131
137
  * the proper Protected Mode zone. Setting this option may cause browser
132
138
  * instability or flaky and unresponsive code. Only "best effort" support is
133
139
  * provided when using this option.
@@ -136,8 +142,8 @@ class Options extends Capabilities {
136
142
  * @return {!Options} A self reference.
137
143
  */
138
144
  initialBrowserUrl(url) {
139
- this.set(Key.INITIAL_BROWSER_URL, url);
140
- return this;
145
+ this.options_[Key.INITIAL_BROWSER_URL] = url
146
+ return this
141
147
  }
142
148
 
143
149
  /**
@@ -149,8 +155,8 @@ class Options extends Capabilities {
149
155
  * @return {!Options} A self reference.
150
156
  */
151
157
  enablePersistentHover(enable) {
152
- this.set(Key.ENABLE_PERSISTENT_HOVER, !!enable);
153
- return this;
158
+ this.options_[Key.ENABLE_PERSISTENT_HOVER] = !!enable
159
+ return this
154
160
  }
155
161
 
156
162
  /**
@@ -163,8 +169,8 @@ class Options extends Capabilities {
163
169
  * @return {!Options} A self reference.
164
170
  */
165
171
  enableElementCacheCleanup(enable) {
166
- this.set(Key.ENABLE_ELEMENT_CACHE_CLEANUP, !!enable);
167
- return this;
172
+ this.options_[Key.ENABLE_ELEMENT_CACHE_CLEANUP] = !!enable
173
+ return this
168
174
  }
169
175
 
170
176
  /**
@@ -177,8 +183,8 @@ class Options extends Capabilities {
177
183
  * @return {!Options} A self reference.
178
184
  */
179
185
  requireWindowFocus(require) {
180
- this.set(Key.REQUIRE_WINDOW_FOCUS, !!require);
181
- return this;
186
+ this.options_[Key.REQUIRE_WINDOW_FOCUS] = !!require
187
+ return this
182
188
  }
183
189
 
184
190
  /**
@@ -190,8 +196,8 @@ class Options extends Capabilities {
190
196
  * @return {!Options} A self reference.
191
197
  */
192
198
  browserAttachTimeout(timeout) {
193
- this.set(Key.BROWSER_ATTACH_TIMEOUT, Math.max(timeout, 0));
194
- return this;
199
+ this.options_[Key.BROWSER_ATTACH_TIMEOUT] = Math.max(timeout, 0)
200
+ return this
195
201
  }
196
202
 
197
203
  /**
@@ -204,8 +210,8 @@ class Options extends Capabilities {
204
210
  * @return {!Options} A self reference.
205
211
  */
206
212
  forceCreateProcessApi(force) {
207
- this.set(Key.FORCE_CREATE_PROCESS, !!force);
208
- return this;
213
+ this.options_[Key.FORCE_CREATE_PROCESS] = !!force
214
+ return this
209
215
  }
210
216
 
211
217
  /**
@@ -215,12 +221,32 @@ class Options extends Capabilities {
215
221
  * @param {...(string|!Array.<string>)} args The arguments to add.
216
222
  * @return {!Options} A self reference.
217
223
  */
224
+
225
+ addBrowserCommandSwitches(...args) {
226
+ let current = this.options_[Key.BROWSER_COMMAND_LINE_SWITCHES] || []
227
+ if (typeof current == 'string') current = current.split(' ')
228
+ this.options_[Key.BROWSER_COMMAND_LINE_SWITCHES] = current
229
+ .concat(args)
230
+ .join(' ')
231
+ return this
232
+ }
233
+
234
+ /**
235
+ * Specifies command-line switches to use when launching Internet Explorer.
236
+ * This is only valid when used with {@link #forceCreateProcessApi}.
237
+ *
238
+ * @param {...(string|!Array.<string>)} args The arguments to add.
239
+ * @deprecated Use {@link #addBrowserCommandSwitches} instead.
240
+ * @return {!Options} A self reference.
241
+ */
242
+
218
243
  addArguments(...args) {
219
- let current = this.get(Key.BROWSER_COMMAND_LINE_SWITCHES) || [];
220
- this.set(
221
- Key.BROWSER_COMMAND_LINE_SWITCHES,
222
- current.concat.apply(current, args));
223
- return this;
244
+ let current = this.options_[Key.BROWSER_COMMAND_LINE_SWITCHES] || []
245
+ if (typeof current == 'string') current = current.split(' ')
246
+ this.options_[Key.BROWSER_COMMAND_LINE_SWITCHES] = current
247
+ .concat(args)
248
+ .join(' ')
249
+ return this
224
250
  }
225
251
 
226
252
  /**
@@ -232,8 +258,8 @@ class Options extends Capabilities {
232
258
  * @return {!Options} A self reference.
233
259
  */
234
260
  usePerProcessProxy(enable) {
235
- this.set(Key.USE_PER_PROCESS_PROXY, !!enable);
236
- return this;
261
+ this.options_[Key.USE_PER_PROCESS_PROXY] = !!enable
262
+ return this
237
263
  }
238
264
 
239
265
  /**
@@ -246,8 +272,8 @@ class Options extends Capabilities {
246
272
  * @return {!Options} A self reference.
247
273
  */
248
274
  ensureCleanSession(cleanSession) {
249
- this.set(Key.ENSURE_CLEAN_SESSION, !!cleanSession);
250
- return this;
275
+ this.options_[Key.ENSURE_CLEAN_SESSION] = !!cleanSession
276
+ return this
251
277
  }
252
278
 
253
279
  /**
@@ -256,8 +282,8 @@ class Options extends Capabilities {
256
282
  * @return {!Options} A self reference.
257
283
  */
258
284
  setLogFile(file) {
259
- this.set(Key.LOG_FILE, file);
260
- return this;
285
+ this.options_[Key.LOG_FILE] = file
286
+ return this
261
287
  }
262
288
 
263
289
  /**
@@ -266,8 +292,8 @@ class Options extends Capabilities {
266
292
  * @return {!Options} A self reference.
267
293
  */
268
294
  setLogLevel(level) {
269
- this.set(Key.LOG_LEVEL, level);
270
- return this;
295
+ this.options_[Key.LOG_LEVEL] = level
296
+ return this
271
297
  }
272
298
 
273
299
  /**
@@ -276,8 +302,8 @@ class Options extends Capabilities {
276
302
  * @return {!Options} A self reference.
277
303
  */
278
304
  setHost(host) {
279
- this.set(Key.HOST, host);
280
- return this;
305
+ this.options_[Key.HOST] = host
306
+ return this
281
307
  }
282
308
 
283
309
  /**
@@ -286,8 +312,8 @@ class Options extends Capabilities {
286
312
  * @return {!Options} A self reference.
287
313
  */
288
314
  setExtractPath(path) {
289
- this.set(Key.EXTRACT_PATH, path);
290
- return this;
315
+ this.options_[Key.EXTRACT_PATH] = path
316
+ return this
291
317
  }
292
318
 
293
319
  /**
@@ -296,11 +322,61 @@ class Options extends Capabilities {
296
322
  * @return {!Options} A self reference.
297
323
  */
298
324
  silent(silent) {
299
- this.set(Key.SILENT, silent);
300
- return this;
325
+ this.options_[Key.SILENT] = silent
326
+ return this
327
+ }
328
+
329
+ /**
330
+ * The options File Upload Dialog Timeout in milliseconds
331
+ *
332
+ * @param {number} timeout How long to wait for IE.
333
+ * @return {!Options} A self reference.
334
+ */
335
+ fileUploadDialogTimeout(timeout) {
336
+ this.options_[Key.FILE_UPLOAD_DIALOG_TIMEOUT] = Math.max(timeout, 0)
337
+ return this
338
+ }
339
+
340
+ /**
341
+ * Sets the path of the EdgeChromium driver.
342
+ * @param {string} path The EdgeChromium driver path.
343
+ * @return {!Options} A self reference.
344
+ */
345
+ setEdgePath(path) {
346
+ this.options_[Key.EDGE_EXECUTABLE_PATH] = path
347
+ return this
348
+ }
349
+
350
+ /**
351
+ * Sets the IEDriver to drive Chromium-based Edge in Internet Explorer mode.
352
+ *
353
+ * @param {boolean} attachEdgeChromium Whether to run in Chromium-based-Edge in IE mode
354
+ * @return {!Options} A self reference.
355
+ */
356
+ setEdgeChromium(attachEdgeChromium) {
357
+ this.options_[Key.ATTACH_TO_EDGE_CHROMIUM] = !!attachEdgeChromium
358
+ return this
301
359
  }
302
- }
303
360
 
361
+ /**
362
+ * Sets how elements should be scrolled into view for interaction.
363
+ * @param {number} behavior The desired scroll behavior: either 0 to align with
364
+ * the top of the viewport or 1 to align with the bottom.
365
+ * @return {!Options} A self reference.
366
+ */
367
+ setScrollBehavior(behavior) {
368
+ if (
369
+ behavior &&
370
+ behavior !== SCROLL_BEHAVIOUR.TOP &&
371
+ behavior !== SCROLL_BEHAVIOUR.BOTTOM
372
+ ) {
373
+ throw new error.InvalidArgumentError(`Element Scroll Behavior out of range.
374
+ It should be either ${SCROLL_BEHAVIOUR.TOP} or ${SCROLL_BEHAVIOUR.BOTTOM}`)
375
+ }
376
+ this.options_[Key.ELEMENT_SCROLL_BEHAVIOR] = behavior
377
+ return this
378
+ }
379
+ }
304
380
 
305
381
  /**
306
382
  * _Synchronously_ attempts to locate the IE driver executable on the current
@@ -309,57 +385,57 @@ class Options extends Capabilities {
309
385
  * @return {?string} the located executable, or `null`.
310
386
  */
311
387
  function locateSynchronously() {
312
- return process.platform === 'win32'
313
- ? io.findInPath(IEDRIVER_EXE, true) : null;
388
+ return process.platform === 'win32' ? io.findInPath(IEDRIVER_EXE, true) : null
314
389
  }
315
390
 
316
-
317
391
  function createServiceFromCapabilities(capabilities) {
318
392
  if (process.platform !== 'win32') {
319
393
  throw Error(
320
- 'The IEDriver may only be used on Windows, but you appear to be on ' +
321
- process.platform + '. Did you mean to run against a remote ' +
322
- 'WebDriver server?');
394
+ 'The IEDriver may only be used on Windows, but you appear to be on ' +
395
+ process.platform +
396
+ '. Did you mean to run against a remote ' +
397
+ 'WebDriver server?'
398
+ )
323
399
  }
324
400
 
325
- let exe = locateSynchronously();
401
+ let exe = locateSynchronously()
326
402
  if (!exe || !fs.existsSync(exe)) {
327
403
  throw Error(
328
- `${IEDRIVER_EXE} could not be found on the current PATH. Please ` +
404
+ `${IEDRIVER_EXE} could not be found on the current PATH. Please ` +
329
405
  `download the latest version of ${IEDRIVER_EXE} from ` +
330
406
  'http://selenium-release.storage.googleapis.com/index.html and ' +
331
- 'ensure it can be found on your system PATH.');
407
+ 'ensure it can be found on your system PATH.'
408
+ )
332
409
  }
333
410
 
334
- var args = [];
411
+ var args = []
335
412
  if (capabilities.has(Key.HOST)) {
336
- args.push('--host=' + capabilities.get(Key.HOST));
413
+ args.push('--host=' + capabilities.get(Key.HOST))
337
414
  }
338
415
  if (capabilities.has(Key.LOG_FILE)) {
339
- args.push('--log-file=' + capabilities.get(Key.LOG_FILE));
416
+ args.push('--log-file=' + capabilities.get(Key.LOG_FILE))
340
417
  }
341
418
  if (capabilities.has(Key.LOG_LEVEL)) {
342
- args.push('--log-level=' + capabilities.get(Key.LOG_LEVEL));
419
+ args.push('--log-level=' + capabilities.get(Key.LOG_LEVEL))
343
420
  }
344
421
  if (capabilities.has(Key.EXTRACT_PATH)) {
345
- args.push('--extract-path=' + capabilities.get(Key.EXTRACT_PATH));
422
+ args.push('--extract-path=' + capabilities.get(Key.EXTRACT_PATH))
346
423
  }
347
424
  if (capabilities.get(Key.SILENT)) {
348
- args.push('--silent');
425
+ args.push('--silent')
349
426
  }
350
427
 
351
- var port = portprober.findFreePort();
428
+ var port = portprober.findFreePort()
352
429
  return new remote.DriverService(exe, {
353
430
  loopback: true,
354
431
  port: port,
355
- args: port.then(function(port) {
356
- return args.concat('--port=' + port);
432
+ args: port.then(function (port) {
433
+ return args.concat('--port=' + port)
357
434
  }),
358
- stdio: 'ignore'
359
- });
435
+ stdio: 'ignore',
436
+ })
360
437
  }
361
438
 
362
-
363
439
  /**
364
440
  * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
365
441
  * an [IEDriverServer](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver)
@@ -371,12 +447,11 @@ class ServiceBuilder extends remote.DriverService.Builder {
371
447
  * the builder will attempt to locate the IEDriverServer on the system PATH.
372
448
  */
373
449
  constructor(opt_exe) {
374
- super(opt_exe || IEDRIVER_EXE);
375
- this.setLoopback(true); // Required.
450
+ super(opt_exe || IEDRIVER_EXE)
451
+ this.setLoopback(true) // Required.
376
452
  }
377
453
  }
378
454
 
379
-
380
455
  /**
381
456
  * A WebDriver client for Microsoft's Internet Explorer.
382
457
  */
@@ -390,21 +465,22 @@ class Driver extends webdriver.WebDriver {
390
465
  * @return {!Driver} A new driver instance.
391
466
  */
392
467
  static createSession(options, opt_service) {
393
- options = options || new Options();
468
+ options = options || new Options()
394
469
 
395
- let service;
470
+ let service
396
471
 
397
472
  if (opt_service instanceof remote.DriverService) {
398
- service = opt_service;
473
+ service = opt_service
399
474
  } else {
400
- service = createServiceFromCapabilities(options);
475
+ service = createServiceFromCapabilities(options)
401
476
  }
402
477
 
403
- let client = service.start().then(url => new http.HttpClient(url));
404
- let executor = new http.Executor(client);
478
+ let client = service.start().then((url) => new http.HttpClient(url))
479
+ let executor = new http.Executor(client)
405
480
 
406
- return /** @type {!Driver} */(super.createSession(
407
- executor, options, () => service.kill()));
481
+ return /** @type {!Driver} */ (super.createSession(executor, options, () =>
482
+ service.kill()
483
+ ))
408
484
  }
409
485
 
410
486
  /**
@@ -415,13 +491,13 @@ class Driver extends webdriver.WebDriver {
415
491
  setFileDetector() {}
416
492
  }
417
493
 
418
-
419
494
  // PUBLIC API
420
495
 
421
-
422
- exports.Driver = Driver;
423
- exports.Options = Options;
424
- exports.Level = Level;
425
- exports.ServiceBuilder = ServiceBuilder;
426
- exports.locateSynchronously = locateSynchronously;
427
-
496
+ exports.Driver = Driver
497
+ exports.Options = Options
498
+ exports.Level = Level
499
+ exports.ServiceBuilder = ServiceBuilder
500
+ exports.Key = Key
501
+ exports.VENDOR_COMMAND_PREFIX = OPTIONS_CAPABILITY_KEY
502
+ exports.Behavior = SCROLL_BEHAVIOUR
503
+ exports.locateSynchronously = locateSynchronously