selenium-webdriver 4.0.0-alpha.3 → 4.0.0-alpha.4
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 +8 -1
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +0 -0
- package/chrome.js +0 -0
- package/edge.js +0 -0
- package/example/chrome_android.js +0 -0
- package/example/chrome_mobile_emulation.js +0 -0
- package/example/firefox_channels.js +0 -0
- package/example/google_search.js +0 -0
- package/example/google_search_test.js +0 -0
- package/example/headless.js +0 -0
- package/example/logging.js +0 -0
- package/firefox.js +20 -3
- package/http/index.js +0 -0
- package/http/util.js +0 -0
- package/ie.js +0 -0
- package/index.js +0 -0
- package/io/exec.js +0 -0
- package/io/index.js +0 -0
- package/io/zip.js +0 -0
- package/lib/actions.js +0 -0
- package/lib/by.js +0 -0
- package/lib/capabilities.js +0 -0
- package/lib/command.js +0 -0
- package/lib/error.js +0 -0
- package/lib/http.js +0 -0
- package/lib/input.js +0 -0
- package/lib/logging.js +0 -0
- package/lib/promise.js +0 -0
- package/lib/proxy.js +0 -0
- package/lib/session.js +0 -0
- package/lib/symbols.js +0 -0
- package/lib/until.js +0 -0
- package/lib/webdriver.js +0 -0
- package/net/index.js +0 -0
- package/net/portprober.js +0 -0
- package/package.json +1 -1
- package/proxy.js +0 -0
- package/remote/index.js +0 -0
- package/safari.js +0 -0
- package/testing/index.js +0 -0
- package/BUILD.bazel +0 -88
- package/jasmine.json +0 -11
- package/lib/README +0 -5
- package/lib/atoms/BUILD.bazel +0 -28
- package/lib/atoms/make-atoms-module.js +0 -12
- package/lib/test/bootstrap_jasmine.js +0 -28
- package/lib/test/build.js +0 -156
- package/lib/test/data/actions/click.html +0 -24
- package/lib/test/data/actions/drag.html +0 -77
- package/lib/test/data/actions/record_click.html +0 -21
- package/lib/test/data/chrome/download.html +0 -2
- package/lib/test/data/firefox/webextension.xpi +0 -0
- package/lib/test/fileserver.js +0 -337
- package/lib/test/httpserver.js +0 -120
- package/lib/test/index.js +0 -87
- package/lib/test/resources.js +0 -40
- package/test/actions_test.js +0 -206
- package/test/builder_test.js +0 -106
- package/test/chrome/devtools_test.js +0 -93
- package/test/chrome/options_test.js +0 -121
- package/test/chrome/service_test.js +0 -45
- package/test/cookie_test.js +0 -210
- package/test/element_finding_test.js +0 -431
- package/test/execute_script_test.js +0 -355
- package/test/fingerprint_test.js +0 -63
- package/test/firefox_test.js +0 -233
- package/test/frame_test.js +0 -45
- package/test/http/http_test.js +0 -229
- package/test/http/util_test.js +0 -178
- package/test/io/io_test.js +0 -364
- package/test/io/zip_test.js +0 -126
- package/test/lib/by_test.js +0 -160
- package/test/lib/capabilities_test.js +0 -129
- package/test/lib/error_test.js +0 -333
- package/test/lib/http_test.js +0 -576
- package/test/lib/input_test.js +0 -1379
- package/test/lib/logging_test.js +0 -272
- package/test/lib/promise_test.js +0 -674
- package/test/lib/testutil.js +0 -90
- package/test/lib/until_test.js +0 -478
- package/test/lib/webdriver_test.js +0 -1692
- package/test/logging_test.js +0 -160
- package/test/net/index_test.js +0 -60
- package/test/net/portprober_test.js +0 -128
- package/test/page_loading_test.js +0 -156
- package/test/proxy_test.js +0 -167
- package/test/rect_test.js +0 -51
- package/test/remote_test.js +0 -98
- package/test/safari_test.js +0 -44
- package/test/stale_element_test.js +0 -60
- package/test/upload_test.js +0 -78
- package/test/window_test.js +0 -168
- package/tools/init_jasmine.js +0 -7
package/test/io/io_test.js
DELETED
|
@@ -1,364 +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 assert = require('assert'),
|
|
21
|
-
fs = require('fs'),
|
|
22
|
-
path = require('path'),
|
|
23
|
-
tmp = require('tmp');
|
|
24
|
-
|
|
25
|
-
var io = require('../../io');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
describe('io', function() {
|
|
29
|
-
describe('copy', function() {
|
|
30
|
-
var tmpDir;
|
|
31
|
-
|
|
32
|
-
before(function() {
|
|
33
|
-
return io.tmpDir().then(function(d) {
|
|
34
|
-
tmpDir = d;
|
|
35
|
-
|
|
36
|
-
fs.writeFileSync(path.join(d, 'foo'), 'Hello, world');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('can copy one file to another', function() {
|
|
41
|
-
return io.tmpFile().then(function(f) {
|
|
42
|
-
return io.copy(path.join(tmpDir, 'foo'), f).then(function(p) {
|
|
43
|
-
assert.equal(p, f);
|
|
44
|
-
assert.equal('Hello, world', fs.readFileSync(p));
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('can copy symlink to destination', function() {
|
|
50
|
-
if (process.platform === 'win32') {
|
|
51
|
-
return; // No symlinks on windows.
|
|
52
|
-
}
|
|
53
|
-
fs.symlinkSync(
|
|
54
|
-
path.join(tmpDir, 'foo'),
|
|
55
|
-
path.join(tmpDir, 'symlinked-foo'));
|
|
56
|
-
return io.tmpFile().then(function(f) {
|
|
57
|
-
return io.copy(path.join(tmpDir, 'symlinked-foo'), f).then(function(p) {
|
|
58
|
-
assert.equal(p, f);
|
|
59
|
-
assert.equal('Hello, world', fs.readFileSync(p));
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('fails if given a directory as a source', function() {
|
|
65
|
-
return io.tmpFile().then(function(f) {
|
|
66
|
-
return io.copy(tmpDir, f);
|
|
67
|
-
}).then(function() {
|
|
68
|
-
throw Error('Should have failed with a type error');
|
|
69
|
-
}, function() {
|
|
70
|
-
// Do nothing; expected.
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('copyDir', function() {
|
|
76
|
-
it('copies recursively', function() {
|
|
77
|
-
return io.tmpDir().then(function(dir) {
|
|
78
|
-
fs.writeFileSync(path.join(dir, 'file1'), 'hello');
|
|
79
|
-
fs.mkdirSync(path.join(dir, 'sub'));
|
|
80
|
-
fs.mkdirSync(path.join(dir, 'sub/folder'));
|
|
81
|
-
fs.writeFileSync(path.join(dir, 'sub/folder/file2'), 'goodbye');
|
|
82
|
-
|
|
83
|
-
return io.tmpDir().then(function(dst) {
|
|
84
|
-
return io.copyDir(dir, dst).then(function(ret) {
|
|
85
|
-
assert.equal(dst, ret);
|
|
86
|
-
|
|
87
|
-
assert.equal('hello',
|
|
88
|
-
fs.readFileSync(path.join(dst, 'file1')));
|
|
89
|
-
assert.equal('goodbye',
|
|
90
|
-
fs.readFileSync(path.join(dst, 'sub/folder/file2')));
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('creates destination dir if necessary', function() {
|
|
97
|
-
return io.tmpDir().then(function(srcDir) {
|
|
98
|
-
fs.writeFileSync(path.join(srcDir, 'foo'), 'hi');
|
|
99
|
-
return io.tmpDir().then(function(dstDir) {
|
|
100
|
-
return io.copyDir(srcDir, path.join(dstDir, 'sub'));
|
|
101
|
-
});
|
|
102
|
-
}).then(function(p) {
|
|
103
|
-
assert.equal('sub', path.basename(p));
|
|
104
|
-
assert.equal('hi', fs.readFileSync(path.join(p, 'foo')));
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('supports regex exclusion filter', function() {
|
|
109
|
-
return io.tmpDir().then(function(src) {
|
|
110
|
-
fs.writeFileSync(path.join(src, 'foo'), 'a');
|
|
111
|
-
fs.writeFileSync(path.join(src, 'bar'), 'b');
|
|
112
|
-
fs.writeFileSync(path.join(src, 'baz'), 'c');
|
|
113
|
-
fs.mkdirSync(path.join(src, 'sub'));
|
|
114
|
-
fs.writeFileSync(path.join(src, 'sub/quux'), 'd');
|
|
115
|
-
fs.writeFileSync(path.join(src, 'sub/quot'), 'e');
|
|
116
|
-
|
|
117
|
-
return io.tmpDir().then(function(dst) {
|
|
118
|
-
return io.copyDir(src, dst, /(bar|quux)/);
|
|
119
|
-
});
|
|
120
|
-
}).then(function(dir) {
|
|
121
|
-
assert.equal('a', fs.readFileSync(path.join(dir, 'foo')));
|
|
122
|
-
assert.equal('c', fs.readFileSync(path.join(dir, 'baz')));
|
|
123
|
-
assert.equal('e', fs.readFileSync(path.join(dir, 'sub/quot')));
|
|
124
|
-
|
|
125
|
-
assert.ok(!fs.existsSync(path.join(dir, 'bar')));
|
|
126
|
-
assert.ok(!fs.existsSync(path.join(dir, 'sub/quux')));
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('supports exclusion filter function', function() {
|
|
131
|
-
return io.tmpDir().then(function(src) {
|
|
132
|
-
fs.writeFileSync(path.join(src, 'foo'), 'a');
|
|
133
|
-
fs.writeFileSync(path.join(src, 'bar'), 'b');
|
|
134
|
-
fs.writeFileSync(path.join(src, 'baz'), 'c');
|
|
135
|
-
fs.mkdirSync(path.join(src, 'sub'));
|
|
136
|
-
fs.writeFileSync(path.join(src, 'sub/quux'), 'd');
|
|
137
|
-
fs.writeFileSync(path.join(src, 'sub/quot'), 'e');
|
|
138
|
-
|
|
139
|
-
return io.tmpDir().then(function(dst) {
|
|
140
|
-
return io.copyDir(src, dst, function(f) {
|
|
141
|
-
return f !== path.join(src, 'foo')
|
|
142
|
-
&& f !== path.join(src, 'sub/quot');
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
}).then(function(dir) {
|
|
146
|
-
assert.equal('b', fs.readFileSync(path.join(dir, 'bar')));
|
|
147
|
-
assert.equal('c', fs.readFileSync(path.join(dir, 'baz')));
|
|
148
|
-
assert.equal('d', fs.readFileSync(path.join(dir, 'sub/quux')));
|
|
149
|
-
|
|
150
|
-
assert.ok(!fs.existsSync(path.join(dir, 'foo')));
|
|
151
|
-
assert.ok(!fs.existsSync(path.join(dir, 'sub/quot')));
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('exists', function() {
|
|
157
|
-
var dir;
|
|
158
|
-
|
|
159
|
-
before(function() {
|
|
160
|
-
return io.tmpDir().then(function(d) {
|
|
161
|
-
dir = d;
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('returns a rejected promise if input value is invalid', function() {
|
|
166
|
-
return io.exists(undefined).then(
|
|
167
|
-
() => assert.fail('should have failed'),
|
|
168
|
-
e => assert.ok(e instanceof TypeError));
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('works for directories', function() {
|
|
172
|
-
return io.exists(dir).then(assert.ok);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('works for files', function() {
|
|
176
|
-
var file = path.join(dir, 'foo');
|
|
177
|
-
fs.writeFileSync(file, '');
|
|
178
|
-
return io.exists(file).then(assert.ok);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('does not return a rejected promise if file does not exist', function() {
|
|
182
|
-
return io.exists(path.join(dir, 'not-there')).then(function(exists) {
|
|
183
|
-
assert.ok(!exists);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe('unlink', function() {
|
|
189
|
-
var dir;
|
|
190
|
-
|
|
191
|
-
before(function() {
|
|
192
|
-
return io.tmpDir().then(function(d) {
|
|
193
|
-
dir = d;
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('silently succeeds if the path does not exist', function() {
|
|
198
|
-
return io.unlink(path.join(dir, 'not-there'));
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('deletes files', function() {
|
|
202
|
-
var file = path.join(dir, 'foo');
|
|
203
|
-
fs.writeFileSync(file, '');
|
|
204
|
-
return io.exists(file).then(assert.ok).then(function() {
|
|
205
|
-
return io.unlink(file);
|
|
206
|
-
}).then(function() {
|
|
207
|
-
return io.exists(file);
|
|
208
|
-
}).then(function(exists) {
|
|
209
|
-
return assert.ok(!exists);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe('rmDir', function() {
|
|
215
|
-
it('succeeds if the designated directory does not exist', function() {
|
|
216
|
-
return io.tmpDir().then(function(d) {
|
|
217
|
-
return io.rmDir(path.join(d, 'i/do/not/exist'));
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('deletes recursively', function() {
|
|
222
|
-
return io.tmpDir().then(function(dir) {
|
|
223
|
-
fs.writeFileSync(path.join(dir, 'file1'), 'hello');
|
|
224
|
-
fs.mkdirSync(path.join(dir, 'sub'));
|
|
225
|
-
fs.mkdirSync(path.join(dir, 'sub/folder'));
|
|
226
|
-
fs.writeFileSync(path.join(dir, 'sub/folder/file2'), 'goodbye');
|
|
227
|
-
|
|
228
|
-
return io.rmDir(dir).then(function() {
|
|
229
|
-
assert.ok(!fs.existsSync(dir));
|
|
230
|
-
assert.ok(!fs.existsSync(path.join(dir, 'sub/folder/file2')));
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe('findInPath', function() {
|
|
237
|
-
const savedPathEnv = process.env['PATH'];
|
|
238
|
-
afterEach(() => process.env['PATH'] = savedPathEnv);
|
|
239
|
-
|
|
240
|
-
const cwd = process.cwd;
|
|
241
|
-
afterEach(() => process.cwd = cwd);
|
|
242
|
-
|
|
243
|
-
let dirs;
|
|
244
|
-
beforeEach(() => {
|
|
245
|
-
return Promise.all([io.tmpDir(), io.tmpDir(), io.tmpDir()]).then(arr => {
|
|
246
|
-
dirs = arr;
|
|
247
|
-
process.env['PATH'] = arr.join(path.delimiter);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('returns null if file cannot be found', () => {
|
|
252
|
-
assert.strictEqual(io.findInPath('foo.txt'), null);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('can find file on path', () => {
|
|
256
|
-
let filePath = path.join(dirs[1], 'foo.txt');
|
|
257
|
-
fs.writeFileSync(filePath, 'hi');
|
|
258
|
-
|
|
259
|
-
assert.strictEqual(io.findInPath('foo.txt'), filePath);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('returns null if file is in a subdir of a directory on the path', () => {
|
|
263
|
-
let subDir = path.join(dirs[2], 'sub');
|
|
264
|
-
fs.mkdirSync(subDir);
|
|
265
|
-
|
|
266
|
-
let filePath = path.join(subDir, 'foo.txt');
|
|
267
|
-
fs.writeFileSync(filePath, 'hi');
|
|
268
|
-
|
|
269
|
-
assert.strictEqual(io.findInPath('foo.txt'), null);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('does not match on directories', () => {
|
|
273
|
-
fs.mkdirSync(path.join(dirs[2], 'sub'));
|
|
274
|
-
assert.strictEqual(io.findInPath('sub'), null);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('will look in cwd first if requested', () => {
|
|
278
|
-
return io.tmpDir().then(fakeCwd => {
|
|
279
|
-
process.cwd = () => fakeCwd;
|
|
280
|
-
|
|
281
|
-
let theFile = path.join(fakeCwd, 'foo.txt');
|
|
282
|
-
|
|
283
|
-
fs.writeFileSync(path.join(dirs[1], 'foo.txt'), 'hi');
|
|
284
|
-
fs.writeFileSync(theFile, 'bye');
|
|
285
|
-
|
|
286
|
-
assert.strictEqual(io.findInPath('foo.txt', true), theFile);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
describe('read', function() {
|
|
292
|
-
var tmpDir;
|
|
293
|
-
|
|
294
|
-
before(function() {
|
|
295
|
-
return io.tmpDir().then(function(d) {
|
|
296
|
-
tmpDir = d;
|
|
297
|
-
|
|
298
|
-
fs.writeFileSync(path.join(d, 'foo'), 'Hello, world');
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it('can read a file', function() {
|
|
303
|
-
return io.read(path.join(tmpDir, 'foo')).then(buff => {
|
|
304
|
-
assert.ok(buff instanceof Buffer);
|
|
305
|
-
assert.equal('Hello, world', buff.toString());
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('catches errors from invalid input', function() {
|
|
310
|
-
return io.read({})
|
|
311
|
-
.then(() => assert.fail('should have failed'),
|
|
312
|
-
(e) => assert.ok(e instanceof TypeError));
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('rejects returned promise if file does not exist', function() {
|
|
316
|
-
return io.read(path.join(tmpDir, 'not-there'))
|
|
317
|
-
.then(() => assert.fail('should have failed'),
|
|
318
|
-
(e) => assert.equal('ENOENT', e.code));
|
|
319
|
-
});
|
|
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', async function() {
|
|
343
|
-
let dir = await io.tmpDir();
|
|
344
|
-
|
|
345
|
-
fs.writeFileSync(path.join(dir, 'file1'), 'hello');
|
|
346
|
-
fs.mkdirSync(path.join(dir, 'sub'));
|
|
347
|
-
fs.mkdirSync(path.join(dir, 'sub/folder'));
|
|
348
|
-
fs.writeFileSync(path.join(dir, 'sub/folder/file2'), 'goodbye');
|
|
349
|
-
|
|
350
|
-
let seen = await io.walkDir(dir);
|
|
351
|
-
seen.sort((a, b) => {
|
|
352
|
-
if (a.path < b.path) return -1;
|
|
353
|
-
if (a.path > b.path) return 1;
|
|
354
|
-
return 0;
|
|
355
|
-
});
|
|
356
|
-
assert.deepStrictEqual(
|
|
357
|
-
seen,
|
|
358
|
-
[{path: 'file1', dir: false},
|
|
359
|
-
{path: 'sub', dir: true},
|
|
360
|
-
{path: path.join('sub', 'folder'), dir: true},
|
|
361
|
-
{path: path.join('sub', 'folder', 'file2'), dir: false}]);
|
|
362
|
-
});
|
|
363
|
-
})
|
|
364
|
-
});
|
package/test/io/zip_test.js
DELETED
|
@@ -1,126 +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
|
-
const assert = require('assert');
|
|
21
|
-
const fs = require('fs');
|
|
22
|
-
const path = require('path');
|
|
23
|
-
|
|
24
|
-
const io = require('../../io');
|
|
25
|
-
const zip = require('../../io/zip');
|
|
26
|
-
const {InvalidArgumentError} = require('../../lib/error');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const XPI_PATH =
|
|
30
|
-
path.join(__dirname, '../../lib/test/data/firefox/webextension.xpi');
|
|
31
|
-
|
|
32
|
-
describe('io/zip', function() {
|
|
33
|
-
describe('unzip', function() {
|
|
34
|
-
it('creates destination dir if necessary', function() {
|
|
35
|
-
return io.tmpDir()
|
|
36
|
-
.then(dir => zip.unzip(XPI_PATH, dir))
|
|
37
|
-
.then(dir => {
|
|
38
|
-
assertExists(path.join(dir, 'inject.js'));
|
|
39
|
-
assertExists(path.join(dir, 'manifest.json'));
|
|
40
|
-
assertExists(path.join(dir, 'META-INF/manifest.mf'));
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('Zip', function() {
|
|
46
|
-
let dir;
|
|
47
|
-
|
|
48
|
-
beforeEach(function() {
|
|
49
|
-
return io.tmpDir().then(d => dir = d);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('can convert an archive to a buffer', function() {
|
|
53
|
-
let z = new zip.Zip;
|
|
54
|
-
return io.mkdirp(path.join(dir, 'a/b/c/d/e')).then(() => {
|
|
55
|
-
return Promise.all([
|
|
56
|
-
io.write(path.join(dir, 'foo'), 'a file'),
|
|
57
|
-
io.write(path.join(dir, 'a/b/c/carrot'), 'an orange carrot'),
|
|
58
|
-
io.write(path.join(dir, 'a/b/c/d/e/elephant'), 'e is for elephant')
|
|
59
|
-
]);
|
|
60
|
-
})
|
|
61
|
-
.then(() => z.addDir(dir))
|
|
62
|
-
.then(() => Promise.all([io.tmpDir(), z.toBuffer()]))
|
|
63
|
-
.then(([outDir, buf]) => {
|
|
64
|
-
let output = path.join(outDir, 'out.zip');
|
|
65
|
-
return io.write(output, buf)
|
|
66
|
-
.then(() => io.tmpDir())
|
|
67
|
-
.then(d => zip.unzip(output, d))
|
|
68
|
-
.then(d => {
|
|
69
|
-
assertContents(path.join(d, 'foo'), 'a file');
|
|
70
|
-
assertContents(path.join(d, 'a/b/c/carrot'), 'an orange carrot');
|
|
71
|
-
assertContents(
|
|
72
|
-
path.join(d, 'a/b/c/d/e/elephant'),
|
|
73
|
-
'e is for elephant');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('getFile', function() {
|
|
79
|
-
it('returns archive file contents as a buffer', function() {
|
|
80
|
-
let foo = path.join(dir, 'foo');
|
|
81
|
-
fs.writeFileSync(foo, 'hello, world!');
|
|
82
|
-
|
|
83
|
-
let z = new zip.Zip;
|
|
84
|
-
return z.addFile(foo).then(() => {
|
|
85
|
-
assert.ok(z.has('foo'));
|
|
86
|
-
return z.getFile('foo');
|
|
87
|
-
}).then(
|
|
88
|
-
buffer => assert.equal(buffer.toString('utf8'), 'hello, world!'));
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('returns an error if file is not in archive', function() {
|
|
92
|
-
let z = new zip.Zip;
|
|
93
|
-
assert.ok(!z.has('some-file'));
|
|
94
|
-
return z.getFile('some-file')
|
|
95
|
-
.then(() => assert.fail('should have failed'),
|
|
96
|
-
e => assert.strictEqual(e.constructor, InvalidArgumentError));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it(
|
|
100
|
-
'returns a rejected promise if the requested path is a directory',
|
|
101
|
-
function() {
|
|
102
|
-
let file = path.join(dir, 'aFile');
|
|
103
|
-
fs.writeFileSync(file, 'hello, world!');
|
|
104
|
-
|
|
105
|
-
let z = new zip.Zip;
|
|
106
|
-
return z.addDir(dir, 'foo')
|
|
107
|
-
.then(() => z.getFile('foo'))
|
|
108
|
-
.then(
|
|
109
|
-
() => assert.fail('should have failed'),
|
|
110
|
-
e => assert.strictEqual(
|
|
111
|
-
e.constructor, InvalidArgumentError))
|
|
112
|
-
.then(() => z.getFile('foo/aFile'))
|
|
113
|
-
.then(b => assert.equal(b.toString('utf8'), 'hello, world!'));
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
function assertExists(p) {
|
|
119
|
-
assert.ok(fs.existsSync(p), `expected ${p} to exist`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function assertContents(p, c) {
|
|
123
|
-
assert.strictEqual(
|
|
124
|
-
fs.readFileSync(p, 'utf8'), c, `unexpected file contents for ${p}`);
|
|
125
|
-
}
|
|
126
|
-
});
|
package/test/lib/by_test.js
DELETED
|
@@ -1,160 +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 assert = require('assert');
|
|
21
|
-
var by = require('../../lib/by');
|
|
22
|
-
|
|
23
|
-
describe('by', function() {
|
|
24
|
-
describe('By', function() {
|
|
25
|
-
describe('className', function() {
|
|
26
|
-
it('delegates to By.css', function() {
|
|
27
|
-
let locator = by.By.className('foo');
|
|
28
|
-
assert.equal('css selector', locator.using);
|
|
29
|
-
assert.equal('.foo', locator.value);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('escapes class name', function() {
|
|
33
|
-
let locator = by.By.className('foo#bar');
|
|
34
|
-
assert.equal('css selector', locator.using);
|
|
35
|
-
assert.equal('.foo\\#bar', locator.value);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('translates compound class names', function() {
|
|
39
|
-
let locator = by.By.className('a b');
|
|
40
|
-
assert.equal('css selector', locator.using);
|
|
41
|
-
assert.equal('.a.b', locator.value);
|
|
42
|
-
|
|
43
|
-
locator = by.By.className(' x y z-1 "g" ');
|
|
44
|
-
assert.equal('css selector', locator.using);
|
|
45
|
-
assert.equal('.x.y.z-1.\\"g\\"', locator.value);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('id', function() {
|
|
50
|
-
it('delegates to By.css', function() {
|
|
51
|
-
let locator = by.By.id('foo');
|
|
52
|
-
assert.equal('css selector', locator.using);
|
|
53
|
-
assert.equal('*[id="foo"]', locator.value);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('escapes the ID', function() {
|
|
57
|
-
let locator = by.By.id('foo#bar');
|
|
58
|
-
assert.equal('css selector', locator.using);
|
|
59
|
-
assert.equal('*[id="foo\\#bar"]', locator.value);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('name', function() {
|
|
64
|
-
it('delegates to By.css', function() {
|
|
65
|
-
let locator = by.By.name('foo')
|
|
66
|
-
assert.equal('css selector', locator.using);
|
|
67
|
-
assert.equal('*[name="foo"]', locator.value);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('escapes the name', function() {
|
|
71
|
-
let locator = by.By.name('foo"bar"')
|
|
72
|
-
assert.equal('css selector', locator.using);
|
|
73
|
-
assert.equal('*[name="foo\\"bar\\""]', locator.value);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('escapes the name when it starts with a number', function() {
|
|
77
|
-
let locator = by.By.name('123foo"bar"')
|
|
78
|
-
assert.equal('css selector', locator.using);
|
|
79
|
-
assert.equal('*[name="\\31 23foo\\"bar\\""]', locator.value);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('escapes the name when it starts with a negative number', function() {
|
|
83
|
-
let locator = by.By.name('-123foo"bar"')
|
|
84
|
-
assert.equal('css selector', locator.using);
|
|
85
|
-
assert.equal('*[name="-\\31 23foo\\"bar\\""]', locator.value);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
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
|
-
|
|
112
|
-
it('accepts class name', function() {
|
|
113
|
-
let locator = by.checkedLocator({className: 'foo'});
|
|
114
|
-
assert.equal('css selector', locator.using);
|
|
115
|
-
assert.equal('.foo', locator.value);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('accepts css', function() {
|
|
119
|
-
let locator = by.checkedLocator({css: 'a > b'});
|
|
120
|
-
assert.equal('css selector', locator.using);
|
|
121
|
-
assert.equal('a > b', locator.value);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('accepts id', function() {
|
|
125
|
-
let locator = by.checkedLocator({id: 'foobar'});
|
|
126
|
-
assert.equal('css selector', locator.using);
|
|
127
|
-
assert.equal('*[id="foobar"]', locator.value);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('accepts linkText', function() {
|
|
131
|
-
let locator = by.checkedLocator({linkText: 'hello'});
|
|
132
|
-
assert.equal('link text', locator.using);
|
|
133
|
-
assert.equal('hello', locator.value);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('accepts name', function() {
|
|
137
|
-
let locator = by.checkedLocator({name: 'foobar'});
|
|
138
|
-
assert.equal('css selector', locator.using);
|
|
139
|
-
assert.equal('*[name="foobar"]', locator.value);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('accepts partialLinkText', function() {
|
|
143
|
-
let locator = by.checkedLocator({partialLinkText: 'hello'});
|
|
144
|
-
assert.equal('partial link text', locator.using);
|
|
145
|
-
assert.equal('hello', locator.value);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('accepts tagName', function() {
|
|
149
|
-
let locator = by.checkedLocator({tagName: 'div'});
|
|
150
|
-
assert.equal('css selector', locator.using);
|
|
151
|
-
assert.equal('div', locator.value);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('accepts xpath', function() {
|
|
155
|
-
let locator = by.checkedLocator({xpath: '//div[1]'});
|
|
156
|
-
assert.equal('xpath', locator.using);
|
|
157
|
-
assert.equal('//div[1]', locator.value);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|