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
package/opera.js ADDED
@@ -0,0 +1,406 @@
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
+ /**
19
+ * @fileoverview Defines a {@linkplain Driver WebDriver} client for the
20
+ * Opera web browser (v26+). Before using this module, you must download the
21
+ * latest OperaDriver
22
+ * [release](https://github.com/operasoftware/operachromiumdriver/releases) and
23
+ * ensure it can be found on your system
24
+ * [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29).
25
+ *
26
+ * There are three primary classes exported by this module:
27
+ *
28
+ * 1. {@linkplain ServiceBuilder}: configures the
29
+ * {@link ./remote.DriverService remote.DriverService}
30
+ * that manages the
31
+ * [OperaDriver](https://github.com/operasoftware/operachromiumdriver)
32
+ * child process.
33
+ *
34
+ * 2. {@linkplain Options}: defines configuration options for each new Opera
35
+ * session, such as which {@linkplain Options#setProxy proxy} to use,
36
+ * what {@linkplain Options#addExtensions extensions} to install, or
37
+ * what {@linkplain Options#addArguments command-line switches} to use when
38
+ * starting the browser.Service
39
+ *
40
+ * 3. {@linkplain Driver}: the WebDriver client; each new instance will control
41
+ * a unique browser session with a clean user profile (unless otherwise
42
+ * configured through the {@link Options} class).
43
+ *
44
+ * By default, every Opera session will use a single driver service, which is
45
+ * started the first time a {@link Driver} instance is created and terminated
46
+ * when this process exits. The default service will inherit its environment
47
+ * from the current process and direct all output to /dev/null. You may obtain
48
+ * a handle to this default service using
49
+ * {@link #getDefaultService getDefaultService()} and change its configuration
50
+ * with {@link #setDefaultService setDefaultService()}.
51
+ *
52
+ * You may also create a {@link Driver} with its own driver service. This is
53
+ * useful if you need to capture the server's log output for a specific session:
54
+ *
55
+ * var opera = require('selenium-webdriver/opera');
56
+ *
57
+ * var service = new opera.ServiceBuilder()
58
+ * .loggingTo('/my/log/file.txt')
59
+ * .enableVerboseLogging()
60
+ * .build();
61
+ *
62
+ * var options = new opera.Options();
63
+ * // configure browser options ...
64
+ *
65
+ * var driver = opera.Driver.createSession(options, service);
66
+ *
67
+ * Users should only instantiate the {@link Driver} class directly when they
68
+ * need a custom driver service configuration (as shown above). For normal
69
+ * operation, users should start Opera using the
70
+ * {@link ./builder.Builder selenium-webdriver.Builder}.
71
+ */
72
+
73
+ 'use strict'
74
+
75
+ const http = require('./http'),
76
+ io = require('./io'),
77
+ capabilities = require('./lib/capabilities'),
78
+ Symbols = require('./lib/symbols'),
79
+ webdriver = require('./lib/webdriver'),
80
+ remote = require('./remote')
81
+
82
+ /**
83
+ * Name of the OperaDriver executable.
84
+ * @type {string}
85
+ * @const
86
+ */
87
+ const OPERADRIVER_EXE =
88
+ process.platform === 'win32' ? 'operadriver.exe' : 'operadriver'
89
+
90
+ /**
91
+ * _Synchronously_ attempts to locate the operadriver executable on the current
92
+ * system.
93
+ *
94
+ * @return {?string} the located executable, or `null`.
95
+ */
96
+ function locateSynchronously() {
97
+ return io.findInPath(OPERADRIVER_EXE, true)
98
+ }
99
+
100
+ /**
101
+ * Creates {@link remote.DriverService} instances that manages an
102
+ * [OperaDriver](https://github.com/operasoftware/operachromiumdriver)
103
+ * server in a child process.
104
+ */
105
+ class ServiceBuilder extends remote.DriverService.Builder {
106
+ /**
107
+ * @param {string=} opt_exe Path to the server executable to use. If omitted,
108
+ * the builder will attempt to locate the operadriver on the current
109
+ * PATH.
110
+ * @throws {Error} If provided executable does not exist, or the operadriver
111
+ * cannot be found on the PATH.
112
+ */
113
+ constructor(opt_exe) {
114
+ let exe = opt_exe || locateSynchronously()
115
+ if (!exe) {
116
+ throw Error(
117
+ 'The OperaDriver could not be found on the current PATH. Please ' +
118
+ 'download the latest version of the OperaDriver from ' +
119
+ 'https://github.com/operasoftware/operachromiumdriver/releases and ' +
120
+ 'ensure it can be found on your PATH.'
121
+ )
122
+ }
123
+
124
+ super(exe)
125
+ this.setLoopback(true)
126
+ }
127
+
128
+ /**
129
+ * Sets the path of the log file the driver should log to. If a log file is
130
+ * not specified, the driver will log to stderr.
131
+ * @param {string} path Path of the log file to use.
132
+ * @return {!ServiceBuilder} A self reference.
133
+ */
134
+ loggingTo(path) {
135
+ return this.addArguments('--log-path=' + path)
136
+ }
137
+
138
+ /**
139
+ * Enables verbose logging.
140
+ * @return {!ServiceBuilder} A self reference.
141
+ */
142
+ enableVerboseLogging() {
143
+ return this.addArguments('--verbose')
144
+ }
145
+
146
+ /**
147
+ * Silence sthe drivers output.
148
+ * @return {!ServiceBuilder} A self reference.
149
+ */
150
+ silent() {
151
+ return this.addArguments('--silent')
152
+ }
153
+ }
154
+
155
+ /** @type {remote.DriverService} */
156
+ var defaultService = null
157
+
158
+ /**
159
+ * Sets the default service to use for new OperaDriver instances.
160
+ * @param {!remote.DriverService} service The service to use.
161
+ * @throws {Error} If the default service is currently running.
162
+ */
163
+ function setDefaultService(service) {
164
+ if (defaultService && defaultService.isRunning()) {
165
+ throw Error(
166
+ 'The previously configured OperaDriver service is still running. ' +
167
+ 'You must shut it down before you may adjust its configuration.'
168
+ )
169
+ }
170
+ defaultService = service
171
+ }
172
+
173
+ /**
174
+ * Returns the default OperaDriver service. If such a service has not been
175
+ * configured, one will be constructed using the default configuration for
176
+ * a OperaDriver executable found on the system PATH.
177
+ * @return {!remote.DriverService} The default OperaDriver service.
178
+ */
179
+ function getDefaultService() {
180
+ if (!defaultService) {
181
+ defaultService = new ServiceBuilder().build()
182
+ }
183
+ return defaultService
184
+ }
185
+
186
+ /**
187
+ * @type {string}
188
+ * @const
189
+ */
190
+ var OPTIONS_CAPABILITY_KEY = 'chromeOptions'
191
+
192
+ /**
193
+ * Class for managing {@linkplain Driver OperaDriver} specific options.
194
+ */
195
+ class Options {
196
+ constructor() {
197
+ /** @private {!Array.<string>} */
198
+ this.args_ = []
199
+
200
+ /** @private {?string} */
201
+ this.binary_ = null
202
+
203
+ /** @private {!Array.<(string|!Buffer)>} */
204
+ this.extensions_ = []
205
+
206
+ /** @private {./lib/logging.Preferences} */
207
+ this.logPrefs_ = null
208
+
209
+ /** @private {?capabilities.ProxyConfig} */
210
+ this.proxy_ = null
211
+ }
212
+
213
+ /**
214
+ * Extracts the OperaDriver specific options from the given capabilities
215
+ * object.
216
+ * @param {!capabilities.Capabilities} caps The capabilities object.
217
+ * @return {!Options} The OperaDriver options.
218
+ */
219
+ static fromCapabilities(caps) {
220
+ var options
221
+ var o = caps.get(OPTIONS_CAPABILITY_KEY)
222
+ if (o instanceof Options) {
223
+ options = o
224
+ } else if (o) {
225
+ options = new Options()
226
+ .addArguments(o.args || [])
227
+ .addExtensions(o.extensions || [])
228
+ .setOperaBinaryPath(o.binary)
229
+ } else {
230
+ options = new Options()
231
+ }
232
+
233
+ if (caps.has(capabilities.Capability.PROXY)) {
234
+ options.setProxy(caps.get(capabilities.Capability.PROXY))
235
+ }
236
+
237
+ if (caps.has(capabilities.Capability.LOGGING_PREFS)) {
238
+ options.setLoggingPrefs(caps.get(capabilities.Capability.LOGGING_PREFS))
239
+ }
240
+
241
+ return options
242
+ }
243
+
244
+ /**
245
+ * Add additional command line arguments to use when launching the Opera
246
+ * browser. Each argument may be specified with or without the "--" prefix
247
+ * (e.g. "--foo" and "foo"). Arguments with an associated value should be
248
+ * delimited by an "=": "foo=bar".
249
+ * @param {...(string|!Array.<string>)} var_args The arguments to add.
250
+ * @return {!Options} A self reference.
251
+ */
252
+ addArguments(var_args) { // eslint-disable-line
253
+ this.args_ = this.args_.concat.apply(this.args_, arguments)
254
+ return this
255
+ }
256
+
257
+ /**
258
+ * Add additional extensions to install when launching Opera. Each extension
259
+ * should be specified as the path to the packed CRX file, or a Buffer for an
260
+ * extension.
261
+ * @param {...(string|!Buffer|!Array.<(string|!Buffer)>)} var_args The
262
+ * extensions to add.
263
+ * @return {!Options} A self reference.
264
+ */
265
+ addExtensions(var_args) { // eslint-disable-line
266
+ this.extensions_ = this.extensions_.concat.apply(
267
+ this.extensions_,
268
+ arguments
269
+ )
270
+ return this
271
+ }
272
+
273
+ /**
274
+ * Sets the path to the Opera binary to use. On Mac OS X, this path should
275
+ * reference the actual Opera executable, not just the application binary. The
276
+ * binary path be absolute or relative to the operadriver server executable, but
277
+ * it must exist on the machine that will launch Opera.
278
+ *
279
+ * @param {string} path The path to the Opera binary to use.
280
+ * @return {!Options} A self reference.
281
+ */
282
+ setOperaBinaryPath(path) {
283
+ this.binary_ = path
284
+ return this
285
+ }
286
+
287
+ /**
288
+ * Sets the logging preferences for the new session.
289
+ * @param {!./lib/logging.Preferences} prefs The logging preferences.
290
+ * @return {!Options} A self reference.
291
+ */
292
+ setLoggingPrefs(prefs) {
293
+ this.logPrefs_ = prefs
294
+ return this
295
+ }
296
+
297
+ /**
298
+ * Sets the proxy settings for the new session.
299
+ * @param {capabilities.ProxyConfig} proxy The proxy configuration to use.
300
+ * @return {!Options} A self reference.
301
+ */
302
+ setProxy(proxy) {
303
+ this.proxy_ = proxy
304
+ return this
305
+ }
306
+
307
+ /**
308
+ * Converts this options instance to a {@link capabilities.Capabilities}
309
+ * object.
310
+ * @param {capabilities.Capabilities=} opt_capabilities The capabilities to
311
+ * merge these options into, if any.
312
+ * @return {!capabilities.Capabilities} The capabilities.
313
+ */
314
+ toCapabilities(opt_capabilities) {
315
+ var caps = opt_capabilities || capabilities.Capabilities.opera()
316
+ caps
317
+ .set(capabilities.Capability.PROXY, this.proxy_)
318
+ .set(capabilities.Capability.LOGGING_PREFS, this.logPrefs_)
319
+ .set(OPTIONS_CAPABILITY_KEY, this)
320
+ return caps
321
+ }
322
+
323
+ /**
324
+ * Converts this instance to its JSON wire protocol representation. Note this
325
+ * function is an implementation not intended for general use.
326
+ * @return {!Object} The JSON wire protocol representation of this instance.
327
+ */
328
+ [Symbols.serialize]() {
329
+ var json = {
330
+ args: this.args_,
331
+ extensions: this.extensions_.map(function (extension) {
332
+ if (Buffer.isBuffer(extension)) {
333
+ return extension.toString('base64')
334
+ }
335
+ return io
336
+ .read(/** @type {string} */ (extension))
337
+ .then((buffer) => buffer.toString('base64'))
338
+ }),
339
+ }
340
+ if (this.binary_) {
341
+ json.binary = this.binary_
342
+ }
343
+ return json
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Creates a new WebDriver client for Opera.
349
+ */
350
+ class Driver extends webdriver.WebDriver {
351
+ /**
352
+ * Creates a new session for Opera.
353
+ *
354
+ * @param {(Capabilities|Options)=} opt_config The configuration
355
+ * options.
356
+ * @param {remote.DriverService=} opt_service The session to use; will use
357
+ * the {@link getDefaultService default service} by default.
358
+ * @return {!Driver} A new driver instance.
359
+ */
360
+ static createSession(opt_config, opt_service) {
361
+ var service = opt_service || getDefaultService()
362
+ var client = service.start().then((url) => new http.HttpClient(url))
363
+ var executor = new http.Executor(client)
364
+
365
+ var caps =
366
+ opt_config instanceof Options
367
+ ? opt_config.toCapabilities()
368
+ : opt_config || capabilities.Capabilities.opera()
369
+
370
+ // On Linux, the OperaDriver does not look for Opera on the PATH, so we
371
+ // must explicitly find it. See: operachromiumdriver #9.
372
+ if (process.platform === 'linux') {
373
+ var options = Options.fromCapabilities(caps)
374
+ if (!options.binary_) {
375
+ let exe = io.findInPath('opera', true)
376
+ if (!exe) {
377
+ throw Error(
378
+ 'The opera executable could not be found on the current PATH'
379
+ )
380
+ }
381
+ options.setOperaBinaryPath(exe)
382
+ }
383
+ caps = options.toCapabilities(caps)
384
+ }
385
+
386
+ return /** @type {!Driver} */ (super.createSession(executor, caps, () =>
387
+ service.kill()
388
+ ))
389
+ }
390
+
391
+ /**
392
+ * This function is a no-op as file detectors are not supported by this
393
+ * implementation.
394
+ * @override
395
+ */
396
+ setFileDetector() {}
397
+ }
398
+
399
+ // PUBLIC API
400
+
401
+ exports.Driver = Driver
402
+ exports.Options = Options
403
+ exports.ServiceBuilder = ServiceBuilder
404
+ exports.getDefaultService = getDefaultService
405
+ exports.setDefaultService = setDefaultService
406
+ exports.locateSynchronously = locateSynchronously
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "selenium-webdriver",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "The official WebDriver JavaScript bindings from the Selenium project",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -10,7 +10,7 @@
10
10
  "webdriver",
11
11
  "webdriverjs"
12
12
  ],
13
- "homepage": "https://github.com/SeleniumHQ/selenium",
13
+ "homepage": "https://github.com/SeleniumHQ/selenium/tree/trunk/javascript/node/selenium-webdriver#readme",
14
14
  "bugs": {
15
15
  "url": "https://github.com/SeleniumHQ/selenium/issues"
16
16
  },
@@ -23,21 +23,28 @@
23
23
  "node": ">= 10.15.0"
24
24
  },
25
25
  "dependencies": {
26
- "jszip": "^3.1.5",
27
- "rimraf": "^2.6.3",
28
- "tmp": "0.0.30",
29
- "xml2js": "^0.4.19"
26
+ "jszip": "^3.5.0",
27
+ "rimraf": "^2.7.1",
28
+ "tmp": "^0.2.1",
29
+ "ws": "^7.3.1"
30
30
  },
31
31
  "devDependencies": {
32
- "express": "^4.16.4",
33
- "jasmine": "^3.3.1",
34
- "mocha": "^5.2.0",
35
- "multer": "^1.4.1",
32
+ "eslint": "^7.15.0",
33
+ "eslint-config-prettier": "^7.0.0",
34
+ "eslint-plugin-no-only-tests": "^2.4.0",
35
+ "eslint-plugin-node": "^11.1.0",
36
+ "eslint-plugin-prettier": "^3.2.0",
37
+ "express": "^4.17.1",
38
+ "jasmine": "^3.6.1",
39
+ "mocha": "^8.1.0",
40
+ "multer": "^1.4.2",
41
+ "prettier": "^2.2.1",
36
42
  "serve-index": "^1.9.1",
37
- "sinon": "^7.2.3"
43
+ "sinon": "^7.5.0"
38
44
  },
39
45
  "scripts": {
40
- "test": "mocha -t 600000 --recursive test",
46
+ "lint": "eslint --ignore-pattern node_modules --ignore-pattern generator --ext js lib/http.js \"**/*.js\"",
47
+ "test": "npm run lint && mocha -t 600000 --recursive test",
41
48
  "test-jasmine": "jasmine JASMINE_CONFIG_PATH=jasmine.json"
42
49
  },
43
50
  "mocha": {
package/proxy.js CHANGED
@@ -27,6 +27,6 @@
27
27
  * .build();
28
28
  */
29
29
 
30
- 'use strict';
30
+ 'use strict'
31
31
 
32
- module.exports = require('./lib/proxy');
32
+ module.exports = require('./lib/proxy')