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.
- package/CHANGES.md +273 -0
- package/NOTICE +1 -1
- package/README.md +28 -36
- package/chrome.js +221 -146
- package/edge.js +43 -118
- package/example/chrome_android.js +8 -9
- package/example/chrome_mobile_emulation.js +9 -10
- package/example/firefox_channels.js +23 -19
- package/example/google_search.js +3 -3
- package/example/google_search_test.js +39 -27
- package/example/headless.js +55 -0
- package/example/logging.js +40 -7
- package/firefox.js +769 -0
- package/http/index.js +41 -4
- package/http/util.js +11 -6
- package/ie.js +57 -98
- package/index.js +182 -115
- package/io/index.js +59 -0
- package/io/zip.js +214 -0
- package/jasmine.json +11 -0
- package/lib/actions.js +68 -63
- package/lib/atoms/get-attribute.js +9 -0
- package/lib/atoms/is-displayed.js +73 -78
- package/lib/by.js +9 -1
- package/lib/capabilities.js +303 -201
- package/lib/command.js +28 -50
- package/lib/error.js +113 -42
- package/lib/http.js +167 -135
- package/lib/input.js +1044 -8
- package/lib/promise.js +222 -3331
- 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/click_tests/disabled_element.html +12 -0
- package/lib/test/data/content-editable.html +10 -0
- package/lib/test/data/firefox/webextension.xpi +0 -0
- package/lib/test/data/inputs.html +42 -0
- package/lib/test/data/key_logger.html +34 -0
- package/lib/test/data/nestedElements.html +10 -1
- package/lib/test/data/scrolling_tests/page_with_partially_hidden_element.html +14 -0
- package/lib/test/data/selectPage.html +12 -0
- package/lib/test/data/simpleTest.html +5 -0
- package/lib/test/data/single_text_input.html +12 -0
- package/lib/test/data/upload_invisible.html +45 -0
- package/lib/test/fileserver.js +23 -19
- package/lib/test/index.js +30 -244
- package/lib/test/resources.js +0 -1
- package/lib/webdriver.js +770 -939
- package/net/index.js +21 -25
- package/net/portprober.js +51 -68
- package/package.json +6 -4
- package/remote/index.js +18 -30
- package/safari.js +42 -129
- package/test/actions_test.js +173 -18
- package/test/builder_test.js +106 -0
- 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 +18 -1
- package/test/http/util_test.js +2 -2
- package/test/{io_test.js → io/io_test.js} +40 -1
- package/test/io/zip_test.js +127 -0
- package/test/lib/by_test.js +21 -0
- package/test/lib/error_test.js +55 -8
- package/test/lib/http_test.js +18 -130
- package/test/lib/input_test.js +1379 -0
- package/test/lib/promise_test.js +473 -908
- package/test/lib/webdriver_test.js +357 -825
- package/test/logging_test.js +37 -43
- package/test/page_loading_test.js +70 -86
- package/test/proxy_test.js +64 -72
- package/test/rect_test.js +14 -25
- package/test/remote_test.js +13 -32
- 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 -315
- package/.npmignore +0 -2
- package/example/async_await_test.js +0 -68
- package/example/google_search_generator.js +0 -50
- package/example/parallel_flows.js +0 -54
- package/firefox/binary.js +0 -344
- package/firefox/extension.js +0 -187
- package/firefox/index.js +0 -722
- package/firefox/profile.js +0 -430
- package/lib/atoms/getAttribute.js +0 -12
- package/lib/events.js +0 -210
- package/lib/firefox/webdriver.json +0 -70
- package/lib/firefox/webdriver.xpi +0 -0
- 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 -96
- package/test/firefox/firefox_test.js +0 -226
- package/test/firefox/profile_test.js +0 -185
- 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/session_test.js +0 -54
- package/test/testing/assert_test.js +0 -373
- package/test/testing/index_test.js +0 -224
- package/testing/assert.js +0 -378
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
const assert = require('assert');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
const error = require('../lib/error');
|
|
24
|
+
const firefox = require('../firefox');
|
|
25
|
+
const io = require('../io');
|
|
26
|
+
const {Browser} = require('../');
|
|
27
|
+
const {Context} = require('../firefox');
|
|
28
|
+
const {Pages, suite, ignore} = require('../lib/test');
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const WEBEXTENSION_EXTENSION =
|
|
32
|
+
path.join(__dirname, '../lib/test/data/firefox/webextension.xpi');
|
|
33
|
+
|
|
34
|
+
const WEBEXTENSION_EXTENSION_ID =
|
|
35
|
+
'webextensions-selenium-example@example.com.xpi';
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
suite(function(env) {
|
|
39
|
+
describe('firefox', function() {
|
|
40
|
+
let driver;
|
|
41
|
+
|
|
42
|
+
beforeEach(function() {
|
|
43
|
+
driver = null;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterEach(function() {
|
|
47
|
+
return driver && driver.quit();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Runs a test that requires Firefox Developer Edition. The test will be
|
|
52
|
+
* skipped if dev cannot be found on the current system.
|
|
53
|
+
*/
|
|
54
|
+
function runWithFirefoxDev(options, testFn) {
|
|
55
|
+
return firefox.Channel.AURORA.locate().then(async (exe) => {
|
|
56
|
+
options = options || new firefox.Options();
|
|
57
|
+
options.setBinary(exe);
|
|
58
|
+
driver = await env.builder()
|
|
59
|
+
.setFirefoxOptions(options)
|
|
60
|
+
.build();
|
|
61
|
+
return testFn();
|
|
62
|
+
}, err => {
|
|
63
|
+
console.warn(
|
|
64
|
+
'Skipping test: could not find Firefox Dev Edition: ' + err);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('Options', function() {
|
|
69
|
+
let profileWithWebExtension;
|
|
70
|
+
let profileWithUserPrefs;
|
|
71
|
+
|
|
72
|
+
before(async function createProfileWithWebExtension() {
|
|
73
|
+
profileWithWebExtension = await io.tmpDir();
|
|
74
|
+
let extensionsDir = path.join(profileWithWebExtension, 'extensions');
|
|
75
|
+
await io.mkdir(extensionsDir);
|
|
76
|
+
await io.write(
|
|
77
|
+
path.join(extensionsDir, WEBEXTENSION_EXTENSION_ID),
|
|
78
|
+
await io.read(WEBEXTENSION_EXTENSION));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
before(async function createProfileWithUserPrefs() {
|
|
82
|
+
profileWithUserPrefs = await io.tmpDir();
|
|
83
|
+
await io.write(
|
|
84
|
+
path.join(profileWithUserPrefs, 'user.js'),
|
|
85
|
+
'user_pref("general.useragent.override", "foo;bar");\n');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('setProfile', function() {
|
|
89
|
+
it('use profile with custom prefs', async function() {
|
|
90
|
+
let options = new firefox.Options;
|
|
91
|
+
options.setProfile(profileWithUserPrefs);
|
|
92
|
+
|
|
93
|
+
driver = env.builder().setFirefoxOptions(options).build();
|
|
94
|
+
|
|
95
|
+
await driver.get(Pages.echoPage);
|
|
96
|
+
await verifyUserAgentWasChanged();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('use profile with extension', function() {
|
|
100
|
+
let options = new firefox.Options;
|
|
101
|
+
options.setProfile(profileWithWebExtension);
|
|
102
|
+
|
|
103
|
+
return runWithFirefoxDev(options, async function() {
|
|
104
|
+
await driver.get(Pages.echoPage);
|
|
105
|
+
await verifyWebExtensionWasInstalled();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('setPreference', function() {
|
|
111
|
+
it('throws if key is not a string', function() {
|
|
112
|
+
let options = new firefox.Options;
|
|
113
|
+
assert.throws(() => options.setPreference(1, 2), TypeError);
|
|
114
|
+
options.setPreference('1', 2); // OK if no throw.
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('throws if value is an invalid type', function() {
|
|
118
|
+
let options = new firefox.Options;
|
|
119
|
+
options.setPreference('a', 1);
|
|
120
|
+
options.setPreference('b', '2');
|
|
121
|
+
options.setPreference('c', true);
|
|
122
|
+
|
|
123
|
+
assert.throws(() => options.setPreference('d', null), TypeError);
|
|
124
|
+
assert.throws(() => options.setPreference('d', undefined), TypeError);
|
|
125
|
+
assert.throws(() => options.setPreference('d', {}), TypeError);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('can start Firefox with custom preferences', async function() {
|
|
129
|
+
let options = new firefox.Options();
|
|
130
|
+
options.setPreference('general.useragent.override', 'foo;bar');
|
|
131
|
+
|
|
132
|
+
driver = env.builder().setFirefoxOptions(options).build();
|
|
133
|
+
|
|
134
|
+
await driver.get(Pages.echoPage);
|
|
135
|
+
await verifyUserAgentWasChanged();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('can add extra prefs on top of an existing profile', async function() {
|
|
139
|
+
let options = new firefox.Options()
|
|
140
|
+
.setPreference('general.useragent.override', 'foo;bar')
|
|
141
|
+
.setProfile(profileWithWebExtension);
|
|
142
|
+
|
|
143
|
+
return runWithFirefoxDev(options, async function() {
|
|
144
|
+
await driver.get(Pages.echoPage);
|
|
145
|
+
await verifyWebExtensionWasInstalled();
|
|
146
|
+
await verifyUserAgentWasChanged();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('addExtensions', function() {
|
|
152
|
+
it('can add extension to brand new profile', async function() {
|
|
153
|
+
let options = new firefox.Options();
|
|
154
|
+
options.addExtensions(WEBEXTENSION_EXTENSION);
|
|
155
|
+
|
|
156
|
+
return runWithFirefoxDev(options, async function() {
|
|
157
|
+
await driver.get(Pages.echoPage);
|
|
158
|
+
await verifyWebExtensionWasInstalled();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('can add extension to custom profile', function() {
|
|
163
|
+
let options = new firefox.Options()
|
|
164
|
+
.addExtensions(WEBEXTENSION_EXTENSION)
|
|
165
|
+
.setProfile(profileWithUserPrefs);
|
|
166
|
+
|
|
167
|
+
return runWithFirefoxDev(options, async function() {
|
|
168
|
+
await driver.get(Pages.echoPage);
|
|
169
|
+
await verifyWebExtensionWasInstalled();
|
|
170
|
+
await verifyUserAgentWasChanged();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('can addExtensions and setPreference', function() {
|
|
175
|
+
let options = new firefox.Options()
|
|
176
|
+
.addExtensions(WEBEXTENSION_EXTENSION)
|
|
177
|
+
.setPreference('general.useragent.override', 'foo;bar')
|
|
178
|
+
|
|
179
|
+
return runWithFirefoxDev(options, async function() {
|
|
180
|
+
await driver.get(Pages.echoPage);
|
|
181
|
+
await verifyWebExtensionWasInstalled();
|
|
182
|
+
await verifyUserAgentWasChanged();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('context switching', function() {
|
|
189
|
+
beforeEach(async function() {
|
|
190
|
+
driver = await env.builder().build();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('can get context', async function() {
|
|
194
|
+
assert.equal(await driver.getContext(), Context.CONTENT);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('can set context', async function() {
|
|
198
|
+
await driver.setContext(Context.CHROME);
|
|
199
|
+
let ctxt = await driver.getContext();
|
|
200
|
+
assert.equal(ctxt, Context.CHROME);
|
|
201
|
+
|
|
202
|
+
await driver.setContext(Context.CONTENT);
|
|
203
|
+
ctxt = await driver.getContext();
|
|
204
|
+
assert.equal(ctxt, Context.CONTENT);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('throws on unknown context', function() {
|
|
208
|
+
return driver.setContext("foo").then(assert.fail, function(e) {
|
|
209
|
+
assert(e instanceof error.InvalidArgumentError);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('addons can be installed and uninstalled at runtime', function() {
|
|
215
|
+
return runWithFirefoxDev(null, async function() {
|
|
216
|
+
await driver.get(Pages.echoPage);
|
|
217
|
+
await verifyWebExtensionNotInstalled();
|
|
218
|
+
|
|
219
|
+
let id = await driver.installAddon(WEBEXTENSION_EXTENSION);
|
|
220
|
+
await driver.sleep(1000); // Give extension time to install (yuck).
|
|
221
|
+
|
|
222
|
+
await driver.get(Pages.echoPage);
|
|
223
|
+
await verifyWebExtensionWasInstalled();
|
|
224
|
+
|
|
225
|
+
await driver.uninstallAddon(id);
|
|
226
|
+
await driver.get(Pages.echoPage);
|
|
227
|
+
await verifyWebExtensionNotInstalled();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
async function verifyUserAgentWasChanged() {
|
|
232
|
+
let userAgent =
|
|
233
|
+
await driver.executeScript('return window.navigator.userAgent');
|
|
234
|
+
assert.equal(userAgent, 'foo;bar');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function verifyWebExtensionNotInstalled() {
|
|
238
|
+
let found =
|
|
239
|
+
await driver.findElements({id: 'webextensions-selenium-example'});
|
|
240
|
+
assert.equal(found.length, 0);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async function verifyWebExtensionWasInstalled() {
|
|
244
|
+
let footer =
|
|
245
|
+
await driver.findElement({id: 'webextensions-selenium-example'});
|
|
246
|
+
let text = await footer.getText();
|
|
247
|
+
assert.equal(
|
|
248
|
+
text, 'Content injected by webextensions-selenium-example');
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}, {browsers: [Browser.FIREFOX]});
|
package/test/http/http_test.js
CHANGED
|
@@ -27,7 +27,6 @@ var HttpClient = require('../../http').HttpClient,
|
|
|
27
27
|
Server = require('../../lib/test/httpserver').Server;
|
|
28
28
|
|
|
29
29
|
describe('HttpClient', function() {
|
|
30
|
-
this.timeout(4 * 1000);
|
|
31
30
|
|
|
32
31
|
var server = new Server(function(req, res) {
|
|
33
32
|
let parsedUrl = url.parse(req.url);
|
|
@@ -44,6 +43,14 @@ describe('HttpClient', function() {
|
|
|
44
43
|
res.writeHead(200, {'content-type': 'text/plain'});
|
|
45
44
|
res.end('hello, world!');
|
|
46
45
|
|
|
46
|
+
} else if (req.method == 'GET' && req.url == '/chunked') {
|
|
47
|
+
res.writeHead(200, {
|
|
48
|
+
'content-type': 'text/html; charset=utf-8',
|
|
49
|
+
'transfer-encoding': 'chunked'
|
|
50
|
+
});
|
|
51
|
+
res.write('<!DOCTYPE html>');
|
|
52
|
+
setTimeout(() => res.end('<h1>Hello, world!</h1>'), 20);
|
|
53
|
+
|
|
47
54
|
} else if (req.method == 'GET' && req.url == '/badredirect') {
|
|
48
55
|
res.writeHead(303, {});
|
|
49
56
|
res.end();
|
|
@@ -121,6 +128,16 @@ describe('HttpClient', function() {
|
|
|
121
128
|
});
|
|
122
129
|
});
|
|
123
130
|
|
|
131
|
+
it('handles chunked responses', function() {
|
|
132
|
+
let request = new HttpRequest('GET', '/chunked');
|
|
133
|
+
|
|
134
|
+
let client = new HttpClient(server.url());
|
|
135
|
+
return client.send(request).then(response => {
|
|
136
|
+
assert.equal(200, response.status);
|
|
137
|
+
assert.equal(response.body, '<!DOCTYPE html><h1>Hello, world!</h1>');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
124
141
|
it('can use basic auth', function() {
|
|
125
142
|
var parsed = url.parse(server.url());
|
|
126
143
|
parsed.auth = 'genie:bottle';
|
package/test/http/util_test.js
CHANGED
|
@@ -132,7 +132,7 @@ describe('selenium-webdriver/http/util', function() {
|
|
|
132
132
|
return util.waitForServer(baseUrl, 200, cancel)
|
|
133
133
|
.then(
|
|
134
134
|
() => { throw Error('Did not expect to succeed!'); },
|
|
135
|
-
(e) => assert.ok(e instanceof
|
|
135
|
+
(e) => assert.ok(e instanceof util.CancellationError));
|
|
136
136
|
});
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -172,7 +172,7 @@ describe('selenium-webdriver/http/util', function() {
|
|
|
172
172
|
return util.waitForUrl(baseUrl, 200, cancel)
|
|
173
173
|
.then(
|
|
174
174
|
() => { throw Error('Did not expect to succeed!'); },
|
|
175
|
-
(e) => assert.ok(e instanceof
|
|
175
|
+
(e) => assert.ok(e instanceof util.CancellationError));
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
});
|
|
@@ -22,7 +22,7 @@ var assert = require('assert'),
|
|
|
22
22
|
path = require('path'),
|
|
23
23
|
tmp = require('tmp');
|
|
24
24
|
|
|
25
|
-
var io = require('
|
|
25
|
+
var io = require('../../io');
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
describe('io', function() {
|
|
@@ -318,4 +318,43 @@ describe('io', function() {
|
|
|
318
318
|
(e) => assert.equal('ENOENT', e.code));
|
|
319
319
|
});
|
|
320
320
|
});
|
|
321
|
+
|
|
322
|
+
describe('mkdirp', function() {
|
|
323
|
+
it('recursively creates entire directory path', function() {
|
|
324
|
+
return io.tmpDir().then(root => {
|
|
325
|
+
let dst = path.join(root, 'foo/bar/baz');
|
|
326
|
+
return io.mkdirp(dst).then(d => {
|
|
327
|
+
assert.strictEqual(d, dst);
|
|
328
|
+
return io.stat(d).then(stats => {
|
|
329
|
+
assert.ok(stats.isDirectory());
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('does nothing if the directory already exists', function() {
|
|
336
|
+
return io.tmpDir()
|
|
337
|
+
.then(dir => io.mkdirp(dir).then(d => assert.strictEqual(d, dir)));
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
describe('walkDir', function() {
|
|
342
|
+
it('walk directory', function() {
|
|
343
|
+
return io.tmpDir().then(dir => {
|
|
344
|
+
fs.writeFileSync(path.join(dir, 'file1'), 'hello');
|
|
345
|
+
fs.mkdirSync(path.join(dir, 'sub'));
|
|
346
|
+
fs.mkdirSync(path.join(dir, 'sub/folder'));
|
|
347
|
+
fs.writeFileSync(path.join(dir, 'sub/folder/file2'), 'goodbye');
|
|
348
|
+
|
|
349
|
+
return io.walkDir(dir).then(seen => {
|
|
350
|
+
assert.deepStrictEqual(
|
|
351
|
+
seen,
|
|
352
|
+
[{path: 'file1', dir: false},
|
|
353
|
+
{path: 'sub', dir: true},
|
|
354
|
+
{path: 'sub/folder', dir: true},
|
|
355
|
+
{path: 'sub/folder/file2', dir: false}]);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
})
|
|
321
360
|
});
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
const assert = require('assert');
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
const io = require('../../io');
|
|
25
|
+
const devmode = require('../../lib/devmode');
|
|
26
|
+
const zip = require('../../io/zip');
|
|
27
|
+
const {InvalidArgumentError} = require('../../lib/error');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const XPI_PATH =
|
|
31
|
+
path.join(__dirname, '../../lib/test/data/firefox/webextension.xpi');
|
|
32
|
+
|
|
33
|
+
describe('io/zip', function() {
|
|
34
|
+
describe('unzip', function() {
|
|
35
|
+
it('creates destination dir if necessary', function() {
|
|
36
|
+
return io.tmpDir()
|
|
37
|
+
.then(dir => zip.unzip(XPI_PATH, dir))
|
|
38
|
+
.then(dir => {
|
|
39
|
+
assertExists(path.join(dir, 'inject.js'));
|
|
40
|
+
assertExists(path.join(dir, 'manifest.json'));
|
|
41
|
+
assertExists(path.join(dir, 'META-INF/manifest.mf'));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('Zip', function() {
|
|
47
|
+
let dir;
|
|
48
|
+
|
|
49
|
+
beforeEach(function() {
|
|
50
|
+
return io.tmpDir().then(d => dir = d);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('can convert an archive to a buffer', function() {
|
|
54
|
+
let z = new zip.Zip;
|
|
55
|
+
return io.mkdirp(path.join(dir, 'a/b/c/d/e')).then(() => {
|
|
56
|
+
return Promise.all([
|
|
57
|
+
io.write(path.join(dir, 'foo'), 'a file'),
|
|
58
|
+
io.write(path.join(dir, 'a/b/c/carrot'), 'an orange carrot'),
|
|
59
|
+
io.write(path.join(dir, 'a/b/c/d/e/elephant'), 'e is for elephant')
|
|
60
|
+
]);
|
|
61
|
+
})
|
|
62
|
+
.then(() => z.addDir(dir))
|
|
63
|
+
.then(() => Promise.all([io.tmpDir(), z.toBuffer()]))
|
|
64
|
+
.then(([outDir, buf]) => {
|
|
65
|
+
let output = path.join(outDir, 'out.zip');
|
|
66
|
+
return io.write(output, buf)
|
|
67
|
+
.then(() => io.tmpDir())
|
|
68
|
+
.then(d => zip.unzip(output, d))
|
|
69
|
+
.then(d => {
|
|
70
|
+
assertContents(path.join(d, 'foo'), 'a file');
|
|
71
|
+
assertContents(path.join(d, 'a/b/c/carrot'), 'an orange carrot');
|
|
72
|
+
assertContents(
|
|
73
|
+
path.join(d, 'a/b/c/d/e/elephant'),
|
|
74
|
+
'e is for elephant');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('getFile', function() {
|
|
80
|
+
it('returns archive file contents as a buffer', function() {
|
|
81
|
+
let foo = path.join(dir, 'foo');
|
|
82
|
+
fs.writeFileSync(foo, 'hello, world!');
|
|
83
|
+
|
|
84
|
+
let z = new zip.Zip;
|
|
85
|
+
return z.addFile(foo).then(() => {
|
|
86
|
+
assert.ok(z.has('foo'));
|
|
87
|
+
return z.getFile('foo');
|
|
88
|
+
}).then(
|
|
89
|
+
buffer => assert.equal(buffer.toString('utf8'), 'hello, world!'));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('returns an error if file is not in archive', function() {
|
|
93
|
+
let z = new zip.Zip;
|
|
94
|
+
assert.ok(!z.has('some-file'));
|
|
95
|
+
return z.getFile('some-file')
|
|
96
|
+
.then(() => assert.fail('should have failed'),
|
|
97
|
+
e => assert.strictEqual(e.constructor, InvalidArgumentError));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it(
|
|
101
|
+
'returns a rejected promise if the requested path is a directory',
|
|
102
|
+
function() {
|
|
103
|
+
let file = path.join(dir, 'aFile');
|
|
104
|
+
fs.writeFileSync(file, 'hello, world!');
|
|
105
|
+
|
|
106
|
+
let z = new zip.Zip;
|
|
107
|
+
return z.addDir(dir, 'foo')
|
|
108
|
+
.then(() => z.getFile('foo'))
|
|
109
|
+
.then(
|
|
110
|
+
() => assert.fail('should have failed'),
|
|
111
|
+
e => assert.strictEqual(
|
|
112
|
+
e.constructor, InvalidArgumentError))
|
|
113
|
+
.then(() => z.getFile('foo/aFile'))
|
|
114
|
+
.then(b => assert.equal(b.toString('utf8'), 'hello, world!'));
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
function assertExists(p) {
|
|
120
|
+
assert.ok(fs.existsSync(p), `expected ${p} to exist`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function assertContents(p, c) {
|
|
124
|
+
assert.strictEqual(
|
|
125
|
+
fs.readFileSync(p, 'utf8'), c, `unexpected file contents for ${p}`);
|
|
126
|
+
}
|
|
127
|
+
});
|
package/test/lib/by_test.js
CHANGED
|
@@ -88,6 +88,27 @@ describe('by', function() {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
describe('checkedLocator', function() {
|
|
91
|
+
it('accepts a By instance', function() {
|
|
92
|
+
let original = by.By.name('foo');
|
|
93
|
+
let locator = by.checkedLocator(original);
|
|
94
|
+
assert.strictEqual(locator, original);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('accepts custom locator functions', function() {
|
|
98
|
+
let original = function() {};
|
|
99
|
+
let locator = by.checkedLocator(original);
|
|
100
|
+
assert.strictEqual(locator, original);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// See https://github.com/SeleniumHQ/selenium/issues/3056
|
|
104
|
+
it('accepts By-like objects', function() {
|
|
105
|
+
let fakeBy = {using: 'id', value: 'foo'};
|
|
106
|
+
let locator = by.checkedLocator(fakeBy);
|
|
107
|
+
assert.strictEqual(locator.constructor, by.By);
|
|
108
|
+
assert.equal(locator.using, 'id');
|
|
109
|
+
assert.equal(locator.value, 'foo');
|
|
110
|
+
});
|
|
111
|
+
|
|
91
112
|
it('accepts class name', function() {
|
|
92
113
|
let locator = by.checkedLocator({className: 'foo'});
|
|
93
114
|
assert.equal('css selector', locator.using);
|
package/test/lib/error_test.js
CHANGED
|
@@ -38,17 +38,19 @@ describe('error', function() {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
test('unknown error', error.WebDriverError);
|
|
41
|
+
test('element not interactable', error.ElementNotInteractableError);
|
|
41
42
|
test('element not selectable', error.ElementNotSelectableError);
|
|
42
|
-
test('
|
|
43
|
+
test('insecure certificate', error.InsecureCertificateError);
|
|
43
44
|
test('invalid argument', error.InvalidArgumentError);
|
|
44
45
|
test('invalid cookie domain', error.InvalidCookieDomainError);
|
|
45
|
-
test('invalid
|
|
46
|
+
test('invalid coordinates', error.InvalidCoordinatesError);
|
|
46
47
|
test('invalid element state', error.InvalidElementStateError);
|
|
47
48
|
test('invalid selector', error.InvalidSelectorError);
|
|
48
49
|
test('invalid session id', error.NoSuchSessionError);
|
|
49
50
|
test('javascript error', error.JavascriptError);
|
|
50
51
|
test('move target out of bounds', error.MoveTargetOutOfBoundsError);
|
|
51
52
|
test('no such alert', error.NoSuchAlertError);
|
|
53
|
+
test('no such cookie', error.NoSuchCookieError);
|
|
52
54
|
test('no such element', error.NoSuchElementError);
|
|
53
55
|
test('no such frame', error.NoSuchFrameError);
|
|
54
56
|
test('no such window', error.NoSuchWindowError);
|
|
@@ -91,8 +93,9 @@ describe('error', function() {
|
|
|
91
93
|
});
|
|
92
94
|
|
|
93
95
|
test(error.WebDriverError, 'unknown error');
|
|
96
|
+
test(error.ElementClickInterceptedError, 'element click intercepted');
|
|
94
97
|
test(error.ElementNotSelectableError, 'element not selectable');
|
|
95
|
-
test(error.
|
|
98
|
+
test(error.InsecureCertificateError, 'insecure certificate');
|
|
96
99
|
test(error.InvalidArgumentError, 'invalid argument');
|
|
97
100
|
test(error.InvalidCookieDomainError, 'invalid cookie domain');
|
|
98
101
|
test(error.InvalidElementStateError, 'invalid element state');
|
|
@@ -101,6 +104,7 @@ describe('error', function() {
|
|
|
101
104
|
test(error.JavascriptError, 'javascript error');
|
|
102
105
|
test(error.MoveTargetOutOfBoundsError, 'move target out of bounds');
|
|
103
106
|
test(error.NoSuchAlertError, 'no such alert');
|
|
107
|
+
test(error.NoSuchCookieError, 'no such cookie');
|
|
104
108
|
test(error.NoSuchElementError, 'no such element');
|
|
105
109
|
test(error.NoSuchFrameError, 'no such frame');
|
|
106
110
|
test(error.NoSuchWindowError, 'no such window');
|
|
@@ -162,17 +166,19 @@ describe('error', function() {
|
|
|
162
166
|
});
|
|
163
167
|
|
|
164
168
|
test('unknown error', error.WebDriverError);
|
|
169
|
+
test('element click intercepted', error.ElementClickInterceptedError);
|
|
165
170
|
test('element not selectable', error.ElementNotSelectableError);
|
|
166
|
-
test('
|
|
171
|
+
test('insecure certificate', error.InsecureCertificateError);
|
|
167
172
|
test('invalid argument', error.InvalidArgumentError);
|
|
168
173
|
test('invalid cookie domain', error.InvalidCookieDomainError);
|
|
169
|
-
test('invalid
|
|
174
|
+
test('invalid coordinates', error.InvalidCoordinatesError);
|
|
170
175
|
test('invalid element state', error.InvalidElementStateError);
|
|
171
176
|
test('invalid selector', error.InvalidSelectorError);
|
|
172
177
|
test('invalid session id', error.NoSuchSessionError);
|
|
173
178
|
test('javascript error', error.JavascriptError);
|
|
174
179
|
test('move target out of bounds', error.MoveTargetOutOfBoundsError);
|
|
175
180
|
test('no such alert', error.NoSuchAlertError);
|
|
181
|
+
test('no such cookie', error.NoSuchCookieError);
|
|
176
182
|
test('no such element', error.NoSuchElementError);
|
|
177
183
|
test('no such frame', error.NoSuchFrameError);
|
|
178
184
|
test('no such window', error.NoSuchWindowError);
|
|
@@ -187,17 +193,54 @@ describe('error', function() {
|
|
|
187
193
|
test('unknown method', error.UnknownMethodError);
|
|
188
194
|
test('unsupported operation', error.UnsupportedOperationError);
|
|
189
195
|
|
|
196
|
+
it('leaves remoteStacktrace empty if not in encoding', function() {
|
|
197
|
+
assert.throws(
|
|
198
|
+
() => error.throwDecodedError({
|
|
199
|
+
error: 'session not created',
|
|
200
|
+
message: 'oops'
|
|
201
|
+
}),
|
|
202
|
+
(e) => {
|
|
203
|
+
assert.strictEqual(e.constructor, error.SessionNotCreatedError);
|
|
204
|
+
assert.strictEqual(e.message, 'oops');
|
|
205
|
+
assert.strictEqual(e.remoteStacktrace, '');
|
|
206
|
+
return true;
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
190
210
|
function test(status, expectedType) {
|
|
191
211
|
it(`"${status}" => ${expectedType.name}`, function() {
|
|
192
212
|
assert.throws(
|
|
193
|
-
() => error.throwDecodedError({
|
|
213
|
+
() => error.throwDecodedError({
|
|
214
|
+
error: status,
|
|
215
|
+
message: 'oops',
|
|
216
|
+
stacktrace: 'some-stacktrace'
|
|
217
|
+
}),
|
|
194
218
|
(e) => {
|
|
195
219
|
assert.strictEqual(e.constructor, expectedType);
|
|
196
220
|
assert.strictEqual(e.message, 'oops');
|
|
221
|
+
assert.strictEqual(e.remoteStacktrace, 'some-stacktrace');
|
|
197
222
|
return true;
|
|
198
223
|
});
|
|
199
224
|
});
|
|
200
225
|
}
|
|
226
|
+
|
|
227
|
+
describe('remote stack trace decoding', function() {
|
|
228
|
+
test('stacktrace');
|
|
229
|
+
test('stackTrace');
|
|
230
|
+
|
|
231
|
+
function test(key) {
|
|
232
|
+
it(`encoded as "${key}"`, function() {
|
|
233
|
+
let data = {error: 'unknown command', message: 'oops'};
|
|
234
|
+
data[key] = 'some-stacktrace';
|
|
235
|
+
assert.throws(
|
|
236
|
+
() => error.throwDecodedError(data),
|
|
237
|
+
(e) => {
|
|
238
|
+
assert.strictEqual(e.remoteStacktrace, 'some-stacktrace');
|
|
239
|
+
return true;
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
201
244
|
});
|
|
202
245
|
|
|
203
246
|
describe('checkLegacyResponse', function() {
|
|
@@ -206,12 +249,12 @@ describe('error', function() {
|
|
|
206
249
|
assert.strictEqual(resp, error.checkLegacyResponse(resp));
|
|
207
250
|
});
|
|
208
251
|
|
|
252
|
+
test('NO_SUCH_SESSION', error.NoSuchSessionError);
|
|
209
253
|
test('NO_SUCH_ELEMENT', error.NoSuchElementError);
|
|
210
254
|
test('NO_SUCH_FRAME', error.NoSuchFrameError);
|
|
211
255
|
test('UNKNOWN_COMMAND', error.UnsupportedOperationError);
|
|
212
256
|
test('UNSUPPORTED_OPERATION', error.UnsupportedOperationError);
|
|
213
257
|
test('STALE_ELEMENT_REFERENCE', error.StaleElementReferenceError);
|
|
214
|
-
test('ELEMENT_NOT_VISIBLE', error.ElementNotVisibleError);
|
|
215
258
|
test('INVALID_ELEMENT_STATE', error.InvalidElementStateError);
|
|
216
259
|
test('UNKNOWN_ERROR', error.WebDriverError);
|
|
217
260
|
test('ELEMENT_NOT_SELECTABLE', error.ElementNotSelectableError);
|
|
@@ -224,12 +267,16 @@ describe('error', function() {
|
|
|
224
267
|
test('UNEXPECTED_ALERT_OPEN', error.UnexpectedAlertOpenError);
|
|
225
268
|
test('NO_SUCH_ALERT', error.NoSuchAlertError);
|
|
226
269
|
test('SCRIPT_TIMEOUT', error.ScriptTimeoutError);
|
|
227
|
-
test('INVALID_ELEMENT_COORDINATES', error.
|
|
270
|
+
test('INVALID_ELEMENT_COORDINATES', error.InvalidCoordinatesError);
|
|
228
271
|
test('INVALID_SELECTOR_ERROR', error.InvalidSelectorError);
|
|
229
272
|
test('SESSION_NOT_CREATED', error.SessionNotCreatedError);
|
|
230
273
|
test('MOVE_TARGET_OUT_OF_BOUNDS', error.MoveTargetOutOfBoundsError);
|
|
231
274
|
test('INVALID_XPATH_SELECTOR', error.InvalidSelectorError);
|
|
232
275
|
test('INVALID_XPATH_SELECTOR_RETURN_TYPE', error.InvalidSelectorError);
|
|
276
|
+
test('ELEMENT_NOT_INTERACTABLE', error.ElementNotInteractableError);
|
|
277
|
+
test('INVALID_ARGUMENT', error.InvalidArgumentError);
|
|
278
|
+
test('UNABLE_TO_CAPTURE_SCREEN', error.UnableToCaptureScreenError);
|
|
279
|
+
test('ELEMENT_CLICK_INTERCEPTED', error.ElementClickInterceptedError);
|
|
233
280
|
test('METHOD_NOT_ALLOWED', error.UnsupportedOperationError);
|
|
234
281
|
|
|
235
282
|
describe('UnexpectedAlertOpenError', function() {
|