selenium-webdriver 4.0.0-alpha.3 → 4.0.0-alpha.7
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 +9 -2
- package/README.md +2 -4
- package/chrome.js +19 -527
- package/chromium.js +762 -0
- package/edge.js +97 -58
- package/firefox.js +23 -5
- package/http/index.js +4 -0
- package/io/index.js +1 -1
- package/lib/actions.js +1 -1
- package/lib/atoms/get-attribute.js +1 -2
- package/lib/atoms/is-displayed.js +5 -6
- package/lib/atoms/make-atoms-module.js +17 -0
- package/lib/capabilities.js +17 -4
- package/lib/command.js +1 -0
- package/lib/http.js +8 -3
- package/lib/input.js +6 -6
- package/lib/logging.js +1 -1
- package/lib/webdriver.js +33 -3
- package/net/portprober.js +1 -1
- package/package.json +8 -9
- package/BUILD.bazel +0 -88
- package/example/chrome_android.js +0 -42
- package/example/chrome_mobile_emulation.js +0 -42
- package/example/firefox_channels.js +0 -77
- package/example/google_search.js +0 -50
- package/example/google_search_test.js +0 -72
- package/example/headless.js +0 -55
- package/example/logging.js +0 -68
- package/jasmine.json +0 -11
- package/lib/atoms/BUILD.bazel +0 -28
- 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/testing/index.js +0 -498
- package/tools/init_jasmine.js +0 -7
|
@@ -1,355 +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 {fail} = require('assert');
|
|
22
|
-
|
|
23
|
-
const {Browser, By, WebElement, error} = require('..');
|
|
24
|
-
const {Pages, ignore, suite} = require('../lib/test');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
suite(function(env) {
|
|
28
|
-
var driver;
|
|
29
|
-
|
|
30
|
-
before(async function() {
|
|
31
|
-
driver = await env.builder().build();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
after(function() {
|
|
35
|
-
return driver.quit();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
beforeEach(function() {
|
|
39
|
-
return driver.get(Pages.echoPage);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('executeScript;', function() {
|
|
43
|
-
var shouldHaveFailed = new Error('Should have failed');
|
|
44
|
-
|
|
45
|
-
it('fails if script throws', function() {
|
|
46
|
-
return execute('throw new Error("boom")')
|
|
47
|
-
.then(function() { throw shouldHaveFailed; })
|
|
48
|
-
.catch(function(e) {
|
|
49
|
-
// The java WebDriver server adds a bunch of crap to error messages.
|
|
50
|
-
// Error message will just be "JavaScript error" for IE.
|
|
51
|
-
assert.ok(
|
|
52
|
-
/.*(JavaScript error|boom).*/.test(e.message),
|
|
53
|
-
`Unexpected error: ${e.message}`);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('fails if script does not parse', function() {
|
|
58
|
-
return execute('throw function\\*')
|
|
59
|
-
.then(function() { throw shouldHaveFailed; })
|
|
60
|
-
.catch(function(e) {
|
|
61
|
-
assert.notEqual(e, shouldHaveFailed);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('scripts;', function() {
|
|
66
|
-
it('do not pollute the global scope', async function() {
|
|
67
|
-
await execute('var x = 1;');
|
|
68
|
-
assert.equal(await execute('return typeof x;'), 'undefined');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('can set global variables', async function() {
|
|
72
|
-
await execute('window.x = 1234;');
|
|
73
|
-
assert.equal(await execute('return x;'), 1234);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('may be defined as a function expression', async function() {
|
|
77
|
-
let result = await execute(function() {
|
|
78
|
-
return 1234 + 'abc';
|
|
79
|
-
});
|
|
80
|
-
assert.equal(result, '1234abc');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('return values;', function() {
|
|
85
|
-
|
|
86
|
-
it('returns undefined as null', async function() {
|
|
87
|
-
assert.strictEqual(await execute('var x; return x;'), null);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('can return null', async function() {
|
|
91
|
-
assert.strictEqual(await execute('return null;'), null);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('can return numbers', async function() {
|
|
95
|
-
assert.equal(await execute('return 1234'), 1234);
|
|
96
|
-
assert.equal(await execute('return 3.1456'), 3.1456);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('can return strings', async function() {
|
|
100
|
-
assert.equal(await execute('return "hello"'), 'hello');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('can return booleans', async function() {
|
|
104
|
-
assert.equal(await execute('return true'), true);
|
|
105
|
-
assert.equal(await execute('return false'), false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('can return an array of primitives', function() {
|
|
109
|
-
return execute('var x; return [1, false, null, 3.14, x]')
|
|
110
|
-
.then(verifyJson([1, false, null, 3.14, null]));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('can return nested arrays', function() {
|
|
114
|
-
return execute('return [[1, 2, [3]]]').then(verifyJson([[1, 2, [3]]]));
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
ignore(env.browsers(Browser.IE)).
|
|
118
|
-
it('can return empty object literal', function() {
|
|
119
|
-
return execute('return {}').then(verifyJson({}));
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('can return object literals', function() {
|
|
123
|
-
return execute('return {a: 1, b: false, c: null}').then(result => {
|
|
124
|
-
verifyJson(['a', 'b', 'c'])(Object.keys(result).sort());
|
|
125
|
-
assert.equal(result.a, 1);
|
|
126
|
-
assert.equal(result.b, false);
|
|
127
|
-
assert.strictEqual(result.c, null);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('can return complex object literals', function() {
|
|
132
|
-
return execute('return {a:{b: "hello"}}')
|
|
133
|
-
.then(verifyJson({a:{b: 'hello'}}));
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('can return dom elements as web elements', async function() {
|
|
137
|
-
let result =
|
|
138
|
-
await execute('return document.querySelector(".header.host")');
|
|
139
|
-
assert.ok(result instanceof WebElement);
|
|
140
|
-
|
|
141
|
-
let text = await result.getText();
|
|
142
|
-
assert.ok(text.startsWith('host: '), `got: ${text}`);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('can return array of dom elements', async function() {
|
|
146
|
-
let result = await execute(
|
|
147
|
-
'var nodes = document.querySelectorAll(".request,.host");' +
|
|
148
|
-
'return [nodes[0], nodes[1]];');
|
|
149
|
-
assert.equal(result.length, 2);
|
|
150
|
-
|
|
151
|
-
assert.ok(result[0] instanceof WebElement);
|
|
152
|
-
assert.ok((await result[0].getText()).startsWith('GET '));;
|
|
153
|
-
|
|
154
|
-
assert.ok(result[1] instanceof WebElement);
|
|
155
|
-
assert.ok((await result[1].getText()).startsWith('host: '));;
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('can return a NodeList as an array of web elements', async function() {
|
|
159
|
-
let result =
|
|
160
|
-
await execute('return document.querySelectorAll(".request,.host");')
|
|
161
|
-
|
|
162
|
-
assert.equal(result.length, 2);
|
|
163
|
-
|
|
164
|
-
assert.ok(result[0] instanceof WebElement);
|
|
165
|
-
assert.ok((await result[0].getText()).startsWith('GET '));;
|
|
166
|
-
|
|
167
|
-
assert.ok(result[1] instanceof WebElement);
|
|
168
|
-
assert.ok((await result[1].getText()).startsWith('host: '));;
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('can return object literal with element property', async function() {
|
|
172
|
-
let result = await execute('return {a: document.body}');
|
|
173
|
-
|
|
174
|
-
assert.ok(result.a instanceof WebElement);
|
|
175
|
-
assert.equal((await result.a.getTagName()).toLowerCase(), 'body');
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('parameters;', function() {
|
|
180
|
-
it('can pass numeric arguments', async function() {
|
|
181
|
-
assert.equal(await execute('return arguments[0]', 12), 12);
|
|
182
|
-
assert.equal(await execute('return arguments[0]', 3.14), 3.14);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('can pass boolean arguments', async function() {
|
|
186
|
-
assert.equal(await execute('return arguments[0]', true), true);
|
|
187
|
-
assert.equal(await execute('return arguments[0]', false), false);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('can pass string arguments', async function() {
|
|
191
|
-
assert.equal(await execute('return arguments[0]', 'hi'), 'hi');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('can pass null arguments', async function() {
|
|
195
|
-
assert.equal(await execute('return arguments[0] === null', null), true);
|
|
196
|
-
assert.equal(await execute('return arguments[0]', null), null);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('passes undefined as a null argument', async function() {
|
|
200
|
-
var x;
|
|
201
|
-
assert.equal(await execute('return arguments[0] === null', x), true);
|
|
202
|
-
assert.equal(await execute('return arguments[0]', x), null);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('can pass multiple arguments', async function() {
|
|
206
|
-
assert.equal(await execute('return arguments.length'), 0);
|
|
207
|
-
assert.equal(await execute('return arguments.length', 1, 'a', false), 3);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
ignore(env.browsers(Browser.FIREFOX, Browser.SAFARI)).
|
|
211
|
-
it('can return arguments object as array', async function() {
|
|
212
|
-
let val = await execute('return arguments', 1, 'a', false);
|
|
213
|
-
|
|
214
|
-
assert.equal(val.length, 3);
|
|
215
|
-
assert.equal(val[0], 1);
|
|
216
|
-
assert.equal(val[1], 'a');
|
|
217
|
-
assert.equal(val[2], false);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('can pass object literal', async function() {
|
|
221
|
-
let result = await execute(
|
|
222
|
-
'return [typeof arguments[0], arguments[0].a]', {a: 'hello'})
|
|
223
|
-
assert.equal(result[0], 'object');
|
|
224
|
-
assert.equal(result[1], 'hello');
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('WebElement arguments are passed as DOM elements', async function() {
|
|
228
|
-
let el = await driver.findElement(By.tagName('div'));
|
|
229
|
-
let result =
|
|
230
|
-
await execute('return arguments[0].tagName.toLowerCase();', el);
|
|
231
|
-
assert.equal(result, 'div');
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('can pass array containing object literals', async function() {
|
|
235
|
-
let result = await execute('return arguments[0]', [{color: "red"}]);
|
|
236
|
-
assert.equal(result.length, 1);
|
|
237
|
-
assert.equal(result[0].color, 'red');
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('does not modify object literal parameters', function() {
|
|
241
|
-
var input = {color: 'red'};
|
|
242
|
-
return execute('return arguments[0];', input).then(verifyJson(input));
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// See https://code.google.com/p/selenium/issues/detail?id=8223.
|
|
247
|
-
describe('issue 8223;', function() {
|
|
248
|
-
describe('using for..in loops;', function() {
|
|
249
|
-
it('can return array built from for-loop index', function() {
|
|
250
|
-
return execute(function() {
|
|
251
|
-
var ret = [];
|
|
252
|
-
for (var i = 0; i < 3; i++) {
|
|
253
|
-
ret.push(i);
|
|
254
|
-
}
|
|
255
|
-
return ret;
|
|
256
|
-
}).then(verifyJson[0, 1, 2]);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('can copy input array contents', function() {
|
|
260
|
-
return execute(function(input) {
|
|
261
|
-
var ret = [];
|
|
262
|
-
for (var i in input) {
|
|
263
|
-
ret.push(input[i]);
|
|
264
|
-
}
|
|
265
|
-
return ret;
|
|
266
|
-
}, ['fa', 'fe', 'fi']).then(verifyJson(['fa', 'fe', 'fi']));
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('can iterate over input object keys', function() {
|
|
270
|
-
return execute(function(thing) {
|
|
271
|
-
var ret = [];
|
|
272
|
-
for (var w in thing.words) {
|
|
273
|
-
ret.push(thing.words[w].word);
|
|
274
|
-
}
|
|
275
|
-
return ret;
|
|
276
|
-
}, {words: [{word: 'fa'}, {word: 'fe'}, {word: 'fi'}]})
|
|
277
|
-
.then(verifyJson(['fa', 'fe', 'fi']));
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
describe('recursive functions;', function() {
|
|
281
|
-
it('can build array from input', function() {
|
|
282
|
-
var input = ['fa', 'fe', 'fi'];
|
|
283
|
-
return execute(function(thearray) {
|
|
284
|
-
var ret = [];
|
|
285
|
-
function build_response(thearray, ret) {
|
|
286
|
-
ret.push(thearray.shift());
|
|
287
|
-
return (!thearray.length && ret
|
|
288
|
-
|| build_response(thearray, ret));
|
|
289
|
-
}
|
|
290
|
-
return build_response(thearray, ret);
|
|
291
|
-
}, input).then(verifyJson(input));
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('can build array from elements in object', function() {
|
|
295
|
-
var input = {words: [{word: 'fa'}, {word: 'fe'}, {word: 'fi'}]};
|
|
296
|
-
return execute(function(thing) {
|
|
297
|
-
var ret = [];
|
|
298
|
-
function build_response(thing, ret) {
|
|
299
|
-
var item = thing.words.shift();
|
|
300
|
-
ret.push(item.word);
|
|
301
|
-
return (!thing.words.length && ret
|
|
302
|
-
|| build_response(thing, ret));
|
|
303
|
-
}
|
|
304
|
-
return build_response(thing, ret);
|
|
305
|
-
}, input).then(verifyJson(['fa', 'fe', 'fi']));
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
describe('async timeouts', function() {
|
|
312
|
-
var TIMEOUT_IN_MS = 200;
|
|
313
|
-
var ACCEPTABLE_WAIT = TIMEOUT_IN_MS / 10;
|
|
314
|
-
var TOO_LONG_WAIT = TIMEOUT_IN_MS * 10;
|
|
315
|
-
|
|
316
|
-
before(function() {
|
|
317
|
-
return driver.manage().setTimeouts({script: TIMEOUT_IN_MS});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('does not fail if script execute in time', function() {
|
|
321
|
-
return executeTimeOutScript(ACCEPTABLE_WAIT);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it('fails if script took too long', function() {
|
|
325
|
-
return executeTimeOutScript(TOO_LONG_WAIT)
|
|
326
|
-
.then(function() {
|
|
327
|
-
fail('it should have timed out');
|
|
328
|
-
}).catch(function(e) {
|
|
329
|
-
if (env.browser.name === Browser.SAFARI) {
|
|
330
|
-
assert.equal(e.name, error.TimeoutError.name);
|
|
331
|
-
} else {
|
|
332
|
-
assert.equal(e.name, error.ScriptTimeoutError.name);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
function executeTimeOutScript(sleepTime) {
|
|
338
|
-
return driver.executeAsyncScript(function(sleepTime) {
|
|
339
|
-
var callback = arguments[arguments.length - 1];
|
|
340
|
-
setTimeout(callback, sleepTime)
|
|
341
|
-
}, sleepTime);
|
|
342
|
-
}
|
|
343
|
-
})
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
function verifyJson(expected) {
|
|
347
|
-
return function(actual) {
|
|
348
|
-
assert.equal(JSON.stringify(actual), JSON.stringify(expected));
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function execute() {
|
|
353
|
-
return driver.executeScript.apply(driver, arguments);
|
|
354
|
-
}
|
|
355
|
-
});
|
package/test/fingerprint_test.js
DELETED
|
@@ -1,63 +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
|
-
|
|
22
|
-
const test = require('../lib/test');
|
|
23
|
-
const Pages = test.Pages;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
test.suite(function(env) {
|
|
27
|
-
var browsers = env.browsers;
|
|
28
|
-
|
|
29
|
-
var driver;
|
|
30
|
-
test.before(function() {
|
|
31
|
-
driver = env.builder().build();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test.after(function() {
|
|
35
|
-
driver.quit();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('fingerprinting', function() {
|
|
39
|
-
test.it('it should fingerprint the navigator object', async function() {
|
|
40
|
-
await driver.get(Pages.simpleTestPage);
|
|
41
|
-
|
|
42
|
-
let wd = await driver.executeScript('return navigator.webdriver');
|
|
43
|
-
assert.strictEqual(wd, true);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test.it('fingerprint must not be writable', async function() {
|
|
47
|
-
await driver.get(Pages.simpleTestPage);
|
|
48
|
-
|
|
49
|
-
let wd = await driver.executeScript(
|
|
50
|
-
'navigator.webdriver = "ohai"; return navigator.webdriver');
|
|
51
|
-
assert.strictEqual(wd, true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test.it('leaves fingerprint on svg pages', async function() {
|
|
55
|
-
await driver.get(Pages.svgPage);
|
|
56
|
-
|
|
57
|
-
let wd = await driver.executeScript('return navigator.webdriver');
|
|
58
|
-
assert.strictEqual(wd, true);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Currently only implemented in legacy firefox.
|
|
63
|
-
}, {browsers: ['legacy-firefox']});
|
package/test/firefox_test.js
DELETED
|
@@ -1,233 +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 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
|
-
describe('Options', function() {
|
|
51
|
-
let profileWithWebExtension;
|
|
52
|
-
let profileWithUserPrefs;
|
|
53
|
-
|
|
54
|
-
before(async function createProfileWithWebExtension() {
|
|
55
|
-
profileWithWebExtension = await io.tmpDir();
|
|
56
|
-
let extensionsDir = path.join(profileWithWebExtension, 'extensions');
|
|
57
|
-
await io.mkdir(extensionsDir);
|
|
58
|
-
await io.write(
|
|
59
|
-
path.join(extensionsDir, WEBEXTENSION_EXTENSION_ID),
|
|
60
|
-
await io.read(WEBEXTENSION_EXTENSION));
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
before(async function createProfileWithUserPrefs() {
|
|
64
|
-
profileWithUserPrefs = await io.tmpDir();
|
|
65
|
-
await io.write(
|
|
66
|
-
path.join(profileWithUserPrefs, 'user.js'),
|
|
67
|
-
'user_pref("general.useragent.override", "foo;bar");\n');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('setProfile', function() {
|
|
71
|
-
it('use profile with custom prefs', async function() {
|
|
72
|
-
let options = new firefox.Options;
|
|
73
|
-
options.setProfile(profileWithUserPrefs);
|
|
74
|
-
|
|
75
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
76
|
-
|
|
77
|
-
await driver.get(Pages.echoPage);
|
|
78
|
-
await verifyUserAgentWasChanged();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('use profile with extension', async function() {
|
|
82
|
-
let options = new firefox.Options;
|
|
83
|
-
options.setProfile(profileWithWebExtension);
|
|
84
|
-
|
|
85
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
86
|
-
|
|
87
|
-
await driver.get(Pages.echoPage);
|
|
88
|
-
await verifyWebExtensionWasInstalled();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('setPreference', function() {
|
|
93
|
-
it('throws if key is not a string', function() {
|
|
94
|
-
let options = new firefox.Options;
|
|
95
|
-
assert.throws(() => options.setPreference(1, 2), TypeError);
|
|
96
|
-
options.setPreference('1', 2); // OK if no throw.
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('throws if value is an invalid type', function() {
|
|
100
|
-
let options = new firefox.Options;
|
|
101
|
-
options.setPreference('a', 1);
|
|
102
|
-
options.setPreference('b', '2');
|
|
103
|
-
options.setPreference('c', true);
|
|
104
|
-
|
|
105
|
-
assert.throws(() => options.setPreference('d', null), TypeError);
|
|
106
|
-
assert.throws(() => options.setPreference('d', undefined), TypeError);
|
|
107
|
-
assert.throws(() => options.setPreference('d', {}), TypeError);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('can start Firefox with custom preferences', async function() {
|
|
111
|
-
let options = new firefox.Options();
|
|
112
|
-
options.setPreference('general.useragent.override', 'foo;bar');
|
|
113
|
-
|
|
114
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
115
|
-
|
|
116
|
-
await driver.get(Pages.echoPage);
|
|
117
|
-
await verifyUserAgentWasChanged();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('can add extra prefs on top of an existing profile', async function() {
|
|
121
|
-
let options = new firefox.Options()
|
|
122
|
-
.setPreference('general.useragent.override', 'foo;bar')
|
|
123
|
-
.setProfile(profileWithWebExtension);
|
|
124
|
-
|
|
125
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
126
|
-
|
|
127
|
-
await driver.get(Pages.echoPage);
|
|
128
|
-
await verifyWebExtensionWasInstalled();
|
|
129
|
-
await verifyUserAgentWasChanged();
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('addExtensions', function() {
|
|
134
|
-
it('can add extension to brand new profile', async function() {
|
|
135
|
-
let options = new firefox.Options();
|
|
136
|
-
options.addExtensions(WEBEXTENSION_EXTENSION);
|
|
137
|
-
|
|
138
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
139
|
-
|
|
140
|
-
await driver.get(Pages.echoPage);
|
|
141
|
-
await verifyWebExtensionWasInstalled();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('can add extension to custom profile', async function() {
|
|
145
|
-
let options = new firefox.Options()
|
|
146
|
-
.addExtensions(WEBEXTENSION_EXTENSION)
|
|
147
|
-
.setProfile(profileWithUserPrefs);
|
|
148
|
-
|
|
149
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
150
|
-
|
|
151
|
-
await driver.get(Pages.echoPage);
|
|
152
|
-
await verifyWebExtensionWasInstalled();
|
|
153
|
-
await verifyUserAgentWasChanged();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('can addExtensions and setPreference', async function() {
|
|
157
|
-
let options = new firefox.Options()
|
|
158
|
-
.addExtensions(WEBEXTENSION_EXTENSION)
|
|
159
|
-
.setPreference('general.useragent.override', 'foo;bar')
|
|
160
|
-
|
|
161
|
-
driver = env.builder().setFirefoxOptions(options).build();
|
|
162
|
-
|
|
163
|
-
await driver.get(Pages.echoPage);
|
|
164
|
-
await verifyWebExtensionWasInstalled();
|
|
165
|
-
await verifyUserAgentWasChanged();
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('context switching', function() {
|
|
171
|
-
beforeEach(async function() {
|
|
172
|
-
driver = await env.builder().build();
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('can get context', async function() {
|
|
176
|
-
assert.equal(await driver.getContext(), Context.CONTENT);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('can set context', async function() {
|
|
180
|
-
await driver.setContext(Context.CHROME);
|
|
181
|
-
let ctxt = await driver.getContext();
|
|
182
|
-
assert.equal(ctxt, Context.CHROME);
|
|
183
|
-
|
|
184
|
-
await driver.setContext(Context.CONTENT);
|
|
185
|
-
ctxt = await driver.getContext();
|
|
186
|
-
assert.equal(ctxt, Context.CONTENT);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('throws on unknown context', function() {
|
|
190
|
-
return driver.setContext("foo").then(assert.fail, function(e) {
|
|
191
|
-
assert(e instanceof error.InvalidArgumentError);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('addons can be installed and uninstalled at runtime', async function() {
|
|
197
|
-
driver = env.builder().build();
|
|
198
|
-
|
|
199
|
-
await driver.get(Pages.echoPage);
|
|
200
|
-
await verifyWebExtensionNotInstalled();
|
|
201
|
-
|
|
202
|
-
let id = await driver.installAddon(WEBEXTENSION_EXTENSION);
|
|
203
|
-
await driver.sleep(1000); // Give extension time to install (yuck).
|
|
204
|
-
|
|
205
|
-
await driver.get(Pages.echoPage);
|
|
206
|
-
await verifyWebExtensionWasInstalled();
|
|
207
|
-
|
|
208
|
-
await driver.uninstallAddon(id);
|
|
209
|
-
await driver.get(Pages.echoPage);
|
|
210
|
-
await verifyWebExtensionNotInstalled();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
async function verifyUserAgentWasChanged() {
|
|
214
|
-
let userAgent =
|
|
215
|
-
await driver.executeScript('return window.navigator.userAgent');
|
|
216
|
-
assert.equal(userAgent, 'foo;bar');
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async function verifyWebExtensionNotInstalled() {
|
|
220
|
-
let found =
|
|
221
|
-
await driver.findElements({id: 'webextensions-selenium-example'});
|
|
222
|
-
assert.equal(found.length, 0);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async function verifyWebExtensionWasInstalled() {
|
|
226
|
-
let footer =
|
|
227
|
-
await driver.findElement({id: 'webextensions-selenium-example'});
|
|
228
|
-
let text = await footer.getText();
|
|
229
|
-
assert.equal(
|
|
230
|
-
text, 'Content injected by webextensions-selenium-example');
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}, {browsers: [Browser.FIREFOX]});
|
package/test/frame_test.js
DELETED
|
@@ -1,45 +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
|
-
|
|
22
|
-
const test = require('../lib/test');
|
|
23
|
-
const {Browser, By} = require('..');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
test.suite(function(env) {
|
|
27
|
-
var driver;
|
|
28
|
-
|
|
29
|
-
before(async function() { driver = await env.builder().build(); });
|
|
30
|
-
after(function() { return driver.quit(); });
|
|
31
|
-
|
|
32
|
-
beforeEach(function() {
|
|
33
|
-
return driver.switchTo().defaultContent();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('can switch to a frame and back to the parent frame', async function() {
|
|
37
|
-
await driver.get(test.Pages.iframePage);
|
|
38
|
-
|
|
39
|
-
let frame = await driver.findElement(By.name('iframe1-name'));
|
|
40
|
-
await driver.switchTo().frame(frame);
|
|
41
|
-
assert.equal(await driver.executeScript('return document.title'), 'We Leave From Here');
|
|
42
|
-
await driver.switchTo().parentFrame();
|
|
43
|
-
assert.equal(await driver.executeScript('return document.title'), 'This page has iframes');
|
|
44
|
-
});
|
|
45
|
-
});
|