selenium-webdriver 4.1.2 → 4.3.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.
package/opera.js DELETED
@@ -1,403 +0,0 @@
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
- const io = require('./io')
77
- const capabilities = require('./lib/capabilities')
78
- const Symbols = require('./lib/symbols')
79
- const webdriver = require('./lib/webdriver')
80
- const 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
- let 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
- const 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
- let options
221
- const 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) {
253
- this.args_ = this.args_.concat.apply(this.args_, var_args)
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) {
266
- this.extensions_ = this.extensions_.concat.apply(this.extensions_, var_args)
267
- return this
268
- }
269
-
270
- /**
271
- * Sets the path to the Opera binary to use. On Mac OS X, this path should
272
- * reference the actual Opera executable, not just the application binary. The
273
- * binary path be absolute or relative to the operadriver server executable, but
274
- * it must exist on the machine that will launch Opera.
275
- *
276
- * @param {string} path The path to the Opera binary to use.
277
- * @return {!Options} A self reference.
278
- */
279
- setOperaBinaryPath(path) {
280
- this.binary_ = path
281
- return this
282
- }
283
-
284
- /**
285
- * Sets the logging preferences for the new session.
286
- * @param {!./lib/logging.Preferences} prefs The logging preferences.
287
- * @return {!Options} A self reference.
288
- */
289
- setLoggingPrefs(prefs) {
290
- this.logPrefs_ = prefs
291
- return this
292
- }
293
-
294
- /**
295
- * Sets the proxy settings for the new session.
296
- * @param {capabilities.ProxyConfig} proxy The proxy configuration to use.
297
- * @return {!Options} A self reference.
298
- */
299
- setProxy(proxy) {
300
- this.proxy_ = proxy
301
- return this
302
- }
303
-
304
- /**
305
- * Converts this options instance to a {@link capabilities.Capabilities}
306
- * object.
307
- * @param {capabilities.Capabilities=} opt_capabilities The capabilities to
308
- * merge these options into, if any.
309
- * @return {!capabilities.Capabilities} The capabilities.
310
- */
311
- toCapabilities(opt_capabilities) {
312
- var caps = opt_capabilities || capabilities.Capabilities.opera()
313
- caps
314
- .set(capabilities.Capability.PROXY, this.proxy_)
315
- .set(capabilities.Capability.LOGGING_PREFS, this.logPrefs_)
316
- .set(OPTIONS_CAPABILITY_KEY, this)
317
- return caps
318
- }
319
-
320
- /**
321
- * Converts this instance to its JSON wire protocol representation. Note this
322
- * function is an implementation not intended for general use.
323
- * @return {!Object} The JSON wire protocol representation of this instance.
324
- */
325
- [Symbols.serialize]() {
326
- var json = {
327
- args: this.args_,
328
- extensions: this.extensions_.map(function (extension) {
329
- if (Buffer.isBuffer(extension)) {
330
- return extension.toString('base64')
331
- }
332
- return io
333
- .read(/** @type {string} */ (extension))
334
- .then((buffer) => buffer.toString('base64'))
335
- }),
336
- }
337
- if (this.binary_) {
338
- json.binary = this.binary_
339
- }
340
- return json
341
- }
342
- }
343
-
344
- /**
345
- * Creates a new WebDriver client for Opera.
346
- */
347
- class Driver extends webdriver.WebDriver {
348
- /**
349
- * Creates a new session for Opera.
350
- *
351
- * @param {(Capabilities|Options)=} opt_config The configuration
352
- * options.
353
- * @param {remote.DriverService=} opt_service The session to use; will use
354
- * the {@link getDefaultService default service} by default.
355
- * @return {!Driver} A new driver instance.
356
- */
357
- static createSession(opt_config, opt_service) {
358
- const service = opt_service || getDefaultService()
359
- const client = service.start().then((url) => new http.HttpClient(url))
360
- const executor = new http.Executor(client)
361
-
362
- let caps =
363
- opt_config instanceof Options
364
- ? opt_config.toCapabilities()
365
- : opt_config || capabilities.Capabilities.opera()
366
-
367
- // On Linux, the OperaDriver does not look for Opera on the PATH, so we
368
- // must explicitly find it. See: operachromiumdriver #9.
369
- if (process.platform === 'linux') {
370
- const options = Options.fromCapabilities(caps)
371
- if (!options.binary_) {
372
- let exe = io.findInPath('opera', true)
373
- if (!exe) {
374
- throw Error(
375
- 'The opera executable could not be found on the current PATH'
376
- )
377
- }
378
- options.setOperaBinaryPath(exe)
379
- }
380
- caps = options.toCapabilities(caps)
381
- }
382
-
383
- return /** @type {!Driver} */ (
384
- super.createSession(executor, caps, () => service.kill())
385
- )
386
- }
387
-
388
- /**
389
- * This function is a no-op as file detectors are not supported by this
390
- * implementation.
391
- * @override
392
- */
393
- setFileDetector() {}
394
- }
395
-
396
- // PUBLIC API
397
-
398
- exports.Driver = Driver
399
- exports.Options = Options
400
- exports.ServiceBuilder = ServiceBuilder
401
- exports.getDefaultService = getDefaultService
402
- exports.setDefaultService = setDefaultService
403
- exports.locateSynchronously = locateSynchronously