selenium-webdriver 3.3.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.
Files changed (117) hide show
  1. package/CHANGES.md +273 -0
  2. package/NOTICE +1 -1
  3. package/README.md +28 -36
  4. package/chrome.js +221 -146
  5. package/edge.js +43 -118
  6. package/example/chrome_android.js +8 -9
  7. package/example/chrome_mobile_emulation.js +9 -10
  8. package/example/firefox_channels.js +23 -19
  9. package/example/google_search.js +3 -3
  10. package/example/google_search_test.js +39 -27
  11. package/example/headless.js +55 -0
  12. package/example/logging.js +40 -7
  13. package/firefox.js +769 -0
  14. package/http/index.js +41 -4
  15. package/http/util.js +11 -6
  16. package/ie.js +57 -98
  17. package/index.js +182 -115
  18. package/io/index.js +59 -0
  19. package/io/zip.js +214 -0
  20. package/jasmine.json +11 -0
  21. package/lib/actions.js +68 -63
  22. package/lib/atoms/get-attribute.js +9 -0
  23. package/lib/atoms/is-displayed.js +73 -78
  24. package/lib/by.js +9 -1
  25. package/lib/capabilities.js +303 -201
  26. package/lib/command.js +28 -50
  27. package/lib/error.js +113 -42
  28. package/lib/http.js +167 -135
  29. package/lib/input.js +1044 -8
  30. package/lib/promise.js +222 -3331
  31. package/lib/proxy.js +134 -39
  32. package/lib/test/bootstrap_jasmine.js +28 -0
  33. package/lib/test/data/actions/click.html +24 -0
  34. package/lib/test/data/actions/drag.html +77 -0
  35. package/lib/test/data/actions/record_click.html +21 -0
  36. package/lib/test/data/chrome/download.html +2 -0
  37. package/lib/test/data/click_tests/disabled_element.html +12 -0
  38. package/lib/test/data/content-editable.html +10 -0
  39. package/lib/test/data/firefox/webextension.xpi +0 -0
  40. package/lib/test/data/inputs.html +42 -0
  41. package/lib/test/data/key_logger.html +34 -0
  42. package/lib/test/data/nestedElements.html +10 -1
  43. package/lib/test/data/scrolling_tests/page_with_partially_hidden_element.html +14 -0
  44. package/lib/test/data/selectPage.html +12 -0
  45. package/lib/test/data/simpleTest.html +5 -0
  46. package/lib/test/data/single_text_input.html +12 -0
  47. package/lib/test/data/upload_invisible.html +45 -0
  48. package/lib/test/fileserver.js +23 -19
  49. package/lib/test/index.js +30 -244
  50. package/lib/test/resources.js +0 -1
  51. package/lib/webdriver.js +770 -939
  52. package/net/index.js +21 -25
  53. package/net/portprober.js +51 -68
  54. package/package.json +6 -4
  55. package/remote/index.js +18 -30
  56. package/safari.js +42 -129
  57. package/test/actions_test.js +173 -18
  58. package/test/builder_test.js +106 -0
  59. package/test/chrome/devtools_test.js +93 -0
  60. package/test/chrome/options_test.js +48 -154
  61. package/test/chrome/service_test.js +7 -7
  62. package/test/cookie_test.js +77 -63
  63. package/test/element_finding_test.js +206 -201
  64. package/test/execute_script_test.js +115 -114
  65. package/test/fingerprint_test.js +16 -15
  66. package/test/firefox_test.js +251 -0
  67. package/test/http/http_test.js +18 -1
  68. package/test/http/util_test.js +2 -2
  69. package/test/{io_test.js → io/io_test.js} +40 -1
  70. package/test/io/zip_test.js +127 -0
  71. package/test/lib/by_test.js +21 -0
  72. package/test/lib/error_test.js +55 -8
  73. package/test/lib/http_test.js +18 -130
  74. package/test/lib/input_test.js +1379 -0
  75. package/test/lib/promise_test.js +473 -908
  76. package/test/lib/webdriver_test.js +357 -825
  77. package/test/logging_test.js +37 -43
  78. package/test/page_loading_test.js +70 -86
  79. package/test/proxy_test.js +64 -72
  80. package/test/rect_test.js +14 -25
  81. package/test/remote_test.js +13 -32
  82. package/test/safari_test.js +7 -71
  83. package/test/stale_element_test.js +20 -23
  84. package/test/tag_name_test.js +10 -9
  85. package/test/upload_test.js +27 -35
  86. package/test/window_test.js +72 -85
  87. package/testing/index.js +386 -315
  88. package/.npmignore +0 -2
  89. package/example/async_await_test.js +0 -68
  90. package/example/google_search_generator.js +0 -50
  91. package/example/parallel_flows.js +0 -54
  92. package/firefox/binary.js +0 -344
  93. package/firefox/extension.js +0 -187
  94. package/firefox/index.js +0 -722
  95. package/firefox/profile.js +0 -430
  96. package/lib/atoms/getAttribute.js +0 -12
  97. package/lib/events.js +0 -210
  98. package/lib/firefox/webdriver.json +0 -70
  99. package/lib/firefox/webdriver.xpi +0 -0
  100. package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
  101. package/lib/test/data/firefox/sample.xpi +0 -0
  102. package/lib/test/promise.js +0 -79
  103. package/opera.js +0 -405
  104. package/phantomjs.js +0 -282
  105. package/test/firefox/extension_test.js +0 -96
  106. package/test/firefox/firefox_test.js +0 -226
  107. package/test/firefox/profile_test.js +0 -185
  108. package/test/lib/events_test.js +0 -177
  109. package/test/lib/promise_aplus_test.js +0 -78
  110. package/test/lib/promise_error_test.js +0 -884
  111. package/test/lib/promise_flow_test.js +0 -2288
  112. package/test/lib/promise_generator_test.js +0 -310
  113. package/test/phantomjs/execute_phantomjs_test.js +0 -59
  114. package/test/session_test.js +0 -54
  115. package/test/testing/assert_test.js +0 -373
  116. package/test/testing/index_test.js +0 -224
  117. package/testing/assert.js +0 -378
package/firefox/index.js DELETED
@@ -1,722 +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 the {@linkplain Driver WebDriver} client for Firefox.
20
- * Before using this module, you must download the latest
21
- * [geckodriver release] and ensure it can be found on your system [PATH].
22
- *
23
- * Each FirefoxDriver instance will be created with an anonymous profile,
24
- * ensuring browser historys do not share session data (cookies, history, cache,
25
- * offline storage, etc.)
26
- *
27
- * __Customizing the Firefox Profile__
28
- *
29
- * The {@linkplain Profile} class may be used to configure the browser profile
30
- * used with WebDriver, with functions to install additional
31
- * {@linkplain Profile#addExtension extensions}, configure browser
32
- * {@linkplain Profile#setPreference preferences}, and more. For example, you
33
- * may wish to include Firebug:
34
- *
35
- * const {Builder} = require('selenium-webdriver');
36
- * const firefox = require('selenium-webdriver/firefox');
37
- *
38
- * let profile = new firefox.Profile();
39
- * profile.addExtension('/path/to/firebug.xpi');
40
- * profile.setPreference('extensions.firebug.showChromeErrors', true);
41
- *
42
- * let options = new firefox.Options().setProfile(profile);
43
- * let driver = new Builder()
44
- * .forBrowser('firefox')
45
- * .setFirefoxOptions(options)
46
- * .build();
47
- *
48
- * The {@linkplain Profile} class may also be used to configure WebDriver based
49
- * on a pre-existing browser profile:
50
- *
51
- * let profile = new firefox.Profile(
52
- * '/usr/local/home/bob/.mozilla/firefox/3fgog75h.testing');
53
- * let options = new firefox.Options().setProfile(profile);
54
- *
55
- * The FirefoxDriver will _never_ modify a pre-existing profile; instead it will
56
- * create a copy for it to modify. By extension, there are certain browser
57
- * preferences that are required for WebDriver to function properly and they
58
- * will always be overwritten.
59
- *
60
- * __Using a Custom Firefox Binary__
61
- *
62
- * On Windows and MacOS, the FirefoxDriver will search for Firefox in its
63
- * default installation location:
64
- *
65
- * - Windows: C:\Program Files and C:\Program Files (x86).
66
- * - MacOS: /Applications/Firefox.app
67
- *
68
- * For Linux, Firefox will always be located on the PATH: `$(where firefox)`.
69
- *
70
- * Several methods are provided for starting Firefox with a custom executable.
71
- * First, on Windows and MacOS, you may configure WebDriver to check the default
72
- * install location for a non-release channel. If the requested channel cannot
73
- * be found in its default location, WebDriver will fallback to searching your
74
- * PATH. _Note:_ on Linux, Firefox is _always_ located on your path, regardless
75
- * of the requested channel.
76
- *
77
- * const {Builder} = require('selenium-webdriver');
78
- * const firefox = require('selenium-webdriver/firefox');
79
- *
80
- * let options = new firefox.Options().setBinary(firefox.Channel.NIGHTLY);
81
- * let driver = new Builder()
82
- * .forBrowser('firefox')
83
- * .setFirefoxOptions(options)
84
- * .build();
85
- *
86
- * On all platforms, you may configrue WebDriver to use a Firefox specific
87
- * executable:
88
- *
89
- * let options = new firefox.Options()
90
- * .setBinary('/my/firefox/install/dir/firefox-bin');
91
- *
92
- * __Remote Testing__
93
- *
94
- * You may customize the Firefox binary and profile when running against a
95
- * remote Selenium server. Your custom profile will be packaged as a zip and
96
- * transfered to the remote host for use. The profile will be transferred
97
- * _once for each new session_. The performance impact should be minimal if
98
- * you've only configured a few extra browser preferences. If you have a large
99
- * profile with several extensions, you should consider installing it on the
100
- * remote host and defining its path via the {@link Options} class. Custom
101
- * binaries are never copied to remote machines and must be referenced by
102
- * installation path.
103
- *
104
- * const {Builder} = require('selenium-webdriver');
105
- * const firefox = require('selenium-webdriver/firefox');
106
- *
107
- * let options = new firefox.Options()
108
- * .setProfile('/profile/path/on/remote/host')
109
- * .setBinary('/install/dir/on/remote/host/firefox-bin');
110
- *
111
- * let driver = new Builder()
112
- * .forBrowser('firefox')
113
- * .usingServer('http://127.0.0.1:4444/wd/hub')
114
- * .setFirefoxOptions(options)
115
- * .build();
116
- *
117
- * __Testing Older Versions of Firefox__
118
- *
119
- * To test versions of Firefox prior to Firefox 47, you must disable the use of
120
- * the geckodriver using the {@link Options} class.
121
- *
122
- * let options = new firefox.Options().useGeckoDriver(false);
123
- *
124
- * Alternatively, you may disable the geckodriver at runtime by setting the
125
- * environment variable `SELENIUM_MARIONETTE=false`.
126
- *
127
- * [geckodriver release]: https://github.com/mozilla/geckodriver/releases/
128
- * [PATH]: http://en.wikipedia.org/wiki/PATH_%28variable%29
129
- */
130
-
131
- 'use strict';
132
-
133
- const url = require('url');
134
-
135
- const {Binary, Channel} = require('./binary'),
136
- Profile = require('./profile').Profile,
137
- decodeProfile = require('./profile').decode,
138
- http = require('../http'),
139
- httpUtil = require('../http/util'),
140
- io = require('../io'),
141
- capabilities = require('../lib/capabilities'),
142
- command = require('../lib/command'),
143
- logging = require('../lib/logging'),
144
- promise = require('../lib/promise'),
145
- webdriver = require('../lib/webdriver'),
146
- net = require('../net'),
147
- portprober = require('../net/portprober'),
148
- remote = require('../remote');
149
-
150
-
151
- /**
152
- * Firefox-specific capability keys. Users should use the {@linkplain Options}
153
- * class instead of referencing these keys directly. _These keys are considered
154
- * implementation details and may be removed or changed at any time._
155
- *
156
- * @enum {string}
157
- */
158
- const Capability = {
159
- /**
160
- * Defines the Firefox binary to use. May be set to either a
161
- * {@linkplain Binary} instance, or a string path to the Firefox executable.
162
- */
163
- BINARY: 'firefox_binary',
164
-
165
- /**
166
- * Specifies whether to use Mozilla's Marionette, or the legacy FirefoxDriver
167
- * from the Selenium project. Defaults to false.
168
- */
169
- MARIONETTE: 'marionette',
170
-
171
- /**
172
- * Defines the Firefox profile to use. May be set to either a
173
- * {@linkplain Profile} instance, or to a base-64 encoded zip of a profile
174
- * directory.
175
- */
176
- PROFILE: 'firefox_profile'
177
- };
178
-
179
-
180
- /**
181
- * Configuration options for the FirefoxDriver.
182
- */
183
- class Options {
184
- constructor() {
185
- /** @private {Profile} */
186
- this.profile_ = null;
187
-
188
- /** @private {Binary} */
189
- this.binary_ = null;
190
-
191
- /** @private {logging.Preferences} */
192
- this.logPrefs_ = null;
193
-
194
- /** @private {?capabilities.ProxyConfig} */
195
- this.proxy_ = null;
196
-
197
- /** @private {boolean} */
198
- this.marionette_ = true;
199
- }
200
-
201
- /**
202
- * Sets the profile to use. The profile may be specified as a
203
- * {@link Profile} object or as the path to an existing Firefox profile to use
204
- * as a template.
205
- *
206
- * @param {(string|!Profile)} profile The profile to use.
207
- * @return {!Options} A self reference.
208
- */
209
- setProfile(profile) {
210
- if (typeof profile === 'string') {
211
- profile = new Profile(profile);
212
- }
213
- this.profile_ = profile;
214
- return this;
215
- }
216
-
217
- /**
218
- * Sets the binary to use. The binary may be specified as the path to a
219
- * Firefox executable, a specific {@link Channel}, or as a {@link Binary}
220
- * object.
221
- *
222
- * @param {(string|!Binary|!Channel)} binary The binary to use.
223
- * @return {!Options} A self reference.
224
- * @throws {TypeError} If `binary` is an invalid type.
225
- */
226
- setBinary(binary) {
227
- if (typeof binary === 'string' || binary instanceof Channel) {
228
- binary = new Binary(binary);
229
- }
230
-
231
- if (!(binary instanceof Binary)) {
232
- throw TypeError(
233
- 'binary must be a string path, Channel, or Binary object');
234
- }
235
-
236
- this.binary_ = binary;
237
- return this;
238
- }
239
-
240
- /**
241
- * Sets the logging preferences for the new session.
242
- * @param {logging.Preferences} prefs The logging preferences.
243
- * @return {!Options} A self reference.
244
- */
245
- setLoggingPreferences(prefs) {
246
- this.logPrefs_ = prefs;
247
- return this;
248
- }
249
-
250
- /**
251
- * Sets the proxy to use.
252
- *
253
- * @param {capabilities.ProxyConfig} proxy The proxy configuration to use.
254
- * @return {!Options} A self reference.
255
- */
256
- setProxy(proxy) {
257
- this.proxy_ = proxy;
258
- return this;
259
- }
260
-
261
- /**
262
- * Sets whether to use Mozilla's geckodriver to drive the browser. This option
263
- * is enabled by default and required for Firefox 47+.
264
- *
265
- * @param {boolean} enable Whether to enable the geckodriver.
266
- * @see https://github.com/mozilla/geckodriver
267
- */
268
- useGeckoDriver(enable) {
269
- this.marionette_ = enable;
270
- return this;
271
- }
272
-
273
- /**
274
- * Converts these options to a {@link capabilities.Capabilities} instance.
275
- *
276
- * @return {!capabilities.Capabilities} A new capabilities object.
277
- */
278
- toCapabilities() {
279
- var caps = capabilities.Capabilities.firefox();
280
- if (this.logPrefs_) {
281
- caps.set(capabilities.Capability.LOGGING_PREFS, this.logPrefs_);
282
- }
283
- if (this.proxy_) {
284
- caps.set(capabilities.Capability.PROXY, this.proxy_);
285
- }
286
- if (this.binary_) {
287
- caps.set(Capability.BINARY, this.binary_);
288
- }
289
- if (this.profile_) {
290
- caps.set(Capability.PROFILE, this.profile_);
291
- }
292
- caps.set(Capability.MARIONETTE, this.marionette_);
293
- return caps;
294
- }
295
- }
296
-
297
-
298
- /**
299
- * Enum of available command contexts.
300
- *
301
- * Command contexts are specific to Marionette, and may be used with the
302
- * {@link #context=} method. Contexts allow you to direct all subsequent
303
- * commands to either "content" (default) or "chrome". The latter gives
304
- * you elevated security permissions.
305
- *
306
- * @enum {string}
307
- */
308
- const Context = {
309
- CONTENT: "content",
310
- CHROME: "chrome",
311
- };
312
-
313
-
314
- const GECKO_DRIVER_EXE =
315
- process.platform === 'win32' ? 'geckodriver.exe' : 'geckodriver';
316
-
317
-
318
- /**
319
- * @return {string} .
320
- * @throws {Error}
321
- */
322
- function findGeckoDriver() {
323
- let exe = io.findInPath(GECKO_DRIVER_EXE, true);
324
- if (!exe) {
325
- throw Error(
326
- 'The ' + GECKO_DRIVER_EXE + ' executable could not be found on the current ' +
327
- 'PATH. Please download the latest version from ' +
328
- 'https://github.com/mozilla/geckodriver/releases/' +
329
- 'WebDriver and ensure it can be found on your PATH.');
330
- }
331
- return exe;
332
- }
333
-
334
-
335
- /**
336
- * @param {(Profile|string)} profile The profile to prepare.
337
- * @param {number} port The port the FirefoxDriver should listen on.
338
- * @return {!Promise<string>} a promise for the path to the profile directory.
339
- */
340
- function prepareProfile(profile, port) {
341
- if (typeof profile === 'string') {
342
- return decodeProfile(/** @type {string} */(profile)).then(dir => {
343
- profile = new Profile(dir);
344
- profile.setPreference('webdriver_firefox_port', port);
345
- return profile.writeToDisk();
346
- });
347
- }
348
-
349
- profile = profile || new Profile;
350
- profile.setPreference('webdriver_firefox_port', port);
351
- return profile.writeToDisk();
352
- }
353
-
354
-
355
- function normalizeProxyConfiguration(config) {
356
- if ('manual' === config.proxyType) {
357
- if (config.ftpProxy && !config.ftpProxyPort) {
358
- let hostAndPort = net.splitHostAndPort(config.ftpProxy);
359
- config.ftpProxy = hostAndPort.host;
360
- config.ftpProxyPort = hostAndPort.port;
361
- }
362
-
363
- if (config.httpProxy && !config.httpProxyPort) {
364
- let hostAndPort = net.splitHostAndPort(config.httpProxy);
365
- config.httpProxy = hostAndPort.host;
366
- config.httpProxyPort = hostAndPort.port;
367
- }
368
-
369
- if (config.sslProxy && !config.sslProxyPort) {
370
- let hostAndPort = net.splitHostAndPort(config.sslProxy);
371
- config.sslProxy = hostAndPort.host;
372
- config.sslProxyPort = hostAndPort.port;
373
- }
374
-
375
- if (config.socksProxy && !config.socksProxyPort) {
376
- let hostAndPort = net.splitHostAndPort(config.socksProxy);
377
- config.socksProxy = hostAndPort.host;
378
- config.socksProxyPort = hostAndPort.port;
379
- }
380
- } else if ('pac' === config.proxyType) {
381
- if (config.proxyAutoconfigUrl && !config.pacUrl) {
382
- config.pacUrl = config.proxyAutoconfigUrl;
383
- }
384
- }
385
- return config;
386
- }
387
-
388
-
389
- /** @enum {string} */
390
- const ExtensionCommand = {
391
- GET_CONTEXT: 'getContext',
392
- SET_CONTEXT: 'setContext',
393
- };
394
-
395
-
396
- /**
397
- * Creates a command executor with support for Marionette's custom commands.
398
- * @param {!Promise<string>} serverUrl The server's URL.
399
- * @return {!command.Executor} The new command executor.
400
- */
401
- function createExecutor(serverUrl) {
402
- let client = serverUrl.then(url => new http.HttpClient(url));
403
- let executor = new http.Executor(client);
404
- configureExecutor(executor);
405
- return executor;
406
- }
407
-
408
-
409
- /**
410
- * Configures the given executor with Firefox-specific commands.
411
- * @param {!http.Executor} executor the executor to configure.
412
- */
413
- function configureExecutor(executor) {
414
- executor.defineCommand(
415
- ExtensionCommand.GET_CONTEXT,
416
- 'GET',
417
- '/session/:sessionId/moz/context');
418
-
419
- executor.defineCommand(
420
- ExtensionCommand.SET_CONTEXT,
421
- 'POST',
422
- '/session/:sessionId/moz/context');
423
- }
424
-
425
-
426
- /**
427
- * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
428
- * a [geckodriver](https://github.com/mozilla/geckodriver) server in a child
429
- * process.
430
- */
431
- class ServiceBuilder extends remote.DriverService.Builder {
432
- /**
433
- * @param {string=} opt_exe Path to the server executable to use. If omitted,
434
- * the builder will attempt to locate the geckodriver on the system PATH.
435
- */
436
- constructor(opt_exe) {
437
- super(opt_exe || findGeckoDriver());
438
- this.setLoopback(true); // Required.
439
- }
440
-
441
- /**
442
- * Enables verbose logging.
443
- *
444
- * @param {boolean=} opt_trace Whether to enable trace-level logging. By
445
- * default, only debug logging is enabled.
446
- * @return {!ServiceBuilder} A self reference.
447
- */
448
- enableVerboseLogging(opt_trace) {
449
- return this.addArguments(opt_trace ? '-vv' : '-v');
450
- }
451
-
452
- /**
453
- * Sets the path to the executable Firefox binary that the geckodriver should
454
- * use. If this method is not called, this builder will attempt to locate
455
- * Firefox in the default installation location for the current platform.
456
- *
457
- * @param {(string|!Binary)} binary Path to the executable Firefox binary to use.
458
- * @return {!ServiceBuilder} A self reference.
459
- * @see Binary#locate()
460
- */
461
- setFirefoxBinary(binary) {
462
- let exe = typeof binary === 'string'
463
- ? Promise.resolve(binary) : binary.locate();
464
- return this.addArguments('-b', exe);
465
- }
466
- }
467
-
468
-
469
- /**
470
- * @typedef {{executor: !command.Executor,
471
- * capabilities: (!capabilities.Capabilities|
472
- * {desired: (capabilities.Capabilities|undefined),
473
- * required: (capabilities.Capabilities|undefined)}),
474
- * onQuit: function(this: void): ?}}
475
- */
476
- var DriverSpec;
477
-
478
-
479
- /**
480
- * @param {(http.Executor|remote.DriverService|undefined)} executor
481
- * @param {!capabilities.Capabilities} caps
482
- * @param {Profile} profile
483
- * @param {Binary} binary
484
- * @return {DriverSpec}
485
- */
486
- function createGeckoDriver(executor, caps, profile, binary) {
487
- let firefoxOptions = {};
488
- caps.set('moz:firefoxOptions', firefoxOptions);
489
-
490
- if (binary) {
491
- if (binary.getExe()) {
492
- firefoxOptions['binary'] = binary.getExe();
493
- }
494
-
495
- let args = binary.getArguments();
496
- if (args.length) {
497
- firefoxOptions['args'] = args;
498
- }
499
- }
500
-
501
- if (profile) {
502
- // If the user specified a template directory or any extensions to install,
503
- // we need to encode the profile as a base64 string (which requires writing
504
- // it to disk first). Otherwise, if the user just specified some custom
505
- // preferences, we can send those directly.
506
- if (profile.getTemplateDir() || profile.getExtensions().length) {
507
- firefoxOptions['profile'] = profile.encode();
508
-
509
- } else {
510
- let prefs = profile.getPreferences();
511
- if (Object.keys(prefs).length) {
512
- firefoxOptions['prefs'] = prefs;
513
- }
514
- }
515
- }
516
-
517
- let sessionCaps = caps;
518
- if (caps.has(capabilities.Capability.PROXY)) {
519
- let proxy = normalizeProxyConfiguration(
520
- caps.get(capabilities.Capability.PROXY));
521
-
522
- // Marionette requires proxy settings to be specified as required
523
- // capabilities. See mozilla/geckodriver#97
524
- let required = new capabilities.Capabilities()
525
- .set(capabilities.Capability.PROXY, proxy);
526
-
527
- caps.delete(capabilities.Capability.PROXY);
528
- sessionCaps = {required, desired: caps};
529
- }
530
-
531
- /** @type {!command.Executor} */
532
- let cmdExecutor;
533
- let onQuit = function() {};
534
-
535
- if (executor instanceof http.Executor) {
536
- configureExecutor(executor);
537
- cmdExecutor = executor;
538
- } else if (executor instanceof remote.DriverService) {
539
- cmdExecutor = createExecutor(executor.start());
540
- onQuit = () => executor.kill();
541
- } else {
542
- let builder = new ServiceBuilder();
543
- if (binary) {
544
- builder.setFirefoxBinary(binary);
545
- }
546
- let service = builder.build();
547
- cmdExecutor = createExecutor(service.start());
548
- onQuit = () => service.kill();
549
- }
550
-
551
- return {
552
- executor: cmdExecutor,
553
- capabilities: sessionCaps,
554
- onQuit
555
- };
556
- }
557
-
558
-
559
- /**
560
- * @param {!capabilities.Capabilities} caps
561
- * @param {Profile} profile
562
- * @param {!Binary} binary
563
- * @return {DriverSpec}
564
- */
565
- function createLegacyDriver(caps, profile, binary, flow) {
566
- profile = profile || new Profile;
567
-
568
- let freePort = portprober.findFreePort();
569
- let preparedProfile =
570
- freePort.then(port => prepareProfile(profile, port));
571
- let command = preparedProfile.then(dir => binary.launch(dir));
572
-
573
- let serverUrl = command.then(() => freePort)
574
- .then(function(/** number */port) {
575
- let serverUrl = url.format({
576
- protocol: 'http',
577
- hostname: net.getLoopbackAddress(),
578
- port: port + '',
579
- pathname: '/hub'
580
- });
581
- let ready = httpUtil.waitForServer(serverUrl, 45 * 1000);
582
- return ready.then(() => serverUrl);
583
- });
584
-
585
- return {
586
- executor: createExecutor(serverUrl),
587
- capabilities: caps,
588
- onQuit: function() {
589
- return command.then(command => {
590
- command.kill();
591
- return preparedProfile.then(io.rmDir)
592
- .then(() => command.result(),
593
- () => command.result());
594
- });
595
- }
596
- };
597
- }
598
-
599
-
600
- /**
601
- * A WebDriver client for Firefox.
602
- */
603
- class Driver extends webdriver.WebDriver {
604
- /**
605
- * Creates a new Firefox session.
606
- *
607
- * @param {(Options|capabilities.Capabilities|Object)=} opt_config The
608
- * configuration options for this driver, specified as either an
609
- * {@link Options} or {@link capabilities.Capabilities}, or as a raw hash
610
- * object.
611
- * @param {(http.Executor|remote.DriverService)=} opt_executor Either a
612
- * pre-configured command executor to use for communicating with an
613
- * externally managed remote end (which is assumed to already be running),
614
- * or the `DriverService` to use to start the geckodriver in a child
615
- * process.
616
- *
617
- * If an executor is provided, care should e taken not to use reuse it with
618
- * other clients as its internal command mappings will be updated to support
619
- * Firefox-specific commands.
620
- *
621
- * _This parameter may only be used with Mozilla's GeckoDriver._
622
- *
623
- * @param {promise.ControlFlow=} opt_flow The flow to
624
- * schedule commands through. Defaults to the active flow object.
625
- * @throws {Error} If a custom command executor is provided and the driver is
626
- * configured to use the legacy FirefoxDriver from the Selenium project.
627
- * @return {!Driver} A new driver instance.
628
- */
629
- static createSession(opt_config, opt_executor, opt_flow) {
630
- let caps;
631
- if (opt_config instanceof Options) {
632
- caps = opt_config.toCapabilities();
633
- } else {
634
- caps = new capabilities.Capabilities(opt_config);
635
- }
636
-
637
- let binary = caps.get(Capability.BINARY) || new Binary();
638
- caps.delete(Capability.BINARY);
639
- if (typeof binary === 'string') {
640
- binary = new Binary(binary);
641
- }
642
-
643
- let profile;
644
- if (caps.has(Capability.PROFILE)) {
645
- profile = caps.get(Capability.PROFILE);
646
- caps.delete(Capability.PROFILE);
647
- }
648
-
649
- // Users must now explicitly disable marionette to use the legacy
650
- // FirefoxDriver.
651
- let noMarionette =
652
- caps.get(Capability.MARIONETTE) === false
653
- || /^0|false$/i.test(process.env['SELENIUM_MARIONETTE']);
654
- let useMarionette = !noMarionette;
655
-
656
- let spec;
657
- if (useMarionette) {
658
- spec = createGeckoDriver(opt_executor, caps, profile, binary);
659
- } else {
660
- if (opt_executor) {
661
- throw Error('You may not use a custom command executor with the legacy'
662
- + ' FirefoxDriver');
663
- }
664
- spec = createLegacyDriver(caps, profile, binary, opt_flow);
665
- }
666
-
667
- return /** @type {!Driver} */(webdriver.WebDriver.createSession(
668
- spec.executor, spec.capabilities, opt_flow, this, spec.onQuit));
669
- }
670
-
671
- /**
672
- * This function is a no-op as file detectors are not supported by this
673
- * implementation.
674
- * @override
675
- */
676
- setFileDetector() {
677
- }
678
-
679
- /**
680
- * Get the context that is currently in effect.
681
- *
682
- * @return {!promise.Thenable<Context>} Current context.
683
- */
684
- getContext() {
685
- return this.schedule(
686
- new command.Command(ExtensionCommand.GET_CONTEXT),
687
- 'get WebDriver.context');
688
- }
689
-
690
- /**
691
- * Changes target context for commands between chrome- and content.
692
- *
693
- * Changing the current context has a stateful impact on all subsequent
694
- * commands. The {@link Context.CONTENT} context has normal web
695
- * platform document permissions, as if you would evaluate arbitrary
696
- * JavaScript. The {@link Context.CHROME} context gets elevated
697
- * permissions that lets you manipulate the browser chrome itself,
698
- * with full access to the XUL toolkit.
699
- *
700
- * Use your powers wisely.
701
- *
702
- * @param {!promise.Thenable<void>} ctx The context to switch to.
703
- */
704
- setContext(ctx) {
705
- return this.schedule(
706
- new command.Command(ExtensionCommand.SET_CONTEXT)
707
- .setParameter("context", ctx),
708
- 'set WebDriver.context');
709
- }
710
- }
711
-
712
-
713
- // PUBLIC API
714
-
715
-
716
- exports.Binary = Binary;
717
- exports.Channel = Channel;
718
- exports.Context = Context;
719
- exports.Driver = Driver;
720
- exports.Options = Options;
721
- exports.Profile = Profile;
722
- exports.ServiceBuilder = ServiceBuilder;