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.
Files changed (95) hide show
  1. package/CHANGES.md +8 -1
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +0 -0
  5. package/chrome.js +0 -0
  6. package/edge.js +0 -0
  7. package/example/chrome_android.js +0 -0
  8. package/example/chrome_mobile_emulation.js +0 -0
  9. package/example/firefox_channels.js +0 -0
  10. package/example/google_search.js +0 -0
  11. package/example/google_search_test.js +0 -0
  12. package/example/headless.js +0 -0
  13. package/example/logging.js +0 -0
  14. package/firefox.js +20 -3
  15. package/http/index.js +0 -0
  16. package/http/util.js +0 -0
  17. package/ie.js +0 -0
  18. package/index.js +0 -0
  19. package/io/exec.js +0 -0
  20. package/io/index.js +0 -0
  21. package/io/zip.js +0 -0
  22. package/lib/actions.js +0 -0
  23. package/lib/by.js +0 -0
  24. package/lib/capabilities.js +0 -0
  25. package/lib/command.js +0 -0
  26. package/lib/error.js +0 -0
  27. package/lib/http.js +0 -0
  28. package/lib/input.js +0 -0
  29. package/lib/logging.js +0 -0
  30. package/lib/promise.js +0 -0
  31. package/lib/proxy.js +0 -0
  32. package/lib/session.js +0 -0
  33. package/lib/symbols.js +0 -0
  34. package/lib/until.js +0 -0
  35. package/lib/webdriver.js +0 -0
  36. package/net/index.js +0 -0
  37. package/net/portprober.js +0 -0
  38. package/package.json +1 -1
  39. package/proxy.js +0 -0
  40. package/remote/index.js +0 -0
  41. package/safari.js +0 -0
  42. package/testing/index.js +0 -0
  43. package/BUILD.bazel +0 -88
  44. package/jasmine.json +0 -11
  45. package/lib/README +0 -5
  46. package/lib/atoms/BUILD.bazel +0 -28
  47. package/lib/atoms/make-atoms-module.js +0 -12
  48. package/lib/test/bootstrap_jasmine.js +0 -28
  49. package/lib/test/build.js +0 -156
  50. package/lib/test/data/actions/click.html +0 -24
  51. package/lib/test/data/actions/drag.html +0 -77
  52. package/lib/test/data/actions/record_click.html +0 -21
  53. package/lib/test/data/chrome/download.html +0 -2
  54. package/lib/test/data/firefox/webextension.xpi +0 -0
  55. package/lib/test/fileserver.js +0 -337
  56. package/lib/test/httpserver.js +0 -120
  57. package/lib/test/index.js +0 -87
  58. package/lib/test/resources.js +0 -40
  59. package/test/actions_test.js +0 -206
  60. package/test/builder_test.js +0 -106
  61. package/test/chrome/devtools_test.js +0 -93
  62. package/test/chrome/options_test.js +0 -121
  63. package/test/chrome/service_test.js +0 -45
  64. package/test/cookie_test.js +0 -210
  65. package/test/element_finding_test.js +0 -431
  66. package/test/execute_script_test.js +0 -355
  67. package/test/fingerprint_test.js +0 -63
  68. package/test/firefox_test.js +0 -233
  69. package/test/frame_test.js +0 -45
  70. package/test/http/http_test.js +0 -229
  71. package/test/http/util_test.js +0 -178
  72. package/test/io/io_test.js +0 -364
  73. package/test/io/zip_test.js +0 -126
  74. package/test/lib/by_test.js +0 -160
  75. package/test/lib/capabilities_test.js +0 -129
  76. package/test/lib/error_test.js +0 -333
  77. package/test/lib/http_test.js +0 -576
  78. package/test/lib/input_test.js +0 -1379
  79. package/test/lib/logging_test.js +0 -272
  80. package/test/lib/promise_test.js +0 -674
  81. package/test/lib/testutil.js +0 -90
  82. package/test/lib/until_test.js +0 -478
  83. package/test/lib/webdriver_test.js +0 -1692
  84. package/test/logging_test.js +0 -160
  85. package/test/net/index_test.js +0 -60
  86. package/test/net/portprober_test.js +0 -128
  87. package/test/page_loading_test.js +0 -156
  88. package/test/proxy_test.js +0 -167
  89. package/test/rect_test.js +0 -51
  90. package/test/remote_test.js +0 -98
  91. package/test/safari_test.js +0 -44
  92. package/test/stale_element_test.js +0 -60
  93. package/test/upload_test.js +0 -78
  94. package/test/window_test.js +0 -168
  95. package/tools/init_jasmine.js +0 -7
@@ -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
- const assert = require('assert');
21
-
22
- const test = require('../lib/test');
23
- const {Browser, By, logging} = require('..');
24
-
25
- test.suite(function(env) {
26
- // Logging API is not supported in IE.
27
- // Logging API not supported in Marionette.
28
- // Logging API not supported in Safari.
29
- test.ignore(env.browsers(Browser.IE, Browser.SAFARI, Browser.FIREFOX)).
30
- describe('logging', function() {
31
- var driver;
32
-
33
- beforeEach(function() {
34
- driver = null;
35
- });
36
-
37
- afterEach(async function() {
38
- if (driver) {
39
- return driver.quit();
40
- }
41
- });
42
-
43
- it('can be disabled', async function() {
44
- var prefs = new logging.Preferences();
45
- prefs.setLevel(logging.Type.BROWSER, logging.Level.OFF);
46
-
47
- driver = await env.builder()
48
- .setLoggingPrefs(prefs)
49
- .build();
50
-
51
- await driver.get(dataUrl(
52
- '<!DOCTYPE html><script>',
53
- 'console.info("hello");',
54
- 'console.warn("this is a warning");',
55
- 'console.error("and this is an error");',
56
- '</script>'));
57
- return driver.manage().logs().get(logging.Type.BROWSER)
58
- .then(entries => assert.equal(entries.length, 0));
59
- });
60
-
61
- // Firefox does not capture JS error console log messages.
62
- test.ignore(env.browsers(Browser.FIREFOX, 'legacy-firefox')).
63
- it('can be turned down', async function() {
64
- var prefs = new logging.Preferences();
65
- prefs.setLevel(logging.Type.BROWSER, logging.Level.SEVERE);
66
-
67
- driver = await env.builder()
68
- .setLoggingPrefs(prefs)
69
- .build();
70
-
71
- await driver.get(dataUrl(
72
- '<!DOCTYPE html><script>',
73
- 'console.info("hello");',
74
- 'console.warn("this is a warning");',
75
- 'console.error("and this is an error");',
76
- '</script>'));
77
- return driver.manage().logs().get(logging.Type.BROWSER)
78
- .then(function(entries) {
79
- assert.equal(entries.length, 1);
80
- assert.equal(entries[0].level.name, 'SEVERE');
81
- assert.ok(/.*\"?and this is an error\"?/.test(entries[0].message));
82
- });
83
- });
84
-
85
- // Firefox does not capture JS error console log messages.
86
- test.ignore(env.browsers(Browser.FIREFOX, 'legacy-firefox')).
87
- it('can be made verbose', async function() {
88
- var prefs = new logging.Preferences();
89
- prefs.setLevel(logging.Type.BROWSER, logging.Level.DEBUG);
90
-
91
- driver = await env.builder()
92
- .setLoggingPrefs(prefs)
93
- .build();
94
-
95
- await driver.get(dataUrl(
96
- '<!DOCTYPE html><script>',
97
- 'console.debug("hello");',
98
- 'console.warn("this is a warning");',
99
- 'console.error("and this is an error");',
100
- '</script>'));
101
- return driver.manage().logs().get(logging.Type.BROWSER)
102
- .then(function(entries) {
103
- assert.equal(entries.length, 3);
104
- assert.equal(entries[0].level.name, 'DEBUG');
105
- assert.ok(/.*\"?hello\"?/.test(entries[0].message));
106
-
107
- assert.equal(entries[1].level.name, 'WARNING');
108
- assert.ok(/.*\"?this is a warning\"?/.test(entries[1].message));
109
-
110
- assert.equal(entries[2].level.name, 'SEVERE');
111
- assert.ok(/.*\"?and this is an error\"?/.test(entries[2].message));
112
- });
113
- });
114
-
115
- // Firefox does not capture JS error console log messages.
116
- test.ignore(env.browsers(Browser.FIREFOX, 'legacy-firefox')).
117
- it('clears records after retrieval', async function() {
118
- var prefs = new logging.Preferences();
119
- prefs.setLevel(logging.Type.BROWSER, logging.Level.DEBUG);
120
-
121
- driver = await env.builder()
122
- .setLoggingPrefs(prefs)
123
- .build();
124
-
125
- await driver.get(dataUrl(
126
- '<!DOCTYPE html><script>',
127
- 'console.debug("hello");',
128
- 'console.warn("this is a warning");',
129
- 'console.error("and this is an error");',
130
- '</script>'));
131
- await driver.manage().logs().get(logging.Type.BROWSER)
132
- .then(entries => assert.equal(entries.length, 3));
133
- return driver.manage().logs().get(logging.Type.BROWSER)
134
- .then(entries => assert.equal(entries.length, 0));
135
- });
136
-
137
- it('does not mix log types', async function() {
138
- var prefs = new logging.Preferences();
139
- prefs.setLevel(logging.Type.BROWSER, logging.Level.DEBUG);
140
- prefs.setLevel(logging.Type.DRIVER, logging.Level.SEVERE);
141
-
142
- driver = await env.builder()
143
- .setLoggingPrefs(prefs)
144
- .build();
145
-
146
- await driver.get(dataUrl(
147
- '<!DOCTYPE html><script>',
148
- 'console.debug("hello");',
149
- 'console.warn("this is a warning");',
150
- 'console.error("and this is an error");',
151
- '</script>'));
152
- return driver.manage().logs().get(logging.Type.DRIVER)
153
- .then(entries => assert.equal(entries.length, 0));
154
- });
155
- });
156
-
157
- function dataUrl(...args) {
158
- return 'data:text/html,' + args.join('');
159
- }
160
- });
@@ -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
- var assert = require('assert');
21
-
22
- var net = require('../../net');
23
-
24
- describe('net.splitHostAndPort', function() {
25
- it('hostname with no port', function() {
26
- assert.deepEqual(
27
- net.splitHostAndPort('www.example.com'),
28
- {host: 'www.example.com', port: null});
29
- });
30
-
31
- it('hostname with port', function() {
32
- assert.deepEqual(
33
- net.splitHostAndPort('www.example.com:80'),
34
- {host: 'www.example.com', port: 80});
35
- });
36
-
37
- it('IPv4 with no port', function() {
38
- assert.deepEqual(
39
- net.splitHostAndPort('127.0.0.1'),
40
- {host: '127.0.0.1', port: null});
41
- });
42
-
43
- it('IPv4 with port', function() {
44
- assert.deepEqual(
45
- net.splitHostAndPort('127.0.0.1:1234'),
46
- {host: '127.0.0.1', port: 1234});
47
- });
48
-
49
- it('IPv6 with no port', function() {
50
- assert.deepEqual(
51
- net.splitHostAndPort('1234:0:1000:5768:1234:5678:90'),
52
- {host: '1234:0:1000:5768:1234:5678:90', port: null});
53
- });
54
-
55
- it('IPv6 with port', function() {
56
- assert.deepEqual(
57
- net.splitHostAndPort('[1234:0:1000:5768:1234:5678:90]:1234'),
58
- {host: '1234:0:1000:5768:1234:5678:90', port: 1234});
59
- });
60
- });
@@ -1,128 +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 net = require('net');
22
-
23
- const portprober = require('../../net/portprober');
24
-
25
- describe('isFree', function() {
26
-
27
- var server;
28
-
29
- beforeEach(function() {
30
- server = net.createServer(function(){});
31
- })
32
-
33
- afterEach(function(done) {
34
- if (!server) return done();
35
- server.close(function() {
36
- done();
37
- });
38
- });
39
-
40
- it('should work for INADDR_ANY', function(done) {
41
- server.listen(0, function() {
42
- var port = server.address().port;
43
- assertPortNotfree(port).then(function() {
44
- return new Promise(resolve => {
45
- server.close(function() {
46
- server = null;
47
- resolve(assertPortIsFree(port));
48
- });
49
- });
50
- }).then(function() { done(); }, done);
51
- });
52
- });
53
-
54
- it('should work for a specific host', function(done) {
55
- var host = '127.0.0.1';
56
- server.listen(0, host, function() {
57
- var port = server.address().port;
58
- assertPortNotfree(port, host).then(function() {
59
- return new Promise(resolve => {
60
- server.close(function() {
61
- server = null;
62
- resolve(assertPortIsFree(port, host));
63
- });
64
- });
65
- }).then(function() { done(); }, done);
66
- });
67
- });
68
- });
69
-
70
- describe('findFreePort', function() {
71
- var server;
72
-
73
- beforeEach(function() {
74
- server = net.createServer(function(){});
75
- })
76
-
77
- afterEach(function(done) {
78
- if (!server) return done();
79
- server.close(function() {
80
- done();
81
- });
82
- });
83
-
84
- it('should work for INADDR_ANY', function(done) {
85
- portprober.findFreePort().then(function(port) {
86
- server.listen(port, function() {
87
- assertPortNotfree(port).then(function() {
88
- return new Promise(resolve => {
89
- server.close(function() {
90
- server = null;
91
- resolve(assertPortIsFree(port));
92
- });
93
- });
94
- }).then(function() { done(); }, done);
95
- });
96
- });
97
- });
98
-
99
- it('should work for a specific host', function(done) {
100
- var host = '127.0.0.1';
101
- portprober.findFreePort(host).then(function(port) {
102
- server.listen(port, host, function() {
103
- assertPortNotfree(port, host).then(function() {
104
- return new Promise(resolve => {
105
- server.close(function() {
106
- server = null;
107
- resolve(assertPortIsFree(port, host));
108
- });
109
- });
110
- }).then(function() { done(); }, done);
111
- });
112
- });
113
- });
114
- });
115
-
116
-
117
- function assertPortIsFree(port, opt_host) {
118
- return portprober.isFree(port, opt_host).then(function(free) {
119
- assert.ok(free, 'port should be free');
120
- });
121
- }
122
-
123
-
124
- function assertPortNotfree(port, opt_host) {
125
- return portprober.isFree(port, opt_host).then(function(free) {
126
- assert.ok(!free, 'port should is not free');
127
- });
128
- }
@@ -1,156 +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 error = require('../lib/error');
23
- const test = require('../lib/test');
24
- const {Browser, By, until} = require('..');
25
-
26
- const Pages = test.Pages;
27
-
28
-
29
- test.suite(function(env) {
30
- var browsers = (...args) => env.browsers(...args);
31
-
32
- var driver;
33
- before(async function() {
34
- driver = await env.builder().build();
35
- });
36
-
37
- beforeEach(async function() {
38
- if (!driver) {
39
- driver = await env.builder().build();
40
- }
41
- });
42
-
43
- after(function() {
44
- if (driver) {
45
- return driver.quit();
46
- }
47
- });
48
-
49
- it('should wait for document to be loaded', async function() {
50
- await driver.get(Pages.simpleTestPage);
51
- assert.equal(await driver.getTitle(), 'Hello WebDriver');
52
- });
53
-
54
- it('should follow redirects sent in the http response headers',
55
- async function() {
56
- await driver.get(Pages.redirectPage);
57
- assert.equal(await driver.getTitle(), 'We Arrive Here');
58
- });
59
-
60
- it('should be able to get a fragment on the current page', async function() {
61
- await driver.get(Pages.xhtmlTestPage);
62
- await driver.get(Pages.xhtmlTestPage + '#text');
63
- await driver.findElement(By.id('id1'));
64
- });
65
-
66
- it('should wait for all frames to load in a frameset', async function() {
67
- await driver.get(Pages.framesetPage);
68
- await driver.switchTo().frame(0);
69
-
70
- let txt = await driver.findElement(By.css('span#pageNumber')).getText();
71
- assert.equal(txt.trim(), '1');
72
-
73
- await driver.switchTo().defaultContent();
74
- await driver.switchTo().frame(1);
75
- txt = await driver.findElement(By.css('span#pageNumber')).getText();
76
-
77
- assert.equal(txt.trim(), '2');
78
-
79
- // For safari, need to make sure browser is focused on the main frame or
80
- // subsequent tests will fail.
81
- if (env.browser.name === Browser.SAFARI) {
82
- await driver.switchTo().defaultContent();
83
- }
84
- });
85
-
86
- it('should be able to navigate back in browser history', async function() {
87
- await driver.get(Pages.formPage);
88
-
89
- await driver.findElement(By.id('imageButton')).click();
90
- await driver.wait(until.titleIs('We Arrive Here'), 2500);
91
-
92
- await driver.navigate().back();
93
- await driver.wait(until.titleIs('We Leave From Here'), 2500);
94
- });
95
-
96
- it('should be able to navigate back in presence of iframes', async function() {
97
- await driver.get(Pages.xhtmlTestPage);
98
-
99
- await driver.findElement(By.name('sameWindow')).click();
100
- await driver.wait(until.titleIs('This page has iframes'), 2500);
101
-
102
- await driver.navigate().back();
103
- await driver.wait(until.titleIs('XHTML Test Page'), 2500);
104
- });
105
-
106
- it('should be able to navigate forwards in browser history', async function() {
107
- await driver.get(Pages.formPage);
108
-
109
- await driver.findElement(By.id('imageButton')).click();
110
- await driver.wait(until.titleIs('We Arrive Here'), 5000);
111
-
112
- await driver.navigate().back();
113
- await driver.wait(until.titleIs('We Leave From Here'), 5000);
114
-
115
- await driver.navigate().forward();
116
- await driver.wait(until.titleIs('We Arrive Here'), 5000);
117
- });
118
-
119
- it('should be able to refresh a page', async function() {
120
- await driver.get(Pages.xhtmlTestPage);
121
-
122
- await driver.navigate().refresh();
123
-
124
- assert.equal(await driver.getTitle(), 'XHTML Test Page');
125
- });
126
-
127
- it('should return title of page if set', async function() {
128
- await driver.get(Pages.xhtmlTestPage);
129
- assert.equal(await driver.getTitle(), 'XHTML Test Page');
130
-
131
- await driver.get(Pages.simpleTestPage);
132
- assert.equal(await driver.getTitle(), 'Hello WebDriver');
133
- });
134
-
135
- describe('timeouts', function() {
136
- afterEach(function() {
137
- let nullDriver = () => driver = null;
138
- if (driver) {
139
- return driver.quit().then(nullDriver, nullDriver);
140
- }
141
- });
142
-
143
- it('should timeout if page load timeout is set', async function() {
144
- await driver.manage().setTimeouts({pageLoad: 1});
145
- return driver.get(Pages.sleepingPage + '?time=3')
146
- .then(function() {
147
- throw Error('Should have timed out on page load');
148
- }, function(e) {
149
- if (!(e instanceof error.ScriptTimeoutError)
150
- && !(e instanceof error.TimeoutError)) {
151
- throw Error('Unexpected error response: ' + e);
152
- }
153
- });
154
- });
155
- });
156
- });
@@ -1,167 +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 http = require('http');
22
- const url = require('url');
23
-
24
- const firefox = require('../firefox');
25
- const proxy = require('../proxy');
26
- const test = require('../lib/test');
27
- const {Browser} = require('..');
28
- const {Server} = require('../lib/test/httpserver');
29
-
30
- const Pages = test.Pages;
31
-
32
- test.suite(function(env) {
33
- function writeResponse(res, body, encoding, contentType) {
34
- res.writeHead(200, {
35
- 'Content-Length': Buffer.byteLength(body, encoding),
36
- 'Content-Type': contentType
37
- });
38
- res.end(body);
39
- }
40
-
41
- function writePacFile(res) {
42
- writeResponse(res, [
43
- 'function FindProxyForURL(url, host) {',
44
- ' if (shExpMatch(url, "' + goodbyeServer.url('*') + '")) {',
45
- ' return "DIRECT";',
46
- ' }',
47
- ' return "PROXY ' + proxyServer.host() + '";',
48
- '}'
49
- ].join('\n'), 'ascii', 'application/x-javascript-config');
50
- }
51
-
52
- var proxyServer = new Server(function(req, res) {
53
- var pathname = url.parse(req.url).pathname;
54
- if (pathname === '/proxy.pac') {
55
- return writePacFile(res);
56
- }
57
-
58
- writeResponse(res, [
59
- '<!DOCTYPE html>',
60
- '<title>Proxy page</title>',
61
- '<h3>This is the proxy landing page</h3>'
62
- ].join(''), 'utf8', 'text/html; charset=UTF-8');
63
- });
64
-
65
- var helloServer = new Server(function(req, res) {
66
- writeResponse(res, [
67
- '<!DOCTYPE html>',
68
- '<title>Hello</title>',
69
- '<h3>Hello, world!</h3>'
70
- ].join(''), 'utf8', 'text/html; charset=UTF-8');
71
- });
72
-
73
- var goodbyeServer = new Server(function(req, res) {
74
- writeResponse(res, [
75
- '<!DOCTYPE html>',
76
- '<title>Goodbye</title>',
77
- '<h3>Goodbye, world!</h3>'
78
- ].join(''), 'utf8', 'text/html; charset=UTF-8');
79
- });
80
-
81
- // Cannot pass start directly to mocha's before, as mocha will interpret the optional
82
- // port parameter as an async callback parameter.
83
- function mkStartFunc(server) {
84
- return function() {
85
- return server.start();
86
- };
87
- }
88
-
89
- before(mkStartFunc(proxyServer));
90
- before(mkStartFunc(helloServer));
91
- before(mkStartFunc(goodbyeServer));
92
-
93
- after(proxyServer.stop.bind(proxyServer));
94
- after(helloServer.stop.bind(helloServer));
95
- after(goodbyeServer.stop.bind(goodbyeServer));
96
-
97
- var driver;
98
- beforeEach(function() { driver = null; });
99
- afterEach(function() { return driver && driver.quit(); });
100
-
101
- function createDriver(proxy) {
102
- return driver = env.builder()
103
- .setProxy(proxy)
104
- .build();
105
- }
106
-
107
- // Proxy support not implemented.
108
- test.ignore(env.browsers(Browser.CHROME, Browser.IE, Browser.SAFARI)).
109
- describe('manual proxy settings', function() {
110
- it('can configure HTTP proxy host', async function() {
111
- await createDriver(proxy.manual({
112
- http: proxyServer.host(),
113
- bypass: []
114
- }));
115
-
116
- await driver.get(helloServer.url());
117
- assert.equal(await driver.getTitle(), 'Proxy page');
118
- assert.equal(
119
- await driver.findElement({tagName: 'h3'}).getText(),
120
- 'This is the proxy landing page');
121
- });
122
-
123
- it('can bypass proxy for specific hosts', async function() {
124
- await createDriver(proxy.manual({
125
- http: proxyServer.host(),
126
- bypass: [helloServer.host()]
127
- }));
128
-
129
- await driver.get(helloServer.url());
130
- assert.equal(await driver.getTitle(), 'Hello');
131
- assert.equal(
132
- await driver.findElement({tagName: 'h3'}).getText(),
133
- 'Hello, world!');
134
-
135
- // For firefox the no proxy settings appear to match on hostname only.
136
- let url = goodbyeServer.url().replace(/127\.0\.0\.1/, 'localhost');
137
- await driver.get(url);
138
- assert.equal(await driver.getTitle(), 'Proxy page');
139
- assert.equal(
140
- await driver.findElement({tagName: 'h3'}).getText(),
141
- 'This is the proxy landing page');
142
- });
143
-
144
- // TODO: test ftp and https proxies.
145
- });
146
-
147
- // PhantomJS does not support PAC file proxy configuration.
148
- // Safari does not support proxies.
149
- test.ignore(env.browsers(Browser.IE, Browser.SAFARI, Browser.CHROME, Browser.FIREFOX)).
150
- describe('pac proxy settings', function() {
151
- it('can configure proxy through PAC file', async function() {
152
- await createDriver(proxy.pac(proxyServer.url('/proxy.pac')));
153
-
154
- await driver.get(helloServer.url());
155
- assert.equal(await driver.getTitle(), 'Proxy page');
156
- assert.equal(
157
- await driver.findElement({tagName: 'h3'}).getText(),
158
- 'This is the proxy landing page');
159
-
160
- await driver.get(goodbyeServer.url());
161
- assert.equal(await driver.getTitle(), 'Goodbye');
162
- assert.equal(
163
- await driver.findElement({tagName: 'h3'}).getText(),
164
- 'Goodbye, world!');
165
- });
166
- });
167
- });