selenium-webdriver 3.6.0 → 4.0.0-alpha.1

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 (97) hide show
  1. package/CHANGES.md +181 -0
  2. package/README.md +25 -27
  3. package/chrome.js +113 -127
  4. package/edge.js +42 -117
  5. package/example/chrome_android.js +8 -8
  6. package/example/chrome_mobile_emulation.js +8 -8
  7. package/example/firefox_channels.js +22 -18
  8. package/example/google_search_test.js +39 -26
  9. package/example/logging.js +39 -6
  10. package/firefox.js +769 -0
  11. package/http/index.js +41 -4
  12. package/http/util.js +11 -6
  13. package/ie.js +56 -97
  14. package/index.js +178 -114
  15. package/jasmine.json +11 -0
  16. package/lib/actions.js +68 -63
  17. package/lib/by.js +1 -1
  18. package/lib/capabilities.js +255 -192
  19. package/lib/command.js +26 -50
  20. package/lib/error.js +85 -44
  21. package/lib/http.js +133 -110
  22. package/lib/input.js +1044 -8
  23. package/lib/promise.js +222 -3323
  24. package/lib/proxy.js +134 -39
  25. package/lib/test/bootstrap_jasmine.js +28 -0
  26. package/lib/test/data/actions/click.html +24 -0
  27. package/lib/test/data/actions/drag.html +77 -0
  28. package/lib/test/data/actions/record_click.html +21 -0
  29. package/lib/test/data/chrome/download.html +2 -0
  30. package/lib/test/data/inputs.html +42 -0
  31. package/lib/test/data/selectPage.html +12 -0
  32. package/lib/test/data/simpleTest.html +5 -0
  33. package/lib/test/data/upload_invisible.html +45 -0
  34. package/lib/test/fileserver.js +23 -19
  35. package/lib/test/index.js +30 -212
  36. package/lib/test/resources.js +0 -1
  37. package/lib/webdriver.js +675 -936
  38. package/net/index.js +21 -25
  39. package/net/portprober.js +51 -68
  40. package/package.json +5 -3
  41. package/remote/index.js +5 -19
  42. package/safari.js +41 -128
  43. package/test/actions_test.js +173 -18
  44. package/test/{session_test.js → builder_test.js} +44 -37
  45. package/test/chrome/devtools_test.js +93 -0
  46. package/test/chrome/options_test.js +48 -154
  47. package/test/chrome/service_test.js +7 -7
  48. package/test/cookie_test.js +77 -63
  49. package/test/element_finding_test.js +206 -201
  50. package/test/execute_script_test.js +115 -114
  51. package/test/fingerprint_test.js +16 -15
  52. package/test/firefox_test.js +251 -0
  53. package/test/http/http_test.js +0 -1
  54. package/test/http/util_test.js +2 -2
  55. package/test/io/zip_test.js +6 -7
  56. package/test/lib/error_test.js +34 -7
  57. package/test/lib/http_test.js +8 -128
  58. package/test/lib/input_test.js +1379 -0
  59. package/test/lib/promise_test.js +473 -908
  60. package/test/lib/webdriver_test.js +296 -868
  61. package/test/logging_test.js +37 -43
  62. package/test/page_loading_test.js +71 -81
  63. package/test/proxy_test.js +64 -72
  64. package/test/rect_test.js +14 -25
  65. package/test/remote_test.js +10 -29
  66. package/test/safari_test.js +7 -71
  67. package/test/stale_element_test.js +20 -23
  68. package/test/tag_name_test.js +10 -9
  69. package/test/upload_test.js +27 -35
  70. package/test/window_test.js +72 -85
  71. package/testing/index.js +386 -314
  72. package/.npmignore +0 -2
  73. package/example/async_await_test.js +0 -69
  74. package/example/google_search_generator.js +0 -47
  75. package/example/parallel_flows.js +0 -51
  76. package/firefox/binary.js +0 -347
  77. package/firefox/extension.js +0 -224
  78. package/firefox/index.js +0 -576
  79. package/firefox/profile.js +0 -311
  80. package/lib/events.js +0 -210
  81. package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
  82. package/lib/test/data/firefox/sample.xpi +0 -0
  83. package/lib/test/promise.js +0 -79
  84. package/opera.js +0 -405
  85. package/phantomjs.js +0 -282
  86. package/test/firefox/extension_test.js +0 -120
  87. package/test/firefox/firefox_test.js +0 -244
  88. package/test/firefox/profile_test.js +0 -140
  89. package/test/lib/events_test.js +0 -177
  90. package/test/lib/promise_aplus_test.js +0 -78
  91. package/test/lib/promise_error_test.js +0 -884
  92. package/test/lib/promise_flow_test.js +0 -2288
  93. package/test/lib/promise_generator_test.js +0 -310
  94. package/test/phantomjs/execute_phantomjs_test.js +0 -59
  95. package/test/testing/assert_test.js +0 -373
  96. package/test/testing/index_test.js +0 -224
  97. package/testing/assert.js +0 -378
@@ -0,0 +1,251 @@
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
+ /**
51
+ * Runs a test that requires Firefox Developer Edition. The test will be
52
+ * skipped if dev cannot be found on the current system.
53
+ */
54
+ function runWithFirefoxDev(options, testFn) {
55
+ return firefox.Channel.AURORA.locate().then(async (exe) => {
56
+ options = options || new firefox.Options();
57
+ options.setBinary(exe);
58
+ driver = await env.builder()
59
+ .setFirefoxOptions(options)
60
+ .build();
61
+ return testFn();
62
+ }, err => {
63
+ console.warn(
64
+ 'Skipping test: could not find Firefox Dev Edition: ' + err);
65
+ });
66
+ }
67
+
68
+ describe('Options', function() {
69
+ let profileWithWebExtension;
70
+ let profileWithUserPrefs;
71
+
72
+ before(async function createProfileWithWebExtension() {
73
+ profileWithWebExtension = await io.tmpDir();
74
+ let extensionsDir = path.join(profileWithWebExtension, 'extensions');
75
+ await io.mkdir(extensionsDir);
76
+ await io.write(
77
+ path.join(extensionsDir, WEBEXTENSION_EXTENSION_ID),
78
+ await io.read(WEBEXTENSION_EXTENSION));
79
+ });
80
+
81
+ before(async function createProfileWithUserPrefs() {
82
+ profileWithUserPrefs = await io.tmpDir();
83
+ await io.write(
84
+ path.join(profileWithUserPrefs, 'user.js'),
85
+ 'user_pref("general.useragent.override", "foo;bar");\n');
86
+ });
87
+
88
+ describe('setProfile', function() {
89
+ it('use profile with custom prefs', async function() {
90
+ let options = new firefox.Options;
91
+ options.setProfile(profileWithUserPrefs);
92
+
93
+ driver = env.builder().setFirefoxOptions(options).build();
94
+
95
+ await driver.get(Pages.echoPage);
96
+ await verifyUserAgentWasChanged();
97
+ });
98
+
99
+ it('use profile with extension', function() {
100
+ let options = new firefox.Options;
101
+ options.setProfile(profileWithWebExtension);
102
+
103
+ return runWithFirefoxDev(options, async function() {
104
+ await driver.get(Pages.echoPage);
105
+ await verifyWebExtensionWasInstalled();
106
+ });
107
+ });
108
+ });
109
+
110
+ describe('setPreference', function() {
111
+ it('throws if key is not a string', function() {
112
+ let options = new firefox.Options;
113
+ assert.throws(() => options.setPreference(1, 2), TypeError);
114
+ options.setPreference('1', 2); // OK if no throw.
115
+ });
116
+
117
+ it('throws if value is an invalid type', function() {
118
+ let options = new firefox.Options;
119
+ options.setPreference('a', 1);
120
+ options.setPreference('b', '2');
121
+ options.setPreference('c', true);
122
+
123
+ assert.throws(() => options.setPreference('d', null), TypeError);
124
+ assert.throws(() => options.setPreference('d', undefined), TypeError);
125
+ assert.throws(() => options.setPreference('d', {}), TypeError);
126
+ });
127
+
128
+ it('can start Firefox with custom preferences', async function() {
129
+ let options = new firefox.Options();
130
+ options.setPreference('general.useragent.override', 'foo;bar');
131
+
132
+ driver = env.builder().setFirefoxOptions(options).build();
133
+
134
+ await driver.get(Pages.echoPage);
135
+ await verifyUserAgentWasChanged();
136
+ });
137
+
138
+ it('can add extra prefs on top of an existing profile', async function() {
139
+ let options = new firefox.Options()
140
+ .setPreference('general.useragent.override', 'foo;bar')
141
+ .setProfile(profileWithWebExtension);
142
+
143
+ return runWithFirefoxDev(options, async function() {
144
+ await driver.get(Pages.echoPage);
145
+ await verifyWebExtensionWasInstalled();
146
+ await verifyUserAgentWasChanged();
147
+ });
148
+ });
149
+ });
150
+
151
+ describe('addExtensions', function() {
152
+ it('can add extension to brand new profile', async function() {
153
+ let options = new firefox.Options();
154
+ options.addExtensions(WEBEXTENSION_EXTENSION);
155
+
156
+ return runWithFirefoxDev(options, async function() {
157
+ await driver.get(Pages.echoPage);
158
+ await verifyWebExtensionWasInstalled();
159
+ });
160
+ });
161
+
162
+ it('can add extension to custom profile', function() {
163
+ let options = new firefox.Options()
164
+ .addExtensions(WEBEXTENSION_EXTENSION)
165
+ .setProfile(profileWithUserPrefs);
166
+
167
+ return runWithFirefoxDev(options, async function() {
168
+ await driver.get(Pages.echoPage);
169
+ await verifyWebExtensionWasInstalled();
170
+ await verifyUserAgentWasChanged();
171
+ });
172
+ });
173
+
174
+ it('can addExtensions and setPreference', function() {
175
+ let options = new firefox.Options()
176
+ .addExtensions(WEBEXTENSION_EXTENSION)
177
+ .setPreference('general.useragent.override', 'foo;bar')
178
+
179
+ return runWithFirefoxDev(options, async function() {
180
+ await driver.get(Pages.echoPage);
181
+ await verifyWebExtensionWasInstalled();
182
+ await verifyUserAgentWasChanged();
183
+ });
184
+ });
185
+ });
186
+ });
187
+
188
+ describe('context switching', function() {
189
+ beforeEach(async function() {
190
+ driver = await env.builder().build();
191
+ });
192
+
193
+ it('can get context', async function() {
194
+ assert.equal(await driver.getContext(), Context.CONTENT);
195
+ });
196
+
197
+ it('can set context', async function() {
198
+ await driver.setContext(Context.CHROME);
199
+ let ctxt = await driver.getContext();
200
+ assert.equal(ctxt, Context.CHROME);
201
+
202
+ await driver.setContext(Context.CONTENT);
203
+ ctxt = await driver.getContext();
204
+ assert.equal(ctxt, Context.CONTENT);
205
+ });
206
+
207
+ it('throws on unknown context', function() {
208
+ return driver.setContext("foo").then(assert.fail, function(e) {
209
+ assert(e instanceof error.InvalidArgumentError);
210
+ });
211
+ });
212
+ });
213
+
214
+ it('addons can be installed and uninstalled at runtime', function() {
215
+ return runWithFirefoxDev(null, async function() {
216
+ await driver.get(Pages.echoPage);
217
+ await verifyWebExtensionNotInstalled();
218
+
219
+ let id = await driver.installAddon(WEBEXTENSION_EXTENSION);
220
+ await driver.sleep(1000); // Give extension time to install (yuck).
221
+
222
+ await driver.get(Pages.echoPage);
223
+ await verifyWebExtensionWasInstalled();
224
+
225
+ await driver.uninstallAddon(id);
226
+ await driver.get(Pages.echoPage);
227
+ await verifyWebExtensionNotInstalled();
228
+ });
229
+ });
230
+
231
+ async function verifyUserAgentWasChanged() {
232
+ let userAgent =
233
+ await driver.executeScript('return window.navigator.userAgent');
234
+ assert.equal(userAgent, 'foo;bar');
235
+ }
236
+
237
+ async function verifyWebExtensionNotInstalled() {
238
+ let found =
239
+ await driver.findElements({id: 'webextensions-selenium-example'});
240
+ assert.equal(found.length, 0);
241
+ }
242
+
243
+ async function verifyWebExtensionWasInstalled() {
244
+ let footer =
245
+ await driver.findElement({id: 'webextensions-selenium-example'});
246
+ let text = await footer.getText();
247
+ assert.equal(
248
+ text, 'Content injected by webextensions-selenium-example');
249
+ }
250
+ });
251
+ }, {browsers: [Browser.FIREFOX]});
@@ -27,7 +27,6 @@ var HttpClient = require('../../http').HttpClient,
27
27
  Server = require('../../lib/test/httpserver').Server;
28
28
 
29
29
  describe('HttpClient', function() {
30
- this.timeout(4 * 1000);
31
30
 
32
31
  var server = new Server(function(req, res) {
33
32
  let parsedUrl = url.parse(req.url);
@@ -132,7 +132,7 @@ describe('selenium-webdriver/http/util', function() {
132
132
  return util.waitForServer(baseUrl, 200, cancel)
133
133
  .then(
134
134
  () => { throw Error('Did not expect to succeed!'); },
135
- (e) => assert.ok(e instanceof promise.CancellationError));
135
+ (e) => assert.ok(e instanceof util.CancellationError));
136
136
  });
137
137
  });
138
138
 
@@ -172,7 +172,7 @@ describe('selenium-webdriver/http/util', function() {
172
172
  return util.waitForUrl(baseUrl, 200, cancel)
173
173
  .then(
174
174
  () => { throw Error('Did not expect to succeed!'); },
175
- (e) => assert.ok(e instanceof promise.CancellationError));
175
+ (e) => assert.ok(e instanceof util.CancellationError));
176
176
  });
177
177
  });
178
178
  });
@@ -27,19 +27,18 @@ const zip = require('../../io/zip');
27
27
  const {InvalidArgumentError} = require('../../lib/error');
28
28
 
29
29
 
30
- const SAMPLE_XPI_PATH =
31
- path.join(__dirname, '../../lib/test/data/firefox/sample.xpi');
30
+ const XPI_PATH =
31
+ path.join(__dirname, '../../lib/test/data/firefox/webextension.xpi');
32
32
 
33
33
  describe('io/zip', function() {
34
34
  describe('unzip', function() {
35
35
  it('creates destination dir if necessary', function() {
36
36
  return io.tmpDir()
37
- .then(dir => zip.unzip(SAMPLE_XPI_PATH, dir))
37
+ .then(dir => zip.unzip(XPI_PATH, dir))
38
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'));
39
+ assertExists(path.join(dir, 'inject.js'));
40
+ assertExists(path.join(dir, 'manifest.json'));
41
+ assertExists(path.join(dir, 'META-INF/manifest.mf'));
43
42
  });
44
43
  });
45
44
  });
@@ -40,16 +40,17 @@ describe('error', function() {
40
40
  test('unknown error', error.WebDriverError);
41
41
  test('element not interactable', error.ElementNotInteractableError);
42
42
  test('element not selectable', error.ElementNotSelectableError);
43
- test('element not visible', error.ElementNotVisibleError);
43
+ test('insecure certificate', error.InsecureCertificateError);
44
44
  test('invalid argument', error.InvalidArgumentError);
45
45
  test('invalid cookie domain', error.InvalidCookieDomainError);
46
- test('invalid element coordinates', error.InvalidElementCoordinatesError);
46
+ test('invalid coordinates', error.InvalidCoordinatesError);
47
47
  test('invalid element state', error.InvalidElementStateError);
48
48
  test('invalid selector', error.InvalidSelectorError);
49
49
  test('invalid session id', error.NoSuchSessionError);
50
50
  test('javascript error', error.JavascriptError);
51
51
  test('move target out of bounds', error.MoveTargetOutOfBoundsError);
52
52
  test('no such alert', error.NoSuchAlertError);
53
+ test('no such cookie', error.NoSuchCookieError);
53
54
  test('no such element', error.NoSuchElementError);
54
55
  test('no such frame', error.NoSuchFrameError);
55
56
  test('no such window', error.NoSuchWindowError);
@@ -92,8 +93,9 @@ describe('error', function() {
92
93
  });
93
94
 
94
95
  test(error.WebDriverError, 'unknown error');
96
+ test(error.ElementClickInterceptedError, 'element click intercepted');
95
97
  test(error.ElementNotSelectableError, 'element not selectable');
96
- test(error.ElementNotVisibleError, 'element not visible');
98
+ test(error.InsecureCertificateError, 'insecure certificate');
97
99
  test(error.InvalidArgumentError, 'invalid argument');
98
100
  test(error.InvalidCookieDomainError, 'invalid cookie domain');
99
101
  test(error.InvalidElementStateError, 'invalid element state');
@@ -102,6 +104,7 @@ describe('error', function() {
102
104
  test(error.JavascriptError, 'javascript error');
103
105
  test(error.MoveTargetOutOfBoundsError, 'move target out of bounds');
104
106
  test(error.NoSuchAlertError, 'no such alert');
107
+ test(error.NoSuchCookieError, 'no such cookie');
105
108
  test(error.NoSuchElementError, 'no such element');
106
109
  test(error.NoSuchFrameError, 'no such frame');
107
110
  test(error.NoSuchWindowError, 'no such window');
@@ -163,17 +166,19 @@ describe('error', function() {
163
166
  });
164
167
 
165
168
  test('unknown error', error.WebDriverError);
169
+ test('element click intercepted', error.ElementClickInterceptedError);
166
170
  test('element not selectable', error.ElementNotSelectableError);
167
- test('element not visible', error.ElementNotVisibleError);
171
+ test('insecure certificate', error.InsecureCertificateError);
168
172
  test('invalid argument', error.InvalidArgumentError);
169
173
  test('invalid cookie domain', error.InvalidCookieDomainError);
170
- test('invalid element coordinates', error.InvalidElementCoordinatesError);
174
+ test('invalid coordinates', error.InvalidCoordinatesError);
171
175
  test('invalid element state', error.InvalidElementStateError);
172
176
  test('invalid selector', error.InvalidSelectorError);
173
177
  test('invalid session id', error.NoSuchSessionError);
174
178
  test('javascript error', error.JavascriptError);
175
179
  test('move target out of bounds', error.MoveTargetOutOfBoundsError);
176
180
  test('no such alert', error.NoSuchAlertError);
181
+ test('no such cookie', error.NoSuchCookieError);
177
182
  test('no such element', error.NoSuchElementError);
178
183
  test('no such frame', error.NoSuchFrameError);
179
184
  test('no such window', error.NoSuchWindowError);
@@ -218,6 +223,24 @@ describe('error', function() {
218
223
  });
219
224
  });
220
225
  }
226
+
227
+ describe('remote stack trace decoding', function() {
228
+ test('stacktrace');
229
+ test('stackTrace');
230
+
231
+ function test(key) {
232
+ it(`encoded as "${key}"`, function() {
233
+ let data = {error: 'unknown command', message: 'oops'};
234
+ data[key] = 'some-stacktrace';
235
+ assert.throws(
236
+ () => error.throwDecodedError(data),
237
+ (e) => {
238
+ assert.strictEqual(e.remoteStacktrace, 'some-stacktrace');
239
+ return true;
240
+ });
241
+ });
242
+ }
243
+ });
221
244
  });
222
245
 
223
246
  describe('checkLegacyResponse', function() {
@@ -226,12 +249,12 @@ describe('error', function() {
226
249
  assert.strictEqual(resp, error.checkLegacyResponse(resp));
227
250
  });
228
251
 
252
+ test('NO_SUCH_SESSION', error.NoSuchSessionError);
229
253
  test('NO_SUCH_ELEMENT', error.NoSuchElementError);
230
254
  test('NO_SUCH_FRAME', error.NoSuchFrameError);
231
255
  test('UNKNOWN_COMMAND', error.UnsupportedOperationError);
232
256
  test('UNSUPPORTED_OPERATION', error.UnsupportedOperationError);
233
257
  test('STALE_ELEMENT_REFERENCE', error.StaleElementReferenceError);
234
- test('ELEMENT_NOT_VISIBLE', error.ElementNotVisibleError);
235
258
  test('INVALID_ELEMENT_STATE', error.InvalidElementStateError);
236
259
  test('UNKNOWN_ERROR', error.WebDriverError);
237
260
  test('ELEMENT_NOT_SELECTABLE', error.ElementNotSelectableError);
@@ -244,12 +267,16 @@ describe('error', function() {
244
267
  test('UNEXPECTED_ALERT_OPEN', error.UnexpectedAlertOpenError);
245
268
  test('NO_SUCH_ALERT', error.NoSuchAlertError);
246
269
  test('SCRIPT_TIMEOUT', error.ScriptTimeoutError);
247
- test('INVALID_ELEMENT_COORDINATES', error.InvalidElementCoordinatesError);
270
+ test('INVALID_ELEMENT_COORDINATES', error.InvalidCoordinatesError);
248
271
  test('INVALID_SELECTOR_ERROR', error.InvalidSelectorError);
249
272
  test('SESSION_NOT_CREATED', error.SessionNotCreatedError);
250
273
  test('MOVE_TARGET_OUT_OF_BOUNDS', error.MoveTargetOutOfBoundsError);
251
274
  test('INVALID_XPATH_SELECTOR', error.InvalidSelectorError);
252
275
  test('INVALID_XPATH_SELECTOR_RETURN_TYPE', error.InvalidSelectorError);
276
+ test('ELEMENT_NOT_INTERACTABLE', error.ElementNotInteractableError);
277
+ test('INVALID_ARGUMENT', error.InvalidArgumentError);
278
+ test('UNABLE_TO_CAPTURE_SCREEN', error.UnableToCaptureScreenError);
279
+ test('ELEMENT_CLICK_INTERCEPTED', error.ElementClickInterceptedError);
253
280
  test('METHOD_NOT_ALLOWED', error.UnsupportedOperationError);
254
281
 
255
282
  describe('UnexpectedAlertOpenError', function() {
@@ -118,7 +118,7 @@ describe('http', function() {
118
118
  });
119
119
  });
120
120
 
121
- it('rejects commands missing URL parameters', function() {
121
+ it('rejects commands missing URL parameters', async function() {
122
122
  let command =
123
123
  new Command(CommandName.FIND_CHILD_ELEMENT).
124
124
  setParameter('sessionId', 's123').
@@ -126,12 +126,13 @@ describe('http', function() {
126
126
  setParameter('using', 'id').
127
127
  setParameter('value', 'foo');
128
128
 
129
- assert.throws(
130
- () => executor.execute(command),
131
- function(err) {
132
- return err instanceof error.InvalidArgumentError
133
- && 'Missing required parameter: id' === err.message;
134
- });
129
+ try {
130
+ await executor.execute(command);
131
+ return Promise.reject(Error('should have thrown'));
132
+ } catch (err) {
133
+ assert.strictEqual(err.constructor, error.InvalidArgumentError);
134
+ assert.equal(err.message, 'Missing required parameter: id');
135
+ }
135
136
  assert.ok(!send.called);
136
137
  });
137
138
 
@@ -153,14 +154,6 @@ describe('http', function() {
153
154
  beforeEach(() => executor = new http.Executor(client));
154
155
 
155
156
  describe('in legacy mode', function() {
156
- test(CommandName.GET_WINDOW_SIZE, {sessionId:'s123'}, false,
157
- 'GET', '/session/s123/window/current/size');
158
-
159
- test(CommandName.SET_WINDOW_SIZE,
160
- {sessionId:'s123', width: 1, height: 1}, false,
161
- 'POST', '/session/s123/window/current/size',
162
- {width: 1, height: 1});
163
-
164
157
  test(CommandName.MAXIMIZE_WINDOW, {sessionId:'s123'}, false,
165
158
  'POST', '/session/s123/window/current/maximize');
166
159
 
@@ -171,14 +164,6 @@ describe('http', function() {
171
164
  });
172
165
 
173
166
  describe('in W3C mode', function() {
174
- test(CommandName.GET_WINDOW_SIZE,
175
- {sessionId:'s123'}, true,
176
- 'GET', '/session/s123/window/size');
177
-
178
- test(CommandName.SET_WINDOW_SIZE,
179
- {sessionId:'s123', width: 1, height: 1}, true,
180
- 'POST', '/session/s123/window/size', {width: 1, height: 1});
181
-
182
167
  test(CommandName.MAXIMIZE_WINDOW, {sessionId:'s123'}, true,
183
168
  'POST', '/session/s123/window/maximize');
184
169
 
@@ -366,111 +351,6 @@ describe('http', function() {
366
351
  });
367
352
  });
368
353
 
369
- describe('extracts Session from DESCRIBE_SESSION response', function() {
370
- let command;
371
-
372
- beforeEach(function() {
373
- executor = new http.Executor(client);
374
- command = new Command(CommandName.DESCRIBE_SESSION)
375
- .setParameter('sessionId', 'foo');
376
- });
377
-
378
- describe('fails if server returns invalid response', function() {
379
- describe('(empty response)', function() {
380
- test(true);
381
- test(false);
382
-
383
- function test(w3c) {
384
- it('w3c === ' + w3c, function() {
385
- send.returns(Promise.resolve(new http.Response(200, {}, '')));
386
- executor.w3c = w3c;
387
- return executor.execute(command).then(
388
- () => assert.fail('expected to fail'),
389
- (e) => {
390
- if (!e.message.startsWith('Unable to parse')) {
391
- throw e;
392
- }
393
- });
394
- });
395
- }
396
- });
397
-
398
- describe('(no session ID)', function() {
399
- test(true);
400
- test(false);
401
-
402
- function test(w3c) {
403
- it('w3c === ' + w3c, function() {
404
- let resp = {value:{name: 'Bob'}};
405
- send.returns(Promise.resolve(
406
- new http.Response(200, {}, JSON.stringify(resp))));
407
- executor.w3c = w3c;
408
- return executor.execute(command).then(
409
- () => assert.fail('expected to fail'),
410
- (e) => {
411
- if (!e.message.startsWith('Unable to parse')) {
412
- throw e;
413
- }
414
- });
415
- });
416
- }
417
- });
418
- });
419
-
420
- it('handles legacy response', function() {
421
- var rawResponse = {sessionId: 's123', status: 0, value: {name: 'Bob'}};
422
-
423
- send.returns(Promise.resolve(
424
- new http.Response(200, {}, JSON.stringify(rawResponse))));
425
-
426
- assert.ok(!executor.w3c);
427
- return executor.execute(command).then(function(response) {
428
- assert.ok(response instanceof Session);
429
- assert.equal(response.getId(), 's123');
430
-
431
- let caps = response.getCapabilities();
432
- assert.ok(caps instanceof Capabilities);
433
- assert.equal(caps.get('name'), 'Bob');
434
-
435
- assert.ok(!executor.w3c);
436
- });
437
- });
438
-
439
- it('does not auto-upgrade on W3C response', function() {
440
- var rawResponse = {value: {sessionId: 's123', value: {name: 'Bob'}}};
441
-
442
- send.returns(Promise.resolve(
443
- new http.Response(200, {}, JSON.stringify(rawResponse))));
444
-
445
- assert.ok(!executor.w3c);
446
- return executor.execute(command).then(function(response) {
447
- assert.ok(response instanceof Session);
448
- assert.equal(response.getId(), 's123');
449
-
450
- let caps = response.getCapabilities();
451
- assert.ok(caps instanceof Capabilities);
452
- assert.equal(caps.get('name'), 'Bob');
453
-
454
- assert.ok(!executor.w3c);
455
- });
456
- });
457
-
458
- it('if w3c, does not downgrade on legacy response', function() {
459
- var rawResponse = {sessionId: 's123', status: 0, value: null};
460
-
461
- send.returns(Promise.resolve(
462
- new http.Response(200, {}, JSON.stringify(rawResponse))));
463
-
464
- executor.w3c = true;
465
- return executor.execute(command).then(function(response) {
466
- assert.ok(response instanceof Session);
467
- assert.equal(response.getId(), 's123');
468
- assert.equal(response.getCapabilities().size, 0);
469
- assert.ok(executor.w3c, 'should never downgrade');
470
- });
471
- });
472
- });
473
-
474
354
  it('handles JSON null', function() {
475
355
  var command = new Command(CommandName.GET_CURRENT_URL)
476
356
  .setParameter('sessionId', 's123');