selenium-webdriver 4.0.0-beta.3 → 4.0.0

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.
package/CHANGES.md CHANGED
@@ -1,3 +1,45 @@
1
+ ## v4.0.0
2
+
3
+ * Fixes cdp for Chrome and Firefox (#9909)
4
+ * Add cdp 95 to python and JS
5
+ * Removing unused target for cdpConnection
6
+
7
+
8
+ ## v4.0.0-rc-2
9
+
10
+ * Fix builder test
11
+ * Allow builder to set a single arbitrary capability (#9857)
12
+ * Restore withCapabilities() to ensure backward compatibility
13
+ * Add new websocketUrl capability
14
+ * update ruby, python and JS to add support for v94 and remove support for v92
15
+ * Add a check for Grid CDP endpoint
16
+ * Implement network request interceptions
17
+ * Update connections to devtools so it works in Firefox and Chrome
18
+
19
+ ## v4.0.0-rc-1
20
+
21
+ * Deprecates withCapabilities method and removes tests (#9701)
22
+ * expose `withLocator` method at the top level
23
+ * Enables Mobile feature for Firefox (Still need to expand this to chromium based browsers)
24
+
25
+ * Add the ability to do Relative Locators with all By types. Fixes #9559
26
+ * Add default Opera capabilities. Fixes #9654
27
+ * Add support for ChromeDriver `--enable-chrome-logs` (#9575) [Author: Mark Stacey]
28
+
29
+ The `--enable-chrome-logs` ChromeDriver option can now be enabled using
30
+ the Chromium (or Chrome) ServiceBuilder, similarly to the other options
31
+ provided by ChromeDriver.
32
+
33
+ * Add the debuggerAddress option to chromium.js (#9561) [Author: Brandon Walderman]
34
+ * Adds http client options (#9638)[Author: Dharin Shah]
35
+ * Updating edge.js to extend chromium.driver (fixes #9626)
36
+
37
+
38
+ ## v4.0.0-beta.4
39
+
40
+ * Add windowTypes option support for ChromiumDriver (#7897)
41
+ * Allow relativeby with findElement (#9396)
42
+
1
43
  ## v4.0.0-beta.3
2
44
 
3
45
  * Removed support for legacy actions.
package/README.md CHANGED
@@ -223,7 +223,9 @@ under the License.
223
223
  [edge]: http://go.microsoft.com/fwlink/?LinkId=619687
224
224
  [geckodriver]: https://github.com/mozilla/geckodriver/releases/
225
225
  [reduction]: http://www.webkit.org/quality/reduction.html
226
- [release]: http://selenium-release.storage.googleapis.com/index.html
226
+
227
+ [release]: https://www.selenium.dev/downloads/
228
+
227
229
  [users]: https://groups.google.com/forum/#!forum/selenium-users
228
230
  [safaridriver]: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html#//apple_ref/doc/uid/TP40014305-CH11-DontLinkElementID_28
229
- [operadriver]: https://github.com/operasoftware/operachromiumdriver/releases
231
+ [operadriver]: https://github.com/operasoftware/operachromiumdriver/releases
package/chrome.js CHANGED
@@ -236,10 +236,9 @@ class Driver extends chromium.Driver {
236
236
  */
237
237
  static createSession(opt_config, opt_serviceExecutor) {
238
238
  let caps = opt_config || new Options()
239
- return /** @type {!Driver} */ (super.createSession(
240
- caps,
241
- opt_serviceExecutor
242
- ))
239
+ return /** @type {!Driver} */ (
240
+ super.createSession(caps, opt_serviceExecutor)
241
+ )
243
242
  }
244
243
  }
245
244
 
package/chromium.js CHANGED
@@ -213,6 +213,14 @@ class ServiceBuilder extends remote.DriverService.Builder {
213
213
  return this.addArguments('--log-path=' + path)
214
214
  }
215
215
 
216
+ /**
217
+ * Enables Chrome logging.
218
+ * @returns {!ServiceBuilder} A self reference.
219
+ */
220
+ enableChromeLogging() {
221
+ return this.addArguments('--enable-chrome-logs');
222
+ }
223
+
216
224
  /**
217
225
  * Enables verbose logging.
218
226
  * @return {!ServiceBuilder} A self reference.
@@ -275,6 +283,19 @@ class Options extends Capabilities {
275
283
  return this
276
284
  }
277
285
 
286
+ /**
287
+ * Sets the address of a Chromium remote debugging server to connect to.
288
+ * Address should be of the form "{hostname|IP address}:port"
289
+ * (e.g. "localhost:9222").
290
+ *
291
+ * @param {string} address The address to connect to.
292
+ * @return {!Options} A self reference.
293
+ */
294
+ debuggerAddress(address) {
295
+ this.options_.debuggerAddress = address;
296
+ return this
297
+ }
298
+
278
299
  /**
279
300
  * Configures the driver to start the browser in headless mode.
280
301
  *
@@ -549,6 +570,21 @@ class Options extends Capabilities {
549
570
  return this
550
571
  }
551
572
 
573
+ /**
574
+ * Sets a list of the window types that will appear when getting window
575
+ * handles. For access to <webview> elements, include "webview" in the list.
576
+ * @param {...(string|!Array<string>)} args The window types that will appear
577
+ * when getting window handles.
578
+ * @return {!Options} A self reference.
579
+ */
580
+ windowTypes(...args) {
581
+ let windowTypes = (this.options_.windowTypes || []).concat(...args)
582
+ if (windowTypes.length) {
583
+ this.options_.windowTypes = windowTypes
584
+ }
585
+ return this
586
+ }
587
+
552
588
  /**
553
589
  * Converts this instance to its JSON wire protocol representation. Note this
554
590
  * function is an implementation not intended for general use.
@@ -565,7 +601,7 @@ class Options extends Capabilities {
565
601
  return extension.toString('base64')
566
602
  }
567
603
  return io
568
- .read(/** @type {string} */(extension))
604
+ .read(/** @type {string} */ (extension))
569
605
  .then((buffer) => buffer.toString('base64'))
570
606
  })
571
607
  }
@@ -618,7 +654,7 @@ class Driver extends webdriver.WebDriver {
618
654
  * implementation.
619
655
  * @override
620
656
  */
621
- setFileDetector() { }
657
+ setFileDetector() {}
622
658
 
623
659
  /**
624
660
  * Schedules a command to launch Chrome App with given ID.
@@ -0,0 +1,89 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ class HttpResponse {
19
+ /**
20
+ * Creates a HTTP Response that will be used to
21
+ * mock out network interceptions.
22
+ * @param {*} urlToIntercept
23
+ */
24
+ constructor(urlToIntercept = "") {
25
+ this.returnBody = ""
26
+ this.returnHeaders = []
27
+ this.returnMethod = "GET"
28
+ this.returnStatus = 200
29
+ this.urlToIntercept = urlToIntercept
30
+ }
31
+
32
+ /**
33
+ * Add headers that will be returned when we intercept
34
+ * a HTTP Request
35
+ * @param {*} header
36
+ * @param {*} value
37
+ */
38
+ addHeaders(header, value) {
39
+ this.returnHeaders.push({ name: header, value: value })
40
+ }
41
+
42
+ get headers() {
43
+ return this.returnHeaders
44
+ }
45
+
46
+ /**
47
+ * Set the STATUS value of the returned HTTP Request
48
+ * @param {*} value
49
+ */
50
+ set status(value) {
51
+ // Add in check that his should be a number
52
+ this.returnStatus = value
53
+ }
54
+
55
+ get status() {
56
+ return this.returnStatus
57
+ }
58
+
59
+ /**
60
+ * Sets the value of the body of the HTTP Request that
61
+ * will be returned.
62
+ * @param {*} value
63
+ */
64
+ set body(value) {
65
+ this.returnBody = value
66
+ }
67
+
68
+ get body() {
69
+ let buff = Buffer.from(this.returnBody, "utf-8")
70
+ return buff.toString("base64")
71
+ }
72
+
73
+ /**
74
+ * Sets the method of the HTTP Request
75
+ * @param {*} value the method of the request.
76
+ */
77
+ set method(value) {
78
+ this.returnMethod = value
79
+ }
80
+
81
+ /**
82
+ * Returns the Method to be used in the intercept
83
+ */
84
+ get method() {
85
+ return this.returnMethod
86
+ }
87
+
88
+ }
89
+ exports.HttpResponse = HttpResponse
package/edge.js CHANGED
@@ -80,8 +80,6 @@
80
80
  const { Browser } = require('./lib/capabilities')
81
81
  const io = require('./io')
82
82
  const chromium = require('./chromium')
83
- const http = require('./http')
84
- const webdriver = require('./lib/webdriver')
85
83
 
86
84
  /**
87
85
  * Name of the EdgeDriver executable.
@@ -111,10 +109,10 @@ class ServiceBuilder extends chromium.ServiceBuilder {
111
109
  let exe = opt_exe || locateSynchronously()
112
110
  if (!exe) {
113
111
  throw Error(
114
- `The WebDriver for Edge could not be found on the current PATH. Please download the `+
115
- `latest version of ${EDGEDRIVER_CHROMIUM_EXE} from `+
116
- `https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ `+
117
- `and ensure it can be found on your PATH.`
112
+ `The WebDriver for Edge could not be found on the current PATH. Please download the ` +
113
+ `latest version of ${EDGEDRIVER_CHROMIUM_EXE} from ` +
114
+ `https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ ` +
115
+ `and ensure it can be found on your PATH.`
118
116
  )
119
117
  }
120
118
  super(exe)
@@ -143,24 +141,20 @@ class Options extends chromium.Options {
143
141
  /**
144
142
  * Creates a new WebDriver client for Microsoft's Edge.
145
143
  */
146
- class Driver extends webdriver.WebDriver {
144
+ class Driver extends chromium.Driver {
147
145
  /**
148
146
  * Creates a new browser session for Microsoft's Edge browser.
149
147
  *
150
- * @param {(Capabilities|Options)=} options The configuration options.
151
- * @param {remote.DriverService=} opt_service The service to use; will create
148
+ * @param {(Capabilities|Options)=} opt_config The configuration options.
149
+ * @param {remote.DriverService=} opt_serviceExecutor The service to use; will create
152
150
  * a new Legacy or Chromium service based on {@linkplain Options} by default.
153
151
  * @return {!Driver} A new driver instance.
154
152
  */
155
- static createSession(options, opt_service) {
156
- options = options || new Options()
157
- let service = opt_service || getDefaultService()
158
- let client = service.start().then((url) => new http.HttpClient(url))
159
- let executor = new http.Executor(client)
160
-
161
- return /** @type {!Driver} */ (super.createSession(executor, options, () =>
162
- service.kill()
163
- ))
153
+ static createSession(opt_config, opt_serviceExecutor) {
154
+ let caps = opt_config || new Options()
155
+ return /** @type {!Driver} */ (
156
+ super.createSession(caps, opt_serviceExecutor)
157
+ )
164
158
  }
165
159
 
166
160
  /**
@@ -180,7 +174,7 @@ function setDefaultService(service) {
180
174
  if (defaultService && defaultService.isRunning()) {
181
175
  throw Error(
182
176
  'The previously configured EdgeDriver service is still running. ' +
183
- 'You must shut it down before you may adjust its configuration.'
177
+ 'You must shut it down before you may adjust its configuration.'
184
178
  )
185
179
  }
186
180
  defaultService = service
@@ -199,7 +193,6 @@ function getDefaultService() {
199
193
  return defaultService
200
194
  }
201
195
 
202
-
203
196
  /**
204
197
  * _Synchronously_ attempts to locate the chromedriver executable on the current
205
198
  * system.
@@ -213,6 +206,7 @@ function locateSynchronously() {
213
206
  Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
214
207
  Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions'
215
208
  Driver.prototype.VENDOR_CAPABILITY_PREFIX = 'ms'
209
+ Driver.getDefaultService = getDefaultService
216
210
 
217
211
  // PUBLIC API
218
212
 
package/firefox.js CHANGED
@@ -124,7 +124,6 @@ const io = require('./io')
124
124
  const remote = require('./remote')
125
125
  const webdriver = require('./lib/webdriver')
126
126
  const zip = require('./io/zip')
127
- const cdp = require('./devtools/CDPConnection')
128
127
  const { Browser, Capabilities } = require('./lib/capabilities')
129
128
  const { Zip } = require('./io/zip')
130
129
 
@@ -394,6 +393,31 @@ class Options extends Capabilities {
394
393
  }
395
394
  throw TypeError('binary must be a string path or Channel object')
396
395
  }
396
+
397
+ /**
398
+ * Enables Mobile start up features
399
+ *
400
+ * @param {string} androidPackage The package to use
401
+ * @return {!Options} A self reference
402
+ */
403
+ enableMobile(androidPackage = "org.mozilla.firefox", androidActivity = null, deviceSerial = null) {
404
+ this.firefoxOptions_().androidPackage = androidPackage
405
+
406
+ if (androidActivity) {
407
+ this.firefoxOptions_().androidActivity = androidActivity
408
+ }
409
+ if (deviceSerial) {
410
+ this.firefoxOptions_().deviceSerial = deviceSerial
411
+ }
412
+ return this
413
+ }
414
+
415
+ /**
416
+ * Enables moz:debuggerAddress for firefox cdp
417
+ */
418
+ enableDebugger() {
419
+ return this.set('moz:debuggerAddress', true)
420
+ }
397
421
  }
398
422
 
399
423
  /**
package/http/index.js CHANGED
@@ -77,8 +77,9 @@ class HttpClient {
77
77
  * Defaults to `http.globalAgent`.
78
78
  * @param {?string=} opt_proxy The proxy to use for the connection to the
79
79
  * server. Default is to use no proxy.
80
+ * @param {?Object.<string,Object>} client_options
80
81
  */
81
- constructor(serverUrl, opt_agent, opt_proxy) {
82
+ constructor(serverUrl, opt_agent, opt_proxy, client_options = {}) {
82
83
  /** @private {http.Agent} */
83
84
  this.agent_ = opt_agent || null
84
85
 
@@ -88,12 +89,33 @@ class HttpClient {
88
89
  */
89
90
  this.options_ = getRequestOptions(serverUrl)
90
91
 
92
+ /**
93
+ * client options, header overrides
94
+ */
95
+ this.client_options = client_options
96
+
97
+ /**
98
+ * sets keep-alive for the agent
99
+ * see https://stackoverflow.com/a/58332910
100
+ */
101
+ this.keepAlive = this.client_options['keep-alive']
102
+
91
103
  /**
92
104
  * @private {?RequestOptions}
93
105
  */
94
106
  this.proxyOptions_ = opt_proxy ? getRequestOptions(opt_proxy) : null
95
107
  }
96
108
 
109
+ get keepAlive() {
110
+ return this.agent_.keepAlive
111
+ }
112
+
113
+ set keepAlive(value) {
114
+ if (value === 'true' || value === true) {
115
+ this.agent_.keepAlive = true
116
+ }
117
+ }
118
+
97
119
  /** @override */
98
120
  send(httpRequest) {
99
121
  let data
@@ -106,7 +128,7 @@ class HttpClient {
106
128
  })
107
129
  }
108
130
 
109
- headers['User-Agent'] = USER_AGENT
131
+ headers['User-Agent'] = this.client_options['user-agent'] || USER_AGENT
110
132
  headers['Content-Length'] = 0
111
133
  if (httpRequest.method == 'POST' || httpRequest.method == 'PUT') {
112
134
  data = JSON.stringify(httpRequest.data)
@@ -232,7 +254,7 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy, opt_retries) {
232
254
  hash: location.hash,
233
255
  headers: {
234
256
  Accept: 'application/json; charset=utf-8',
235
- 'User-Agent': USER_AGENT,
257
+ 'User-Agent': options.headers['User-Agent'] || USER_AGENT,
236
258
  },
237
259
  },
238
260
  onOk,
package/ie.js CHANGED
@@ -18,7 +18,7 @@
18
18
  /**
19
19
  * @fileoverview Defines a {@linkplain Driver WebDriver} client for Microsoft's
20
20
  * Internet Explorer. Before using the IEDriver, you must download the latest
21
- * [IEDriverServer](http://selenium-release.storage.googleapis.com/index.html)
21
+ * [IEDriverServer](https://www.selenium.dev/downloads/)
22
22
  * and place it on your
23
23
  * [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29). You must also apply
24
24
  * the system configuration outlined on the Selenium project
@@ -370,7 +370,7 @@ class Options extends Capabilities {
370
370
  behavior !== SCROLL_BEHAVIOUR.TOP &&
371
371
  behavior !== SCROLL_BEHAVIOUR.BOTTOM
372
372
  ) {
373
- throw new error.InvalidArgumentError(`Element Scroll Behavior out of range.
373
+ throw new error.InvalidArgumentError(`Element Scroll Behavior out of range.
374
374
  It should be either ${SCROLL_BEHAVIOUR.TOP} or ${SCROLL_BEHAVIOUR.BOTTOM}`)
375
375
  }
376
376
  this.options_[Key.ELEMENT_SCROLL_BEHAVIOR] = behavior
@@ -402,9 +402,9 @@ function createServiceFromCapabilities(capabilities) {
402
402
  if (!exe || !fs.existsSync(exe)) {
403
403
  throw Error(
404
404
  `${IEDRIVER_EXE} could not be found on the current PATH. Please ` +
405
- `download the latest version of ${IEDRIVER_EXE} from ` +
406
- 'http://selenium-release.storage.googleapis.com/index.html and ' +
407
- 'ensure it can be found on your system PATH.'
405
+ `download the latest version of ${IEDRIVER_EXE} from ` +
406
+ 'https://www.selenium.dev/downloads/ and ' +
407
+ 'ensure it can be found on your system PATH.'
408
408
  )
409
409
  }
410
410
 
@@ -478,9 +478,9 @@ class Driver extends webdriver.WebDriver {
478
478
  let client = service.start().then((url) => new http.HttpClient(url))
479
479
  let executor = new http.Executor(client)
480
480
 
481
- return /** @type {!Driver} */ (super.createSession(executor, options, () =>
482
- service.kill()
483
- ))
481
+ return /** @type {!Driver} */ (
482
+ super.createSession(executor, options, () => service.kill())
483
+ )
484
484
  }
485
485
 
486
486
  /**
package/index.js CHANGED
@@ -103,7 +103,7 @@ function ensureFileDetectorsAreEnabled(ctor) {
103
103
  */
104
104
  class ThenableWebDriver {
105
105
  /** @param {...?} args */
106
- static createSession(...args) {} // eslint-disable-line
106
+ static createSession(...args) { } // eslint-disable-line
107
107
  }
108
108
 
109
109
  /**
@@ -162,7 +162,7 @@ function createDriver(ctor, ...args) {
162
162
  * option always takes precedence over {@code SELENIUM_SERVER_JAR}.
163
163
  *
164
164
  * - {@code SELENIUM_SERVER_JAR}: defines the path to the
165
- * <a href="http://selenium-release.storage.googleapis.com/index.html">
165
+ * <a href="https://www.selenium.dev/downloads/">
166
166
  * standalone Selenium server</a> jar to use. The server will be started the
167
167
  * first time a WebDriver instance and be killed when the process exits.
168
168
  *
@@ -318,6 +318,8 @@ class Builder {
318
318
  }
319
319
 
320
320
  /**
321
+ * Recommended way is to use set*Options where * is the browser(eg setChromeOptions)
322
+ *
321
323
  * Sets the desired capabilities when requesting a new session. This will
322
324
  * overwrite any previously set capabilities.
323
325
  * @param {!(Object|Capabilities)} capabilities The desired capabilities for
@@ -337,6 +339,19 @@ class Builder {
337
339
  getCapabilities() {
338
340
  return this.capabilities_
339
341
  }
342
+
343
+ /**
344
+ * Sets the desired capability when requesting a new session.
345
+ * If there is already a capability named key, its value will be overwritten with value.
346
+ * This is a convenience wrapper around builder.getCapabilities().set(key, value) to support Builder method chaining.
347
+ * @param {string} key The capability key.
348
+ * @param {*} value The capability value.
349
+ * @return {!Builder} A self reference.
350
+ */
351
+ setCapability(key, value) {
352
+ this.capabilities_.set(key, value)
353
+ return this
354
+ }
340
355
 
341
356
  /**
342
357
  * Configures the target browser for clients created by this instance.
@@ -615,7 +630,7 @@ class Builder {
615
630
  if (typeof browser !== 'string') {
616
631
  throw TypeError(
617
632
  `Target browser must be a string, but is <${typeof browser}>;` +
618
- ' did you forget to call forBrowser()?'
633
+ ' did you forget to call forBrowser()?'
619
634
  )
620
635
  }
621
636
 
@@ -736,8 +751,8 @@ class Builder {
736
751
  default:
737
752
  throw new Error(
738
753
  'Do not know how to build driver: ' +
739
- browser +
740
- '; did you forget to call usingServer(url)?'
754
+ browser +
755
+ '; did you forget to call usingServer(url)?'
741
756
  )
742
757
  }
743
758
  }
@@ -793,9 +808,9 @@ function checkOptions(caps, key, optionType, setMethod) {
793
808
  if (val instanceof optionType) {
794
809
  throw new error.InvalidArgumentError(
795
810
  'Options class extends Capabilities and should not be set as key ' +
796
- `"${key}"; set browser-specific options with ` +
797
- `Builder.${setMethod}(). For more information, see the ` +
798
- 'documentation attached to the function that threw this error'
811
+ `"${key}"; set browser-specific options with ` +
812
+ `Builder.${setMethod}(). For more information, see the ` +
813
+ 'documentation attached to the function that threw this error'
799
814
  )
800
815
  }
801
816
  }
@@ -807,6 +822,7 @@ exports.Builder = Builder
807
822
  exports.Button = input.Button
808
823
  exports.By = by.By
809
824
  exports.withTagName = by.withTagName
825
+ exports.withLocator = by.withLocator
810
826
  exports.Capabilities = capabilities.Capabilities
811
827
  exports.Capability = capabilities.Capability
812
828
  exports.Condition = webdriver.Condition
package/io/exec.js CHANGED
@@ -76,7 +76,8 @@ class Result {
76
76
  }
77
77
  }
78
78
 
79
- const COMMAND_RESULT = /** !WeakMap<!Command, !Promise<!Result>> */ new WeakMap()
79
+ const COMMAND_RESULT =
80
+ /** !WeakMap<!Command, !Promise<!Result>> */ new WeakMap()
80
81
  const KILL_HOOK = /** !WeakMap<!Command, function(string)> */ new WeakMap()
81
82
 
82
83
  /**