selenium-webdriver 3.6.0 → 4.0.0-alpha.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/CHANGES.md +181 -0
- package/README.md +25 -27
- package/chrome.js +113 -127
- package/edge.js +42 -117
- package/example/chrome_android.js +8 -8
- package/example/chrome_mobile_emulation.js +8 -8
- package/example/firefox_channels.js +22 -18
- package/example/google_search_test.js +39 -26
- package/example/logging.js +39 -6
- package/firefox.js +769 -0
- package/http/index.js +41 -4
- package/http/util.js +11 -6
- package/ie.js +56 -97
- package/index.js +178 -114
- package/jasmine.json +11 -0
- package/lib/actions.js +68 -63
- package/lib/by.js +1 -1
- package/lib/capabilities.js +255 -192
- package/lib/command.js +26 -50
- package/lib/error.js +85 -44
- package/lib/http.js +133 -110
- package/lib/input.js +1044 -8
- package/lib/promise.js +222 -3323
- package/lib/proxy.js +134 -39
- package/lib/test/bootstrap_jasmine.js +28 -0
- package/lib/test/data/actions/click.html +24 -0
- package/lib/test/data/actions/drag.html +77 -0
- package/lib/test/data/actions/record_click.html +21 -0
- package/lib/test/data/chrome/download.html +2 -0
- package/lib/test/data/inputs.html +42 -0
- package/lib/test/data/selectPage.html +12 -0
- package/lib/test/data/simpleTest.html +5 -0
- package/lib/test/data/upload_invisible.html +45 -0
- package/lib/test/fileserver.js +23 -19
- package/lib/test/index.js +30 -212
- package/lib/test/resources.js +0 -1
- package/lib/webdriver.js +675 -936
- package/net/index.js +21 -25
- package/net/portprober.js +51 -68
- package/package.json +5 -3
- package/remote/index.js +5 -19
- package/safari.js +41 -128
- package/test/actions_test.js +173 -18
- package/test/{session_test.js → builder_test.js} +44 -37
- package/test/chrome/devtools_test.js +93 -0
- package/test/chrome/options_test.js +48 -154
- package/test/chrome/service_test.js +7 -7
- package/test/cookie_test.js +77 -63
- package/test/element_finding_test.js +206 -201
- package/test/execute_script_test.js +115 -114
- package/test/fingerprint_test.js +16 -15
- package/test/firefox_test.js +251 -0
- package/test/http/http_test.js +0 -1
- package/test/http/util_test.js +2 -2
- package/test/io/zip_test.js +6 -7
- package/test/lib/error_test.js +34 -7
- package/test/lib/http_test.js +8 -128
- package/test/lib/input_test.js +1379 -0
- package/test/lib/promise_test.js +473 -908
- package/test/lib/webdriver_test.js +296 -868
- package/test/logging_test.js +37 -43
- package/test/page_loading_test.js +71 -81
- package/test/proxy_test.js +64 -72
- package/test/rect_test.js +14 -25
- package/test/remote_test.js +10 -29
- package/test/safari_test.js +7 -71
- package/test/stale_element_test.js +20 -23
- package/test/tag_name_test.js +10 -9
- package/test/upload_test.js +27 -35
- package/test/window_test.js +72 -85
- package/testing/index.js +386 -314
- package/.npmignore +0 -2
- package/example/async_await_test.js +0 -69
- package/example/google_search_generator.js +0 -47
- package/example/parallel_flows.js +0 -51
- package/firefox/binary.js +0 -347
- package/firefox/extension.js +0 -224
- package/firefox/index.js +0 -576
- package/firefox/profile.js +0 -311
- package/lib/events.js +0 -210
- package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
- package/lib/test/data/firefox/sample.xpi +0 -0
- package/lib/test/promise.js +0 -79
- package/opera.js +0 -405
- package/phantomjs.js +0 -282
- package/test/firefox/extension_test.js +0 -120
- package/test/firefox/firefox_test.js +0 -244
- package/test/firefox/profile_test.js +0 -140
- package/test/lib/events_test.js +0 -177
- package/test/lib/promise_aplus_test.js +0 -78
- package/test/lib/promise_error_test.js +0 -884
- package/test/lib/promise_flow_test.js +0 -2288
- package/test/lib/promise_generator_test.js +0 -310
- package/test/phantomjs/execute_phantomjs_test.js +0 -59
- package/test/testing/assert_test.js +0 -373
- package/test/testing/index_test.js +0 -224
- package/testing/assert.js +0 -378
package/opera.js
DELETED
|
@@ -1,405 +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 selenium-webdriver/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.
|
|
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 selenium-webdriver.Builder}.
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
'use strict';
|
|
74
|
-
|
|
75
|
-
const fs = require('fs');
|
|
76
|
-
|
|
77
|
-
const http = require('./http'),
|
|
78
|
-
io = require('./io'),
|
|
79
|
-
capabilities = require('./lib/capabilities'),
|
|
80
|
-
promise = require('./lib/promise'),
|
|
81
|
-
Symbols = require('./lib/symbols'),
|
|
82
|
-
webdriver = require('./lib/webdriver'),
|
|
83
|
-
portprober = require('./net/portprober'),
|
|
84
|
-
remote = require('./remote');
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Name of the OperaDriver executable.
|
|
89
|
-
* @type {string}
|
|
90
|
-
* @const
|
|
91
|
-
*/
|
|
92
|
-
const OPERADRIVER_EXE =
|
|
93
|
-
process.platform === 'win32' ? 'operadriver.exe' : 'operadriver';
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Creates {@link remote.DriverService} instances that manages an
|
|
98
|
-
* [OperaDriver](https://github.com/operasoftware/operachromiumdriver)
|
|
99
|
-
* server in a child process.
|
|
100
|
-
*/
|
|
101
|
-
class ServiceBuilder extends remote.DriverService.Builder {
|
|
102
|
-
/**
|
|
103
|
-
* @param {string=} opt_exe Path to the server executable to use. If omitted,
|
|
104
|
-
* the builder will attempt to locate the operadriver on the current
|
|
105
|
-
* PATH.
|
|
106
|
-
* @throws {Error} If provided executable does not exist, or the operadriver
|
|
107
|
-
* cannot be found on the PATH.
|
|
108
|
-
*/
|
|
109
|
-
constructor(opt_exe) {
|
|
110
|
-
let exe = opt_exe || io.findInPath(OPERADRIVER_EXE, true);
|
|
111
|
-
if (!exe) {
|
|
112
|
-
throw Error(
|
|
113
|
-
'The OperaDriver could not be found on the current PATH. Please ' +
|
|
114
|
-
'download the latest version of the OperaDriver from ' +
|
|
115
|
-
'https://github.com/operasoftware/operachromiumdriver/releases and ' +
|
|
116
|
-
'ensure it can be found on your PATH.');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
super(exe);
|
|
120
|
-
this.setLoopback(true);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sets the path of the log file the driver should log to. If a log file is
|
|
125
|
-
* not specified, the driver will log to stderr.
|
|
126
|
-
* @param {string} path Path of the log file to use.
|
|
127
|
-
* @return {!ServiceBuilder} A self reference.
|
|
128
|
-
*/
|
|
129
|
-
loggingTo(path) {
|
|
130
|
-
return this.addArguments('--log-path=' + path);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Enables verbose logging.
|
|
135
|
-
* @return {!ServiceBuilder} A self reference.
|
|
136
|
-
*/
|
|
137
|
-
enableVerboseLogging() {
|
|
138
|
-
return this.addArguments('--verbose');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Silence sthe drivers output.
|
|
143
|
-
* @return {!ServiceBuilder} A self reference.
|
|
144
|
-
*/
|
|
145
|
-
silent() {
|
|
146
|
-
return this.addArguments('--silent');
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/** @type {remote.DriverService} */
|
|
153
|
-
var defaultService = null;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Sets the default service to use for new OperaDriver instances.
|
|
158
|
-
* @param {!remote.DriverService} service The service to use.
|
|
159
|
-
* @throws {Error} If the default service is currently running.
|
|
160
|
-
*/
|
|
161
|
-
function setDefaultService(service) {
|
|
162
|
-
if (defaultService && defaultService.isRunning()) {
|
|
163
|
-
throw Error(
|
|
164
|
-
'The previously configured OperaDriver service is still running. ' +
|
|
165
|
-
'You must shut it down before you may adjust its configuration.');
|
|
166
|
-
}
|
|
167
|
-
defaultService = service;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Returns the default OperaDriver service. If such a service has not been
|
|
173
|
-
* configured, one will be constructed using the default configuration for
|
|
174
|
-
* a OperaDriver executable found on the system PATH.
|
|
175
|
-
* @return {!remote.DriverService} The default OperaDriver service.
|
|
176
|
-
*/
|
|
177
|
-
function getDefaultService() {
|
|
178
|
-
if (!defaultService) {
|
|
179
|
-
defaultService = new ServiceBuilder().build();
|
|
180
|
-
}
|
|
181
|
-
return defaultService;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* @type {string}
|
|
187
|
-
* @const
|
|
188
|
-
*/
|
|
189
|
-
var OPTIONS_CAPABILITY_KEY = 'chromeOptions';
|
|
190
|
-
|
|
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(
|
|
239
|
-
caps.get(capabilities.Capability.LOGGING_PREFS));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return options;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Add additional command line arguments to use when launching the Opera
|
|
247
|
-
* browser. Each argument may be specified with or without the "--" prefix
|
|
248
|
-
* (e.g. "--foo" and "foo"). Arguments with an associated value should be
|
|
249
|
-
* delimited by an "=": "foo=bar".
|
|
250
|
-
* @param {...(string|!Array.<string>)} var_args The arguments to add.
|
|
251
|
-
* @return {!Options} A self reference.
|
|
252
|
-
*/
|
|
253
|
-
addArguments(var_args) {
|
|
254
|
-
this.args_ = this.args_.concat.apply(this.args_, arguments);
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Add additional extensions to install when launching Opera. Each extension
|
|
260
|
-
* should be specified as the path to the packed CRX file, or a Buffer for an
|
|
261
|
-
* extension.
|
|
262
|
-
* @param {...(string|!Buffer|!Array.<(string|!Buffer)>)} var_args The
|
|
263
|
-
* extensions to add.
|
|
264
|
-
* @return {!Options} A self reference.
|
|
265
|
-
*/
|
|
266
|
-
addExtensions(var_args) {
|
|
267
|
-
this.extensions_ = this.extensions_.concat.apply(
|
|
268
|
-
this.extensions_, arguments);
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Sets the path to the Opera binary to use. On Mac OS X, this path should
|
|
274
|
-
* reference the actual Opera executable, not just the application binary. The
|
|
275
|
-
* binary path be absolute or relative to the operadriver server executable, but
|
|
276
|
-
* it must exist on the machine that will launch Opera.
|
|
277
|
-
*
|
|
278
|
-
* @param {string} path The path to the Opera binary to use.
|
|
279
|
-
* @return {!Options} A self reference.
|
|
280
|
-
*/
|
|
281
|
-
setOperaBinaryPath(path) {
|
|
282
|
-
this.binary_ = path;
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Sets the logging preferences for the new session.
|
|
288
|
-
* @param {!./lib/logging.Preferences} prefs The logging preferences.
|
|
289
|
-
* @return {!Options} A self reference.
|
|
290
|
-
*/
|
|
291
|
-
setLoggingPrefs(prefs) {
|
|
292
|
-
this.logPrefs_ = prefs;
|
|
293
|
-
return this;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Sets the proxy settings for the new session.
|
|
298
|
-
* @param {capabilities.ProxyConfig} proxy The proxy configuration to use.
|
|
299
|
-
* @return {!Options} A self reference.
|
|
300
|
-
*/
|
|
301
|
-
setProxy(proxy) {
|
|
302
|
-
this.proxy_ = proxy;
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Converts this options instance to a {@link capabilities.Capabilities}
|
|
308
|
-
* object.
|
|
309
|
-
* @param {capabilities.Capabilities=} opt_capabilities The capabilities to
|
|
310
|
-
* merge these options into, if any.
|
|
311
|
-
* @return {!capabilities.Capabilities} The capabilities.
|
|
312
|
-
*/
|
|
313
|
-
toCapabilities(opt_capabilities) {
|
|
314
|
-
var caps = opt_capabilities || capabilities.Capabilities.opera();
|
|
315
|
-
caps.
|
|
316
|
-
set(capabilities.Capability.PROXY, this.proxy_).
|
|
317
|
-
set(capabilities.Capability.LOGGING_PREFS, this.logPrefs_).
|
|
318
|
-
set(OPTIONS_CAPABILITY_KEY, this);
|
|
319
|
-
return caps;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Converts this instance to its JSON wire protocol representation. Note this
|
|
324
|
-
* function is an implementation not intended for general use.
|
|
325
|
-
* @return {!Object} The JSON wire protocol representation of this instance.
|
|
326
|
-
*/
|
|
327
|
-
[Symbols.serialize]() {
|
|
328
|
-
var json = {
|
|
329
|
-
args: this.args_,
|
|
330
|
-
extensions: this.extensions_.map(function(extension) {
|
|
331
|
-
if (Buffer.isBuffer(extension)) {
|
|
332
|
-
return extension.toString('base64');
|
|
333
|
-
}
|
|
334
|
-
return io.read(/** @type {string} */(extension))
|
|
335
|
-
.then(buffer => buffer.toString('base64'));
|
|
336
|
-
})
|
|
337
|
-
};
|
|
338
|
-
if (this.binary_) {
|
|
339
|
-
json.binary = this.binary_;
|
|
340
|
-
}
|
|
341
|
-
return json;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Creates a new WebDriver client for Opera.
|
|
348
|
-
*/
|
|
349
|
-
class Driver extends webdriver.WebDriver {
|
|
350
|
-
/**
|
|
351
|
-
* Creates a new session for Opera.
|
|
352
|
-
*
|
|
353
|
-
* @param {(capabilities.Capabilities|Options)=} opt_config The configuration
|
|
354
|
-
* options.
|
|
355
|
-
* @param {remote.DriverService=} opt_service The session to use; will use
|
|
356
|
-
* the {@link getDefaultService default service} by default.
|
|
357
|
-
* @param {promise.ControlFlow=} opt_flow The control flow to use,
|
|
358
|
-
* or {@code null} to use the currently active flow.
|
|
359
|
-
* @return {!Driver} A new driver instance.
|
|
360
|
-
*/
|
|
361
|
-
static createSession(opt_config, opt_service, opt_flow) {
|
|
362
|
-
var service = opt_service || getDefaultService();
|
|
363
|
-
var client = service.start().then(url => new http.HttpClient(url));
|
|
364
|
-
var executor = new http.Executor(client);
|
|
365
|
-
|
|
366
|
-
var caps =
|
|
367
|
-
opt_config instanceof Options ? 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
|
-
options.setOperaBinaryPath(exe);
|
|
381
|
-
}
|
|
382
|
-
caps = options.toCapabilities(caps);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return /** @type {!Driver} */(
|
|
386
|
-
super.createSession(executor, caps, opt_flow));
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* This function is a no-op as file detectors are not supported by this
|
|
391
|
-
* implementation.
|
|
392
|
-
* @override
|
|
393
|
-
*/
|
|
394
|
-
setFileDetector() {}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
// PUBLIC API
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
exports.Driver = Driver;
|
|
402
|
-
exports.Options = Options;
|
|
403
|
-
exports.ServiceBuilder = ServiceBuilder;
|
|
404
|
-
exports.getDefaultService = getDefaultService;
|
|
405
|
-
exports.setDefaultService = setDefaultService;
|
package/phantomjs.js
DELETED
|
@@ -1,282 +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
|
-
* PhantomJS web browser. By default, it is expected that the PhantomJS
|
|
21
|
-
* executable can be located on your
|
|
22
|
-
* [PATH](https://en.wikipedia.org/wiki/PATH_(variable))
|
|
23
|
-
*
|
|
24
|
-
* __Using a Custom PhantomJS Binary__
|
|
25
|
-
*
|
|
26
|
-
* If you have PhantomJS.exe placed somewhere other than the root of your
|
|
27
|
-
* working directory, you can build a custom Capability and attach the
|
|
28
|
-
* executable's location to the Capability
|
|
29
|
-
*
|
|
30
|
-
* For example, if you're using the
|
|
31
|
-
* [phantomjs-prebuilt](https://www.npmjs.com/package/phantomjs-prebuilt) module
|
|
32
|
-
* from npm:
|
|
33
|
-
*
|
|
34
|
-
* //setup custom phantomJS capability
|
|
35
|
-
* var phantomjs_exe = require('phantomjs-prebuilt').path;
|
|
36
|
-
* var customPhantom = selenium.Capabilities.phantomjs();
|
|
37
|
-
* customPhantom.set("phantomjs.binary.path", phantomjs_exe);
|
|
38
|
-
* //build custom phantomJS driver
|
|
39
|
-
* var driver = new selenium.Builder().
|
|
40
|
-
* withCapabilities(customPhantom).
|
|
41
|
-
* build();
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
'use strict';
|
|
46
|
-
|
|
47
|
-
const fs = require('fs');
|
|
48
|
-
|
|
49
|
-
const http = require('./http'),
|
|
50
|
-
io = require('./io'),
|
|
51
|
-
capabilities = require('./lib/capabilities'),
|
|
52
|
-
command = require('./lib/command'),
|
|
53
|
-
logging = require('./lib/logging'),
|
|
54
|
-
promise = require('./lib/promise'),
|
|
55
|
-
webdriver = require('./lib/webdriver'),
|
|
56
|
-
portprober = require('./net/portprober'),
|
|
57
|
-
remote = require('./remote');
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Name of the PhantomJS executable.
|
|
62
|
-
* @type {string}
|
|
63
|
-
* @const
|
|
64
|
-
*/
|
|
65
|
-
const PHANTOMJS_EXE =
|
|
66
|
-
process.platform === 'win32' ? 'phantomjs.exe' : 'phantomjs';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Capability that designates the location of the PhantomJS executable to use.
|
|
71
|
-
* @type {string}
|
|
72
|
-
* @const
|
|
73
|
-
*/
|
|
74
|
-
const BINARY_PATH_CAPABILITY = 'phantomjs.binary.path';
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Capability that designates the CLI arguments to pass to PhantomJS.
|
|
79
|
-
* @type {string}
|
|
80
|
-
* @const
|
|
81
|
-
*/
|
|
82
|
-
const CLI_ARGS_CAPABILITY = 'phantomjs.cli.args';
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Custom command names supported by PhantomJS.
|
|
87
|
-
* @enum {string}
|
|
88
|
-
*/
|
|
89
|
-
const Command = {
|
|
90
|
-
EXECUTE_PHANTOM_SCRIPT: 'executePhantomScript'
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Finds the PhantomJS executable.
|
|
96
|
-
* @param {string=} opt_exe Path to the executable to use.
|
|
97
|
-
* @return {string} The located executable.
|
|
98
|
-
* @throws {Error} If the executable cannot be found on the PATH, or if the
|
|
99
|
-
* provided executable path does not exist.
|
|
100
|
-
*/
|
|
101
|
-
function findExecutable(opt_exe) {
|
|
102
|
-
var exe = opt_exe || io.findInPath(PHANTOMJS_EXE, true);
|
|
103
|
-
if (!exe) {
|
|
104
|
-
throw Error(
|
|
105
|
-
'The PhantomJS executable could not be found on the current PATH. ' +
|
|
106
|
-
'Please download the latest version from ' +
|
|
107
|
-
'http://phantomjs.org/download.html and ensure it can be found on ' +
|
|
108
|
-
'your PATH. For more information, see ' +
|
|
109
|
-
'https://github.com/ariya/phantomjs/wiki');
|
|
110
|
-
}
|
|
111
|
-
if (!fs.existsSync(exe)) {
|
|
112
|
-
throw Error('File does not exist: ' + exe);
|
|
113
|
-
}
|
|
114
|
-
return exe;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Maps WebDriver logging level name to those recognised by PhantomJS.
|
|
120
|
-
* @const {!Map<string, string>}
|
|
121
|
-
*/
|
|
122
|
-
const WEBDRIVER_TO_PHANTOMJS_LEVEL = new Map([
|
|
123
|
-
[logging.Level.ALL.name, 'DEBUG'],
|
|
124
|
-
[logging.Level.DEBUG.name, 'DEBUG'],
|
|
125
|
-
[logging.Level.INFO.name, 'INFO'],
|
|
126
|
-
[logging.Level.WARNING.name, 'WARN'],
|
|
127
|
-
[logging.Level.SEVERE.name, 'ERROR']]);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Creates a command executor with support for PhantomJS' custom commands.
|
|
132
|
-
* @param {!Promise<string>} url The server's URL.
|
|
133
|
-
* @return {!command.Executor} The new command executor.
|
|
134
|
-
*/
|
|
135
|
-
function createExecutor(url) {
|
|
136
|
-
let client = url.then(url => new http.HttpClient(url));
|
|
137
|
-
let executor = new http.Executor(client);
|
|
138
|
-
|
|
139
|
-
executor.defineCommand(
|
|
140
|
-
Command.EXECUTE_PHANTOM_SCRIPT,
|
|
141
|
-
'POST', '/session/:sessionId/phantom/execute');
|
|
142
|
-
|
|
143
|
-
return executor;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Creates a new WebDriver client for PhantomJS.
|
|
148
|
-
*/
|
|
149
|
-
class Driver extends webdriver.WebDriver {
|
|
150
|
-
/**
|
|
151
|
-
* Creates a new PhantomJS session.
|
|
152
|
-
*
|
|
153
|
-
* @param {capabilities.Capabilities=} opt_capabilities The desired
|
|
154
|
-
* capabilities.
|
|
155
|
-
* @param {promise.ControlFlow=} opt_flow The control flow to use,
|
|
156
|
-
* or {@code null} to use the currently active flow.
|
|
157
|
-
* @param {string=} opt_logFile Path to the log file for the phantomjs
|
|
158
|
-
* executable's output. For convenience, this may be set at runtime with
|
|
159
|
-
* the `SELENIUM_PHANTOMJS_LOG` environment variable.
|
|
160
|
-
* @return {!Driver} A new driver reference.
|
|
161
|
-
*/
|
|
162
|
-
static createSession(opt_capabilities, opt_flow, opt_logFile) {
|
|
163
|
-
// TODO: add an Options class for consistency with the other driver types.
|
|
164
|
-
|
|
165
|
-
var caps = opt_capabilities || capabilities.Capabilities.phantomjs();
|
|
166
|
-
var exe = findExecutable(caps.get(BINARY_PATH_CAPABILITY));
|
|
167
|
-
var args = [];
|
|
168
|
-
|
|
169
|
-
var logPrefs = caps.get(capabilities.Capability.LOGGING_PREFS);
|
|
170
|
-
if (logPrefs instanceof logging.Preferences) {
|
|
171
|
-
logPrefs = logPrefs.toJSON();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (logPrefs && logPrefs[logging.Type.DRIVER]) {
|
|
175
|
-
let level = WEBDRIVER_TO_PHANTOMJS_LEVEL.get(
|
|
176
|
-
logPrefs[logging.Type.DRIVER]);
|
|
177
|
-
if (level) {
|
|
178
|
-
args.push('--webdriver-loglevel=' + level);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
opt_logFile = process.env['SELENIUM_PHANTOMJS_LOG'] || opt_logFile;
|
|
183
|
-
if (typeof opt_logFile === 'string') {
|
|
184
|
-
args.push('--webdriver-logfile=' + opt_logFile);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
var proxy = caps.get(capabilities.Capability.PROXY);
|
|
188
|
-
if (proxy) {
|
|
189
|
-
switch (proxy.proxyType) {
|
|
190
|
-
case 'manual':
|
|
191
|
-
if (proxy.httpProxy) {
|
|
192
|
-
args.push(
|
|
193
|
-
'--proxy-type=http',
|
|
194
|
-
'--proxy=' + proxy.httpProxy);
|
|
195
|
-
console.log(args);
|
|
196
|
-
}
|
|
197
|
-
break;
|
|
198
|
-
case 'pac':
|
|
199
|
-
throw Error('PhantomJS does not support Proxy PAC files');
|
|
200
|
-
case 'system':
|
|
201
|
-
args.push('--proxy-type=system');
|
|
202
|
-
break;
|
|
203
|
-
case 'direct':
|
|
204
|
-
args.push('--proxy-type=none');
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
args = args.concat(caps.get(CLI_ARGS_CAPABILITY) || []);
|
|
209
|
-
|
|
210
|
-
var port = portprober.findFreePort();
|
|
211
|
-
var service = new remote.DriverService(exe, {
|
|
212
|
-
port: port,
|
|
213
|
-
args: Promise.resolve(port).then(function(port) {
|
|
214
|
-
args.push('--webdriver=' + port);
|
|
215
|
-
return args;
|
|
216
|
-
})
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
var executor = createExecutor(service.start());
|
|
220
|
-
return /** @type {!Driver} */(super.createSession(
|
|
221
|
-
executor, caps, opt_flow, () => service.kill()));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* This function is a no-op as file detectors are not supported by this
|
|
226
|
-
* implementation.
|
|
227
|
-
* @override
|
|
228
|
-
*/
|
|
229
|
-
setFileDetector() {}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Executes a PhantomJS fragment. This method is similar to
|
|
233
|
-
* {@link #executeScript}, except it exposes the
|
|
234
|
-
* <a href="http://phantomjs.org/api/">PhantomJS API</a> to the injected
|
|
235
|
-
* script.
|
|
236
|
-
*
|
|
237
|
-
* <p>The injected script will execute in the context of PhantomJS's
|
|
238
|
-
* {@code page} variable. If a page has not been loaded before calling this
|
|
239
|
-
* method, one will be created.</p>
|
|
240
|
-
*
|
|
241
|
-
* <p>Be sure to wrap callback definitions in a try/catch block, as failures
|
|
242
|
-
* may cause future WebDriver calls to fail.</p>
|
|
243
|
-
*
|
|
244
|
-
* <p>Certain callbacks are used by GhostDriver (the PhantomJS WebDriver
|
|
245
|
-
* implementation) and overriding these may cause the script to fail. It is
|
|
246
|
-
* recommended that you check for existing callbacks before defining your own.
|
|
247
|
-
* </p>
|
|
248
|
-
*
|
|
249
|
-
* As with {@link #executeScript}, the injected script may be defined as
|
|
250
|
-
* a string for an anonymous function body (e.g. "return 123;"), or as a
|
|
251
|
-
* function. If a function is provided, it will be decompiled to its original
|
|
252
|
-
* source. Note that injecting functions is provided as a convenience to
|
|
253
|
-
* simplify defining complex scripts. Care must be taken that the function
|
|
254
|
-
* only references variables that will be defined in the page's scope and
|
|
255
|
-
* that the function does not override {@code Function.prototype.toString}
|
|
256
|
-
* (overriding toString() will interfere with how the function is
|
|
257
|
-
* decompiled.
|
|
258
|
-
*
|
|
259
|
-
* @param {(string|!Function)} script The script to execute.
|
|
260
|
-
* @param {...*} var_args The arguments to pass to the script.
|
|
261
|
-
* @return {!promise.Thenable<T>} A promise that resolve to the
|
|
262
|
-
* script's return value.
|
|
263
|
-
* @template T
|
|
264
|
-
*/
|
|
265
|
-
executePhantomJS(script, var_args) {
|
|
266
|
-
if (typeof script === 'function') {
|
|
267
|
-
script = 'return (' + script + ').apply(this, arguments);';
|
|
268
|
-
}
|
|
269
|
-
var args = arguments.length > 1
|
|
270
|
-
? Array.prototype.slice.call(arguments, 1) : [];
|
|
271
|
-
return this.schedule(
|
|
272
|
-
new command.Command(Command.EXECUTE_PHANTOM_SCRIPT)
|
|
273
|
-
.setParameter('script', script)
|
|
274
|
-
.setParameter('args', args),
|
|
275
|
-
'Driver.executePhantomJS()');
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// PUBLIC API
|
|
281
|
-
|
|
282
|
-
exports.Driver = Driver;
|