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
package/test/rect_test.js
DELETED
|
@@ -1,51 +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 {By} = require('..');
|
|
23
|
-
const test = require('../lib/test');
|
|
24
|
-
|
|
25
|
-
test.suite(function(env) {
|
|
26
|
-
describe('WebElement', function() {
|
|
27
|
-
let driver;
|
|
28
|
-
|
|
29
|
-
before(async function() {
|
|
30
|
-
driver = await env.builder().build();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
after(function() {
|
|
34
|
-
return driver.quit();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('getRect()', async function() {
|
|
38
|
-
const html =
|
|
39
|
-
'<!DOCTYPE html><style>'
|
|
40
|
-
+ '*{padding:0; margin:0}'
|
|
41
|
-
+ 'div{position: absolute; top: 50px; left: 40px;'
|
|
42
|
-
+ 'height: 25px;width:35px;background: green;}'
|
|
43
|
-
+ '</style><div>Hello</div>';
|
|
44
|
-
|
|
45
|
-
await driver.get(test.Pages.echoPage + `?html=${encodeURIComponent(html)}`);
|
|
46
|
-
const el = await driver.findElement(By.css('div'));
|
|
47
|
-
const rect = await el.getRect();
|
|
48
|
-
assert.deepEqual(rect, {width: 35, height: 25, x: 40, y: 50});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
package/test/remote_test.js
DELETED
|
@@ -1,98 +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 cmd = require('../lib/command');
|
|
26
|
-
const remote = require('../remote');
|
|
27
|
-
const {CancellationError} = require('../http/util');
|
|
28
|
-
|
|
29
|
-
describe('DriverService', function() {
|
|
30
|
-
describe('start()', function() {
|
|
31
|
-
var service;
|
|
32
|
-
|
|
33
|
-
beforeEach(function() {
|
|
34
|
-
service = new remote.DriverService(process.execPath, {
|
|
35
|
-
port: 1234,
|
|
36
|
-
args: ['-e', 'process.exit(1)']
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
afterEach(function() {
|
|
41
|
-
return service.kill();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('fails if child-process dies', function() {
|
|
45
|
-
return service.start(500).then(expectFailure, verifyFailure);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
function verifyFailure(e) {
|
|
49
|
-
assert.ok(!(e instanceof CancellationError));
|
|
50
|
-
assert.equal('Server terminated early with status 1', e.message);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function expectFailure() {
|
|
54
|
-
throw Error('expected to fail');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('FileDetector', function() {
|
|
60
|
-
class ExplodingDriver {
|
|
61
|
-
execute() {
|
|
62
|
-
throw Error('unexpected call');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
it('returns the original path if the file does not exist', function() {
|
|
67
|
-
return io.tmpDir().then(dir => {
|
|
68
|
-
let theFile = path.join(dir, 'not-there');
|
|
69
|
-
return (new remote.FileDetector)
|
|
70
|
-
.handleFile(new ExplodingDriver, theFile)
|
|
71
|
-
.then(f => assert.equal(f, theFile));
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('returns the original path if it is a directory', function() {
|
|
76
|
-
return io.tmpDir().then(dir => {
|
|
77
|
-
return (new remote.FileDetector)
|
|
78
|
-
.handleFile(new ExplodingDriver, dir)
|
|
79
|
-
.then(f => assert.equal(f, dir));
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('attempts to upload valid files', function() {
|
|
84
|
-
return io.tmpFile().then(theFile => {
|
|
85
|
-
return (new remote.FileDetector)
|
|
86
|
-
.handleFile(
|
|
87
|
-
new (class FakeDriver {
|
|
88
|
-
execute(command) {
|
|
89
|
-
assert.equal(command.getName(), cmd.Name.UPLOAD_FILE);
|
|
90
|
-
assert.equal(typeof command.getParameters()['file'], 'string');
|
|
91
|
-
return Promise.resolve('success!');
|
|
92
|
-
}
|
|
93
|
-
}),
|
|
94
|
-
theFile)
|
|
95
|
-
.then(f => assert.equal(f, 'success!'));
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
package/test/safari_test.js
DELETED
|
@@ -1,44 +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 safari = require('../safari');
|
|
23
|
-
const test = require('../lib/test');
|
|
24
|
-
const webdriver = require('..');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
test.suite(function(env) {
|
|
28
|
-
describe('safaridriver', function() {
|
|
29
|
-
let service;
|
|
30
|
-
|
|
31
|
-
afterEach(function() {
|
|
32
|
-
if (service) {
|
|
33
|
-
return service.kill();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('can start safaridriver', async function() {
|
|
38
|
-
service = new safari.ServiceBuilder().build();
|
|
39
|
-
|
|
40
|
-
let url = await service.start();
|
|
41
|
-
assert(/127\.0\.0\.1/.test(url), `unexpected url: ${url}`);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}, {browsers: ['safari']});
|
|
@@ -1,60 +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 test = require('../lib/test');
|
|
24
|
-
const {Browser, By, error, until} = require('..');
|
|
25
|
-
const Pages = test.Pages;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
test.suite(function(env) {
|
|
29
|
-
var driver;
|
|
30
|
-
before(async function() { driver = await env.builder().build(); });
|
|
31
|
-
after(function() { return driver.quit(); });
|
|
32
|
-
|
|
33
|
-
// Element never goes stale in Safari.
|
|
34
|
-
test.ignore(env.browsers(Browser.SAFARI)).
|
|
35
|
-
it(
|
|
36
|
-
'dynamically removing elements from the DOM trigger a ' +
|
|
37
|
-
'StaleElementReferenceError',
|
|
38
|
-
async function() {
|
|
39
|
-
await driver.get(Pages.javascriptPage);
|
|
40
|
-
|
|
41
|
-
var toBeDeleted = await driver.findElement(By.id('deleted'));
|
|
42
|
-
assert.equal(await toBeDeleted.getTagName(), 'p');
|
|
43
|
-
|
|
44
|
-
await driver.findElement(By.id('delete')).click();
|
|
45
|
-
await driver.wait(until.stalenessOf(toBeDeleted), 5000);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('an element found in a different frame is stale', async function() {
|
|
49
|
-
await driver.get(Pages.missedJsReferencePage);
|
|
50
|
-
|
|
51
|
-
var frame = await driver.findElement(By.css('iframe[name="inner"]'));
|
|
52
|
-
await driver.switchTo().frame(frame);
|
|
53
|
-
|
|
54
|
-
var el = await driver.findElement(By.id('oneline'));
|
|
55
|
-
await driver.switchTo().defaultContent();
|
|
56
|
-
return el.getText().then(fail, function(e) {
|
|
57
|
-
assert.ok(e instanceof error.StaleElementReferenceError);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
package/test/upload_test.js
DELETED
|
@@ -1,78 +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
|
-
|
|
23
|
-
const io = require('../io');
|
|
24
|
-
const remote = require('../remote');
|
|
25
|
-
const test = require('../lib/test');
|
|
26
|
-
const {Browser, By, until} = require('..');
|
|
27
|
-
|
|
28
|
-
const Pages = test.Pages;
|
|
29
|
-
|
|
30
|
-
test.suite(function(env) {
|
|
31
|
-
var LOREM_IPSUM_TEXT = 'lorem ipsum dolor sit amet';
|
|
32
|
-
var FILE_HTML = '<!DOCTYPE html><div>' + LOREM_IPSUM_TEXT + '</div>';
|
|
33
|
-
|
|
34
|
-
var fp;
|
|
35
|
-
before(function() {
|
|
36
|
-
return fp = io.tmpFile().then(function(fp) {
|
|
37
|
-
fs.writeFileSync(fp, FILE_HTML);
|
|
38
|
-
return fp;
|
|
39
|
-
});
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
var driver;
|
|
43
|
-
before(async function() {
|
|
44
|
-
driver = await env.builder().build();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
after(function() {
|
|
48
|
-
if (driver) {
|
|
49
|
-
return driver.quit();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test.ignore(env.browsers(Browser.SAFARI)).
|
|
54
|
-
it('can upload files', async function() {
|
|
55
|
-
driver.setFileDetector(new remote.FileDetector);
|
|
56
|
-
|
|
57
|
-
await driver.get(Pages.uploadPage);
|
|
58
|
-
|
|
59
|
-
var fp = await io.tmpFile().then(function(fp) {
|
|
60
|
-
fs.writeFileSync(fp, FILE_HTML);
|
|
61
|
-
return fp;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
await driver.findElement(By.id('upload')).sendKeys(fp);
|
|
65
|
-
await driver.findElement(By.id('go')).click();
|
|
66
|
-
|
|
67
|
-
// Uploading files across a network may take a while, even if they're small.
|
|
68
|
-
var label = await driver.findElement(By.id('upload_label'));
|
|
69
|
-
await driver.wait(until.elementIsNotVisible(label),
|
|
70
|
-
10 * 1000, 'File took longer than 10 seconds to upload!');
|
|
71
|
-
|
|
72
|
-
var frame = await driver.findElement(By.id('upload_target'));
|
|
73
|
-
await driver.switchTo().frame(frame);
|
|
74
|
-
assert.equal(
|
|
75
|
-
await driver.findElement(By.css('body')).getText(),
|
|
76
|
-
LOREM_IPSUM_TEXT);
|
|
77
|
-
});
|
|
78
|
-
});
|
package/test/window_test.js
DELETED
|
@@ -1,168 +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
|
-
const {UnknownCommandError} = require('../lib/error');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
test.suite(function(env) {
|
|
28
|
-
var driver;
|
|
29
|
-
|
|
30
|
-
before(async function() { driver = await env.builder().build(); });
|
|
31
|
-
after(function() { return driver.quit(); });
|
|
32
|
-
|
|
33
|
-
beforeEach(function() {
|
|
34
|
-
return driver.switchTo().defaultContent();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('can set size of the current window', async function() {
|
|
38
|
-
await driver.get(test.Pages.echoPage);
|
|
39
|
-
await changeSizeBy(-20, -20);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('can set size of the current window from frame', async function() {
|
|
43
|
-
await driver.get(test.Pages.framesetPage);
|
|
44
|
-
|
|
45
|
-
var frame = await driver.findElement({css: 'frame[name="fourth"]'});
|
|
46
|
-
await driver.switchTo().frame(frame);
|
|
47
|
-
await changeSizeBy(-20, -20);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('can set size of the current window from iframe', async function() {
|
|
51
|
-
await driver.get(test.Pages.iframePage);
|
|
52
|
-
|
|
53
|
-
var frame = await driver.findElement({css: 'iframe[name="iframe1-name"]'});
|
|
54
|
-
await driver.switchTo().frame(frame);
|
|
55
|
-
await changeSizeBy(-20, -20);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('can switch to a new window', async function() {
|
|
59
|
-
await driver.get(test.Pages.xhtmlTestPage);
|
|
60
|
-
|
|
61
|
-
let handle = await driver.getWindowHandle();
|
|
62
|
-
let originalHandles = await driver.getAllWindowHandles();
|
|
63
|
-
|
|
64
|
-
await driver.findElement(By.linkText("Open new window")).click();
|
|
65
|
-
await driver.wait(forNewWindowToBeOpened(originalHandles), 2000);
|
|
66
|
-
assert.equal(await driver.getTitle(), "XHTML Test Page");
|
|
67
|
-
|
|
68
|
-
let newHandle = await getNewWindowHandle(originalHandles);
|
|
69
|
-
|
|
70
|
-
await driver.switchTo().window(newHandle);
|
|
71
|
-
assert.equal(await driver.getTitle(), "We Arrive Here");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('can set the window position of the current window', async function() {
|
|
75
|
-
let {x, y} = await driver.manage().window().getRect();
|
|
76
|
-
let newX = x + 10;
|
|
77
|
-
let newY = y + 10;
|
|
78
|
-
|
|
79
|
-
await driver.manage().window().setRect({
|
|
80
|
-
x: newX,
|
|
81
|
-
y: newY,
|
|
82
|
-
width: 640,
|
|
83
|
-
height: 480
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return driver.wait(forPositionToBe(newX, newY), 1000);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('can set the window position from a frame', async function() {
|
|
90
|
-
await driver.get(test.Pages.iframePage);
|
|
91
|
-
|
|
92
|
-
let frame = await driver.findElement(By.name('iframe1-name'));
|
|
93
|
-
await driver.switchTo().frame(frame);
|
|
94
|
-
|
|
95
|
-
let {x, y} = await driver.manage().window().getRect();
|
|
96
|
-
x += 10;
|
|
97
|
-
y += 10;
|
|
98
|
-
|
|
99
|
-
await driver.manage().window().setRect({width: 640, height: 480, x, y});
|
|
100
|
-
return driver.wait(forPositionToBe(x, y), 1000);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('can open a new window', async function() {
|
|
104
|
-
let originalHandles = await driver.getAllWindowHandles()
|
|
105
|
-
let originalHandle = await driver.getWindowHandle()
|
|
106
|
-
|
|
107
|
-
let newHandle;
|
|
108
|
-
try {
|
|
109
|
-
newHandle = await driver.switchTo().newWindow();
|
|
110
|
-
} catch (ex) {
|
|
111
|
-
if (ex instanceof UnknownCommandError) {
|
|
112
|
-
console.warn(
|
|
113
|
-
Error(`${env.browser.name}: aborting test due to unsupported command: ${ex}`).stack);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
assert.equal((await driver.getAllWindowHandles()).length, originalHandles.length + 1);
|
|
119
|
-
assert.notEqual(originalHandle, newHandle);
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
async function changeSizeBy(dx, dy) {
|
|
123
|
-
let {width, height} = await driver.manage().window().getRect();
|
|
124
|
-
width += dx;
|
|
125
|
-
height += dy;
|
|
126
|
-
|
|
127
|
-
let rect = await driver.manage().window().setRect({width, height});
|
|
128
|
-
if (rect.width === width && rect.height === height) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
return driver.wait(forSizeToBe(width, height), 1000);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function forSizeToBe(w, h) {
|
|
135
|
-
return async function() {
|
|
136
|
-
let {width, height} = await driver.manage().window().getRect();
|
|
137
|
-
return width === w && height === h;
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function forPositionToBe(x, y) {
|
|
142
|
-
return async function() {
|
|
143
|
-
let position = await driver.manage().window().getRect();
|
|
144
|
-
return position.x === x &&
|
|
145
|
-
// On OSX, the window height may be bumped down 22px for the top
|
|
146
|
-
// status bar.
|
|
147
|
-
// On Linux, Opera's window position will be off by 28px.
|
|
148
|
-
(position.y >= y && position.y <= (y + 28));
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function forNewWindowToBeOpened(originalHandles) {
|
|
153
|
-
return function() {
|
|
154
|
-
return driver.getAllWindowHandles().then(function(currentHandles) {
|
|
155
|
-
return currentHandles.length > originalHandles.length;
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getNewWindowHandle(originalHandles) {
|
|
161
|
-
// Note: this assumes there's just one new window.
|
|
162
|
-
return driver.getAllWindowHandles().then(function(currentHandles) {
|
|
163
|
-
return currentHandles.filter(function(i) {
|
|
164
|
-
return originalHandles.indexOf(i) < 0;
|
|
165
|
-
})[0];
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
});
|