selenium-webdriver 3.4.0 → 3.5.0
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 +29 -1
- package/NOTICE +1 -1
- package/README.md +1 -4
- package/chrome.js +78 -36
- package/edge.js +2 -2
- package/example/chrome_headless.js +47 -0
- package/example/chrome_mobile_emulation.js +1 -1
- package/firefox/extension.js +118 -81
- package/firefox/index.js +10 -106
- package/firefox/profile.js +13 -49
- package/ie.js +2 -2
- package/index.js +4 -1
- package/io/index.js +59 -0
- package/io/zip.js +214 -0
- package/lib/atoms/getAttribute.js +8 -11
- package/lib/atoms/is-displayed.js +73 -78
- package/lib/capabilities.js +1 -1
- package/lib/error.js +13 -1
- package/lib/http.js +1 -1
- package/lib/test/data/firefox/webextension.xpi +0 -0
- package/lib/test/data/key_logger.html +34 -0
- package/lib/test/data/single_text_input.html +12 -0
- package/lib/test/index.js +1 -34
- package/lib/webdriver.js +3 -12
- package/opera.js +1 -1
- package/package.json +2 -2
- package/phantomjs.js +2 -2
- package/remote/index.js +11 -10
- package/safari.js +2 -2
- package/test/firefox/extension_test.js +41 -17
- package/test/firefox/firefox_test.js +44 -9
- package/test/firefox/profile_test.js +14 -59
- package/test/http/http_test.js +18 -0
- package/test/{io_test.js → io/io_test.js} +40 -1
- package/test/io/zip_test.js +128 -0
- package/test/lib/error_test.js +20 -1
- package/test/lib/webdriver_test.js +5 -3
- package/test/page_loading_test.js +0 -6
- package/test/remote_test.js +3 -3
- package/test/session_test.js +68 -23
- package/lib/firefox/webdriver.xpi +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
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 SAMPLE_XPI_PATH =
|
|
31
|
+
path.join(__dirname, '../../lib/test/data/firefox/sample.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(SAMPLE_XPI_PATH, dir))
|
|
38
|
+
.then(dir => {
|
|
39
|
+
assertExists(path.join(dir, 'chrome.manifest'));
|
|
40
|
+
assertExists(path.join(dir, 'content/overlay.js'));
|
|
41
|
+
assertExists(path.join(dir, 'content/overlay.xul'));
|
|
42
|
+
assertExists(path.join(dir, 'install.rdf'));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('Zip', function() {
|
|
48
|
+
let dir;
|
|
49
|
+
|
|
50
|
+
beforeEach(function() {
|
|
51
|
+
return io.tmpDir().then(d => dir = d);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('can convert an archive to a buffer', function() {
|
|
55
|
+
let z = new zip.Zip;
|
|
56
|
+
return io.mkdirp(path.join(dir, 'a/b/c/d/e')).then(() => {
|
|
57
|
+
return Promise.all([
|
|
58
|
+
io.write(path.join(dir, 'foo'), 'a file'),
|
|
59
|
+
io.write(path.join(dir, 'a/b/c/carrot'), 'an orange carrot'),
|
|
60
|
+
io.write(path.join(dir, 'a/b/c/d/e/elephant'), 'e is for elephant')
|
|
61
|
+
]);
|
|
62
|
+
})
|
|
63
|
+
.then(() => z.addDir(dir))
|
|
64
|
+
.then(() => Promise.all([io.tmpDir(), z.toBuffer()]))
|
|
65
|
+
.then(([outDir, buf]) => {
|
|
66
|
+
let output = path.join(outDir, 'out.zip');
|
|
67
|
+
return io.write(output, buf)
|
|
68
|
+
.then(() => io.tmpDir())
|
|
69
|
+
.then(d => zip.unzip(output, d))
|
|
70
|
+
.then(d => {
|
|
71
|
+
assertContents(path.join(d, 'foo'), 'a file');
|
|
72
|
+
assertContents(path.join(d, 'a/b/c/carrot'), 'an orange carrot');
|
|
73
|
+
assertContents(
|
|
74
|
+
path.join(d, 'a/b/c/d/e/elephant'),
|
|
75
|
+
'e is for elephant');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('getFile', function() {
|
|
81
|
+
it('returns archive file contents as a buffer', function() {
|
|
82
|
+
let foo = path.join(dir, 'foo');
|
|
83
|
+
fs.writeFileSync(foo, 'hello, world!');
|
|
84
|
+
|
|
85
|
+
let z = new zip.Zip;
|
|
86
|
+
return z.addFile(foo).then(() => {
|
|
87
|
+
assert.ok(z.has('foo'));
|
|
88
|
+
return z.getFile('foo');
|
|
89
|
+
}).then(
|
|
90
|
+
buffer => assert.equal(buffer.toString('utf8'), 'hello, world!'));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('returns an error if file is not in archive', function() {
|
|
94
|
+
let z = new zip.Zip;
|
|
95
|
+
assert.ok(!z.has('some-file'));
|
|
96
|
+
return z.getFile('some-file')
|
|
97
|
+
.then(() => assert.fail('should have failed'),
|
|
98
|
+
e => assert.strictEqual(e.constructor, InvalidArgumentError));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it(
|
|
102
|
+
'returns a rejected promise if the requested path is a directory',
|
|
103
|
+
function() {
|
|
104
|
+
let file = path.join(dir, 'aFile');
|
|
105
|
+
fs.writeFileSync(file, 'hello, world!');
|
|
106
|
+
|
|
107
|
+
let z = new zip.Zip;
|
|
108
|
+
return z.addDir(dir, 'foo')
|
|
109
|
+
.then(() => z.getFile('foo'))
|
|
110
|
+
.then(
|
|
111
|
+
() => assert.fail('should have failed'),
|
|
112
|
+
e => assert.strictEqual(
|
|
113
|
+
e.constructor, InvalidArgumentError))
|
|
114
|
+
.then(() => z.getFile('foo/aFile'))
|
|
115
|
+
.then(b => assert.equal(b.toString('utf8'), 'hello, world!'));
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
function assertExists(p) {
|
|
121
|
+
assert.ok(fs.existsSync(p), `expected ${p} to exist`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function assertContents(p, c) {
|
|
125
|
+
assert.strictEqual(
|
|
126
|
+
fs.readFileSync(p, 'utf8'), c, `unexpected file contents for ${p}`);
|
|
127
|
+
}
|
|
128
|
+
});
|
package/test/lib/error_test.js
CHANGED
|
@@ -187,13 +187,32 @@ describe('error', function() {
|
|
|
187
187
|
test('unknown method', error.UnknownMethodError);
|
|
188
188
|
test('unsupported operation', error.UnsupportedOperationError);
|
|
189
189
|
|
|
190
|
+
it('leaves remoteStacktrace empty if not in encoding', function() {
|
|
191
|
+
assert.throws(
|
|
192
|
+
() => error.throwDecodedError({
|
|
193
|
+
error: 'session not created',
|
|
194
|
+
message: 'oops'
|
|
195
|
+
}),
|
|
196
|
+
(e) => {
|
|
197
|
+
assert.strictEqual(e.constructor, error.SessionNotCreatedError);
|
|
198
|
+
assert.strictEqual(e.message, 'oops');
|
|
199
|
+
assert.strictEqual(e.remoteStacktrace, '');
|
|
200
|
+
return true;
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
190
204
|
function test(status, expectedType) {
|
|
191
205
|
it(`"${status}" => ${expectedType.name}`, function() {
|
|
192
206
|
assert.throws(
|
|
193
|
-
() => error.throwDecodedError({
|
|
207
|
+
() => error.throwDecodedError({
|
|
208
|
+
error: status,
|
|
209
|
+
message: 'oops',
|
|
210
|
+
stacktrace: 'some-stacktrace'
|
|
211
|
+
}),
|
|
194
212
|
(e) => {
|
|
195
213
|
assert.strictEqual(e.constructor, expectedType);
|
|
196
214
|
assert.strictEqual(e.message, 'oops');
|
|
215
|
+
assert.strictEqual(e.remoteStacktrace, 'some-stacktrace');
|
|
197
216
|
return true;
|
|
198
217
|
});
|
|
199
218
|
});
|
|
@@ -403,7 +403,7 @@ describe('WebDriver', function() {
|
|
|
403
403
|
|
|
404
404
|
var driver =
|
|
405
405
|
WebDriver.createSession(executor, {'browserName': 'firefox'},
|
|
406
|
-
null,
|
|
406
|
+
null, () => called = true);
|
|
407
407
|
return driver.getSession().then(fail, err => {
|
|
408
408
|
assert.ok(called);
|
|
409
409
|
assertIsStubError(err);
|
|
@@ -464,8 +464,7 @@ describe('WebDriver', function() {
|
|
|
464
464
|
.end();
|
|
465
465
|
|
|
466
466
|
WebDriver.createSession(
|
|
467
|
-
executor, {'browserName': 'firefox'}, null,
|
|
468
|
-
() => {throw e});
|
|
467
|
+
executor, {'browserName': 'firefox'}, null, () => {throw e});
|
|
469
468
|
return waitForAbort().then(err => assert.strictEqual(err, e));
|
|
470
469
|
});
|
|
471
470
|
});
|
|
@@ -1446,6 +1445,7 @@ describe('WebDriver', function() {
|
|
|
1446
1445
|
let executor = new FakeExecutor().
|
|
1447
1446
|
expect(CName.SEND_KEYS_TO_ELEMENT,
|
|
1448
1447
|
{'id': WebElement.buildId('one'),
|
|
1448
|
+
'text': '12abc3',
|
|
1449
1449
|
'value':'12abc3'.split('')}).
|
|
1450
1450
|
andReturnSuccess().
|
|
1451
1451
|
end();
|
|
@@ -1463,6 +1463,7 @@ describe('WebDriver', function() {
|
|
|
1463
1463
|
andReturnSuccess(WebElement.buildId('one')).
|
|
1464
1464
|
expect(CName.SEND_KEYS_TO_ELEMENT,
|
|
1465
1465
|
{'id':WebElement.buildId('one'),
|
|
1466
|
+
'text': 'abc123def',
|
|
1466
1467
|
'value':'abc123def'.split('')}).
|
|
1467
1468
|
andReturnSuccess().
|
|
1468
1469
|
end();
|
|
@@ -1482,6 +1483,7 @@ describe('WebDriver', function() {
|
|
|
1482
1483
|
andReturnSuccess(WebElement.buildId('one')).
|
|
1483
1484
|
expect(CName.SEND_KEYS_TO_ELEMENT,
|
|
1484
1485
|
{'id': WebElement.buildId('one'),
|
|
1486
|
+
'text': 'modified/path',
|
|
1485
1487
|
'value':'modified/path'.split('')}).
|
|
1486
1488
|
andReturnSuccess().
|
|
1487
1489
|
end();
|
|
@@ -57,12 +57,6 @@ test.suite(function(env) {
|
|
|
57
57
|
return assert(driver.getTitle()).equalTo('We Arrive Here');
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
test.ignore(browsers(Browser.SAFARI)).
|
|
61
|
-
it('should follow meta redirects', function*() {
|
|
62
|
-
yield driver.get(Pages.metaRedirectPage);
|
|
63
|
-
return assert(driver.getTitle()).equalTo('We Arrive Here');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
60
|
// Skip Firefox; see https://bugzilla.mozilla.org/show_bug.cgi?id=1280300
|
|
67
61
|
test.ignore(browsers(Browser.FIREFOX)).
|
|
68
62
|
it('should be able to get a fragment on the current page', function*() {
|
package/test/remote_test.js
CHANGED
|
@@ -83,7 +83,7 @@ describe('FileDetector', function() {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
it('returns the original path if the file does not exist', function() {
|
|
86
|
-
return io.tmpDir(dir => {
|
|
86
|
+
return io.tmpDir().then(dir => {
|
|
87
87
|
let theFile = path.join(dir, 'not-there');
|
|
88
88
|
return (new remote.FileDetector)
|
|
89
89
|
.handleFile(new ExplodingDriver, theFile)
|
|
@@ -92,7 +92,7 @@ describe('FileDetector', function() {
|
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it('returns the original path if it is a directory', function() {
|
|
95
|
-
return io.tmpDir(dir => {
|
|
95
|
+
return io.tmpDir().then(dir => {
|
|
96
96
|
return (new remote.FileDetector)
|
|
97
97
|
.handleFile(new ExplodingDriver, dir)
|
|
98
98
|
.then(f => assert.equal(f, dir));
|
|
@@ -100,7 +100,7 @@ describe('FileDetector', function() {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
it('attempts to upload valid files', function() {
|
|
103
|
-
return io.tmpFile(theFile => {
|
|
103
|
+
return io.tmpFile().then(theFile => {
|
|
104
104
|
return (new remote.FileDetector)
|
|
105
105
|
.handleFile(
|
|
106
106
|
new (class FakeDriver {
|
package/test/session_test.js
CHANGED
|
@@ -17,38 +17,83 @@
|
|
|
17
17
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const assert = require('../testing/assert');
|
|
21
|
+
const chrome = require('../chrome');
|
|
22
|
+
const edge = require('../edge');
|
|
23
|
+
const firefox = require('../firefox');
|
|
24
|
+
const ie = require('../ie');
|
|
25
|
+
const opera = require('../opera');
|
|
26
|
+
const phantomjs = require('../phantomjs');
|
|
27
|
+
const safari = require('../safari');
|
|
28
|
+
const test = require('../lib/test');
|
|
29
|
+
const {Browser} = require('../lib/capabilities');
|
|
30
|
+
const {Pages} = require('../lib/test');
|
|
31
|
+
const {WebDriver} = require('..');
|
|
24
32
|
|
|
25
33
|
|
|
26
34
|
test.suite(function(env) {
|
|
27
35
|
var browsers = env.browsers;
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
const BROWSER_MAP = new Map([
|
|
38
|
+
[Browser.CHROME, chrome.Driver],
|
|
39
|
+
[Browser.EDGE, edge.Driver],
|
|
40
|
+
[Browser.FIREFOX, firefox.Driver],
|
|
41
|
+
[Browser.INTERNET_EXPLORER, ie.Driver],
|
|
42
|
+
[Browser.OPERA, opera.Driver],
|
|
43
|
+
[Browser.PHANTOM_JS, phantomjs.Driver],
|
|
44
|
+
[Browser.SAFARI, safari.Driver],
|
|
45
|
+
]);
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
if (BROWSER_MAP.has(env.currentBrowser())) {
|
|
48
|
+
describe('builder creates thenable driver instances', function() {
|
|
49
|
+
let driver;
|
|
50
|
+
|
|
51
|
+
after(() => driver && driver.quit());
|
|
52
|
+
|
|
53
|
+
it(env.currentBrowser(), function() {
|
|
54
|
+
driver = env.builder().build();
|
|
55
|
+
|
|
56
|
+
const want = BROWSER_MAP.get(env.currentBrowser());
|
|
57
|
+
assert(driver).instanceOf(want,
|
|
58
|
+
`want ${want.name}, but got ${driver.name}`);
|
|
59
|
+
assert(typeof driver.then).equalTo('function');
|
|
60
|
+
|
|
61
|
+
return driver
|
|
62
|
+
.then(
|
|
63
|
+
d => assert(d)
|
|
64
|
+
.instanceOf(want, `want ${want.name}, but got ${d.name}`))
|
|
65
|
+
// Load something so the safari driver doesn't crash from starting and
|
|
66
|
+
// stopping in short time.
|
|
67
|
+
.then(() => driver.get(Pages.echoPage));
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe('session management', function() {
|
|
73
|
+
var driver;
|
|
74
|
+
test.before(function*() {
|
|
75
|
+
driver = yield env.builder().build();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test.after(function() {
|
|
79
|
+
return driver.quit();
|
|
80
|
+
});
|
|
37
81
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
82
|
+
test.it('can connect to an existing session', function*() {
|
|
83
|
+
yield driver.get(Pages.simpleTestPage);
|
|
84
|
+
yield assert(driver.getTitle()).equalTo('Hello WebDriver');
|
|
41
85
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
86
|
+
return driver.getSession().then(session1 => {
|
|
87
|
+
let driver2 = WebDriver.attachToSession(
|
|
88
|
+
driver.getExecutor(),
|
|
89
|
+
session1.getId());
|
|
46
90
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
91
|
+
return assert(driver2.getTitle()).equalTo('Hello WebDriver')
|
|
92
|
+
.then(_ => {
|
|
93
|
+
let session2Id = driver2.getSession().then(s => s.getId());
|
|
94
|
+
return assert(session2Id).equalTo(session1.getId());
|
|
95
|
+
});
|
|
96
|
+
});
|
|
52
97
|
});
|
|
53
98
|
});
|
|
54
99
|
});
|
|
Binary file
|