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/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} */(webdriver.WebDriver.createSession(
221
- executor, caps, opt_flow, this, () => 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;
@@ -1,96 +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
- 'use strict';
19
-
20
- var AdmZip = require('adm-zip'),
21
- assert = require('assert'),
22
- crypto = require('crypto'),
23
- fs = require('fs'),
24
- path = require('path');
25
-
26
- var extension = require('../../firefox/extension'),
27
- io = require('../../io'),
28
- it = require('../../testing').it;
29
-
30
-
31
- var JETPACK_EXTENSION = path.join(__dirname,
32
- '../../lib/test/data/firefox/jetpack-sample.xpi');
33
- var NORMAL_EXTENSION = path.join(__dirname,
34
- '../../lib/test/data/firefox/sample.xpi');
35
-
36
- var JETPACK_EXTENSION_ID = 'jid1-EaXX7k0wwiZR7w@jetpack';
37
- var NORMAL_EXTENSION_ID = 'sample@seleniumhq.org';
38
-
39
-
40
- describe('extension', function() {
41
- it('can install a jetpack xpi file', function() {
42
- return io.tmpDir().then(function(dir) {
43
- return extension.install(JETPACK_EXTENSION, dir).then(function(id) {
44
- assert.equal(JETPACK_EXTENSION_ID, id);
45
- var file = path.join(dir, id + '.xpi');
46
- assert.ok(fs.existsSync(file), 'no such file: ' + file);
47
- assert.ok(!fs.statSync(file).isDirectory());
48
-
49
- var copiedSha1 = crypto.createHash('sha1')
50
- .update(fs.readFileSync(file))
51
- .digest('hex');
52
-
53
- var goldenSha1 = crypto.createHash('sha1')
54
- .update(fs.readFileSync(JETPACK_EXTENSION))
55
- .digest('hex');
56
-
57
- assert.equal(copiedSha1, goldenSha1);
58
- });
59
- });
60
- });
61
-
62
- it('can install a normal xpi file', function() {
63
- return io.tmpDir().then(function(dir) {
64
- return extension.install(NORMAL_EXTENSION, dir).then(function(id) {
65
- assert.equal(NORMAL_EXTENSION_ID, id);
66
-
67
- var file = path.join(dir, NORMAL_EXTENSION_ID);
68
- assert.ok(fs.statSync(file).isDirectory());
69
-
70
- assert.ok(fs.existsSync(path.join(file, 'chrome.manifest')));
71
- assert.ok(fs.existsSync(path.join(file, 'content/overlay.xul')));
72
- assert.ok(fs.existsSync(path.join(file, 'content/overlay.js')));
73
- assert.ok(fs.existsSync(path.join(file, 'install.rdf')));
74
- });
75
- });
76
- });
77
-
78
- it('can install an extension from a directory', function() {
79
- return io.tmpDir().then(function(srcDir) {
80
- var buf = fs.readFileSync(NORMAL_EXTENSION);
81
- new AdmZip(buf).extractAllTo(srcDir, true);
82
- return io.tmpDir().then(function(dstDir) {
83
- return extension.install(srcDir, dstDir).then(function(id) {
84
- assert.equal(NORMAL_EXTENSION_ID, id);
85
-
86
- var dir = path.join(dstDir, NORMAL_EXTENSION_ID);
87
-
88
- assert.ok(fs.existsSync(path.join(dir, 'chrome.manifest')));
89
- assert.ok(fs.existsSync(path.join(dir, 'content/overlay.xul')));
90
- assert.ok(fs.existsSync(path.join(dir, 'content/overlay.js')));
91
- assert.ok(fs.existsSync(path.join(dir, 'install.rdf')));
92
- });
93
- });
94
- });
95
- });
96
- });
@@ -1,226 +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
- 'use strict';
19
-
20
- var path = require('path');
21
-
22
- var firefox = require('../../firefox'),
23
- io = require('../../io'),
24
- test = require('../../lib/test'),
25
- assert = require('../../testing/assert'),
26
- Context = require('../../firefox').Context,
27
- error = require('../..').error;
28
-
29
- var {consume} = require('../../lib/promise');
30
-
31
-
32
- var JETPACK_EXTENSION = path.join(__dirname,
33
- '../../lib/test/data/firefox/jetpack-sample.xpi');
34
- var NORMAL_EXTENSION = path.join(__dirname,
35
- '../../lib/test/data/firefox/sample.xpi');
36
-
37
-
38
- test.suite(function(env) {
39
- describe('firefox', function() {
40
- describe('Options', function() {
41
- var driver;
42
-
43
- test.beforeEach(function() {
44
- driver = null;
45
- });
46
-
47
- test.afterEach(function() {
48
- if (driver) {
49
- return driver.quit();
50
- }
51
- });
52
-
53
- /**
54
- * Runs a test that requires Firefox Developer Edition. The test will be
55
- * skipped if dev cannot be found on the current system.
56
- */
57
- function runWithFirefoxDev(options, testFn) {
58
- return firefox.Channel.AURORA.locate().then(exe => {
59
- options.setBinary(exe);
60
- driver = env.builder()
61
- .setFirefoxOptions(options)
62
- .build();
63
- return driver.call(testFn);
64
- }, err => {
65
- console.warn(
66
- 'Skipping test: could not find Firefox Dev Edition: ' + err);
67
- });
68
- }
69
-
70
- describe('can start Firefox with custom preferences', function() {
71
- function runTest(opt_dir) {
72
- return consume(function*() {
73
- let profile = new firefox.Profile(opt_dir);
74
- profile.setPreference('general.useragent.override', 'foo;bar');
75
-
76
- let options = new firefox.Options().setProfile(profile);
77
-
78
- driver = env.builder().
79
- setFirefoxOptions(options).
80
- build();
81
-
82
- yield driver.get('data:text/html,<html><div>content</div></html>');
83
-
84
- var userAgent = yield driver.executeScript(
85
- 'return window.navigator.userAgent');
86
- assert(userAgent).equalTo('foo;bar');
87
- });
88
- }
89
-
90
- test.it('profile created from scratch', function() {
91
- return runTest();
92
- });
93
-
94
- test.it('profile created from template', function() {
95
- return io.tmpDir().then(runTest);
96
- });
97
- });
98
-
99
- test.it('can start Firefox with a jetpack extension', function() {
100
- let profile = new firefox.Profile();
101
- profile.addExtension(JETPACK_EXTENSION);
102
-
103
- let options = new firefox.Options().setProfile(profile);
104
-
105
- return runWithFirefoxDev(options, function*() {
106
- yield loadJetpackPage(driver,
107
- 'data:text/html;charset=UTF-8,<html><div>content</div></html>');
108
-
109
- let text =
110
- yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
111
- assert(text).equalTo('Hello, world!');
112
- });
113
- });
114
-
115
- test.it('can start Firefox with a normal extension', function() {
116
- let profile = new firefox.Profile();
117
- profile.addExtension(NORMAL_EXTENSION);
118
-
119
- let options = new firefox.Options().setProfile(profile);
120
-
121
- return runWithFirefoxDev(options, function*() {
122
- yield driver.get('data:text/html,<html><div>content</div></html>');
123
-
124
- let footer =
125
- yield driver.findElement({id: 'sample-extension-footer'});
126
- let text = yield footer.getText();
127
- assert(text).equalTo('Goodbye');
128
- });
129
- });
130
-
131
- test.it('can start Firefox with multiple extensions', function() {
132
- let profile = new firefox.Profile();
133
- profile.addExtension(JETPACK_EXTENSION);
134
- profile.addExtension(NORMAL_EXTENSION);
135
-
136
- let options = new firefox.Options().setProfile(profile);
137
-
138
- return runWithFirefoxDev(options, function*() {
139
- yield loadJetpackPage(driver,
140
- 'data:text/html;charset=UTF-8,<html><div>content</div></html>');
141
-
142
- let banner =
143
- yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
144
- assert(banner).equalTo('Hello, world!');
145
-
146
- let footer =
147
- yield driver.findElement({id: 'sample-extension-footer'})
148
- .getText();
149
- assert(footer).equalTo('Goodbye');
150
- });
151
- });
152
-
153
- function loadJetpackPage(driver, url) {
154
- // On linux the jetpack extension does not always run the first time
155
- // we load a page. If this happens, just reload the page (a simple
156
- // refresh doesn't appear to work).
157
- return driver.wait(function() {
158
- driver.get(url);
159
- return driver.findElements({id: 'jetpack-sample-banner'})
160
- .then(found => found.length > 0);
161
- }, 3000);
162
- }
163
- });
164
-
165
- describe('binary management', function() {
166
- var driver1, driver2;
167
-
168
- test.ignore(env.isRemote).
169
- it('can start multiple sessions with single binary instance', function*() {
170
- var options = new firefox.Options().setBinary(new firefox.Binary);
171
- env.builder().setFirefoxOptions(options);
172
- driver1 = yield env.builder().build();
173
- driver2 = yield env.builder().build();
174
- // Ok if this doesn't fail.
175
- });
176
-
177
- test.afterEach(function*() {
178
- if (driver1) {
179
- yield driver1.quit();
180
- }
181
-
182
- if (driver2) {
183
- yield driver2.quit();
184
- }
185
- });
186
- });
187
-
188
- describe('context switching', function() {
189
- var driver;
190
-
191
- test.beforeEach(function*() {
192
- driver = yield env.builder().build();
193
- });
194
-
195
- test.afterEach(function() {
196
- if (driver) {
197
- return driver.quit();
198
- }
199
- });
200
-
201
- test.ignore(() => !env.isMarionette).
202
- it('can get context', function() {
203
- return assert(driver.getContext()).equalTo(Context.CONTENT);
204
- });
205
-
206
- test.ignore(() => !env.isMarionette).
207
- it('can set context', function*() {
208
- yield driver.setContext(Context.CHROME);
209
- let ctxt = yield driver.getContext();
210
- assert(ctxt).equalTo(Context.CHROME);
211
-
212
- yield driver.setContext(Context.CONTENT);
213
- ctxt = yield driver.getContext();
214
- assert(ctxt).equalTo(Context.CONTENT);
215
- });
216
-
217
- test.ignore(() => !env.isMarionette).
218
- it('throws on unknown context', function() {
219
- return driver.setContext("foo").then(assert.fail, function(e) {
220
- assert(e).instanceOf(error.InvalidArgumentError);
221
- });
222
- });
223
- });
224
-
225
- });
226
- }, {browsers: ['firefox']});