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.
- package/CHANGES.md +8 -1
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +0 -0
- package/chrome.js +0 -0
- package/edge.js +0 -0
- package/example/chrome_android.js +0 -0
- package/example/chrome_mobile_emulation.js +0 -0
- package/example/firefox_channels.js +0 -0
- package/example/google_search.js +0 -0
- package/example/google_search_test.js +0 -0
- package/example/headless.js +0 -0
- package/example/logging.js +0 -0
- package/firefox.js +20 -3
- package/http/index.js +0 -0
- package/http/util.js +0 -0
- package/ie.js +0 -0
- package/index.js +0 -0
- package/io/exec.js +0 -0
- package/io/index.js +0 -0
- package/io/zip.js +0 -0
- package/lib/actions.js +0 -0
- package/lib/by.js +0 -0
- package/lib/capabilities.js +0 -0
- package/lib/command.js +0 -0
- package/lib/error.js +0 -0
- package/lib/http.js +0 -0
- package/lib/input.js +0 -0
- package/lib/logging.js +0 -0
- package/lib/promise.js +0 -0
- package/lib/proxy.js +0 -0
- package/lib/session.js +0 -0
- package/lib/symbols.js +0 -0
- package/lib/until.js +0 -0
- package/lib/webdriver.js +0 -0
- package/net/index.js +0 -0
- package/net/portprober.js +0 -0
- package/package.json +1 -1
- package/proxy.js +0 -0
- package/remote/index.js +0 -0
- package/safari.js +0 -0
- package/testing/index.js +0 -0
- package/BUILD.bazel +0 -88
- package/jasmine.json +0 -11
- package/lib/README +0 -5
- package/lib/atoms/BUILD.bazel +0 -28
- package/lib/atoms/make-atoms-module.js +0 -12
- 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/tools/init_jasmine.js +0 -7
package/test/lib/http_test.js
DELETED
|
@@ -1,576 +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
|
-
sinon = require('sinon');
|
|
22
|
-
|
|
23
|
-
var Capabilities = require('../../lib/capabilities').Capabilities,
|
|
24
|
-
Command = require('../../lib/command').Command,
|
|
25
|
-
CommandName = require('../../lib/command').Name,
|
|
26
|
-
error = require('../../lib/error'),
|
|
27
|
-
http = require('../../lib/http'),
|
|
28
|
-
Session = require('../../lib/session').Session,
|
|
29
|
-
promise = require('../../lib/promise'),
|
|
30
|
-
WebElement = require('../../lib/webdriver').WebElement;
|
|
31
|
-
|
|
32
|
-
describe('http', function() {
|
|
33
|
-
describe('buildPath', function() {
|
|
34
|
-
it('properly replaces path segments with command parameters', function() {
|
|
35
|
-
var parameters = {'sessionId':'foo', 'url':'http://www.google.com'};
|
|
36
|
-
var finalPath = http.buildPath('/session/:sessionId/url', parameters);
|
|
37
|
-
assert.equal(finalPath, '/session/foo/url');
|
|
38
|
-
assert.deepEqual(parameters, {'url':'http://www.google.com'});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('handles web element references', function() {
|
|
42
|
-
var parameters = {'sessionId':'foo', 'id': WebElement.buildId('bar')};
|
|
43
|
-
|
|
44
|
-
var finalPath = http.buildPath(
|
|
45
|
-
'/session/:sessionId/element/:id/click', parameters);
|
|
46
|
-
assert.equal(finalPath, '/session/foo/element/bar/click');
|
|
47
|
-
assert.deepEqual(parameters, {});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('throws if missing a parameter', function() {
|
|
51
|
-
assert.throws(
|
|
52
|
-
() => http.buildPath('/session/:sessionId', {}),
|
|
53
|
-
function(err) {
|
|
54
|
-
return err instanceof error.InvalidArgumentError
|
|
55
|
-
&& 'Missing required parameter: sessionId' === err.message;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
assert.throws(
|
|
59
|
-
() => http.buildPath(
|
|
60
|
-
'/session/:sessionId/element/:id', {'sessionId': 'foo'}),
|
|
61
|
-
function(err) {
|
|
62
|
-
return err instanceof error.InvalidArgumentError
|
|
63
|
-
&& 'Missing required parameter: id' === err.message;
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('does not match on segments that do not start with a colon', function() {
|
|
68
|
-
assert.equal(
|
|
69
|
-
http.buildPath('/session/foo:bar/baz', {}),
|
|
70
|
-
'/session/foo:bar/baz');
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('Executor', function() {
|
|
75
|
-
let executor;
|
|
76
|
-
let client;
|
|
77
|
-
let send;
|
|
78
|
-
|
|
79
|
-
beforeEach(function setUp() {
|
|
80
|
-
client = new http.Client;
|
|
81
|
-
send = sinon.stub(client, 'send');
|
|
82
|
-
executor = new http.Executor(client);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('command routing', function() {
|
|
86
|
-
it('rejects unrecognized commands', function() {
|
|
87
|
-
return executor.execute(new Command('fake-name'))
|
|
88
|
-
.then(assert.fail, err => {
|
|
89
|
-
if (err instanceof error.UnknownCommandError
|
|
90
|
-
&& 'Unrecognized command: fake-name' === err.message) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
throw err;
|
|
94
|
-
})
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('rejects promise if client fails to send request', function() {
|
|
98
|
-
let error = new Error('boom');
|
|
99
|
-
send.returns(Promise.reject(error));
|
|
100
|
-
return assertFailsToSend(new Command(CommandName.NEW_SESSION))
|
|
101
|
-
.then(function(e) {
|
|
102
|
-
assert.strictEqual(error, e);
|
|
103
|
-
assertSent(
|
|
104
|
-
'POST', '/session', {},
|
|
105
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('can execute commands with no URL parameters', function() {
|
|
110
|
-
var resp = JSON.stringify({sessionId: 'abc123'});
|
|
111
|
-
send.returns(Promise.resolve(new http.Response(200, {}, resp)));
|
|
112
|
-
|
|
113
|
-
let command = new Command(CommandName.NEW_SESSION);
|
|
114
|
-
return assertSendsSuccessfully(command).then(function(response) {
|
|
115
|
-
assertSent(
|
|
116
|
-
'POST', '/session', {},
|
|
117
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('rejects commands missing URL parameters', async function() {
|
|
122
|
-
let command =
|
|
123
|
-
new Command(CommandName.FIND_CHILD_ELEMENT).
|
|
124
|
-
setParameter('sessionId', 's123').
|
|
125
|
-
// Let this be missing: setParameter('id', {'ELEMENT': 'e456'}).
|
|
126
|
-
setParameter('using', 'id').
|
|
127
|
-
setParameter('value', 'foo');
|
|
128
|
-
|
|
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
|
-
}
|
|
136
|
-
assert.ok(!send.called);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('replaces URL parameters with command parameters', function() {
|
|
140
|
-
var command = new Command(CommandName.GET).
|
|
141
|
-
setParameter('sessionId', 's123').
|
|
142
|
-
setParameter('url', 'http://www.google.com');
|
|
143
|
-
|
|
144
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '')));
|
|
145
|
-
|
|
146
|
-
return assertSendsSuccessfully(command).then(function(response) {
|
|
147
|
-
assertSent(
|
|
148
|
-
'POST', '/session/s123/url', {'url': 'http://www.google.com'},
|
|
149
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('uses correct URL', function() {
|
|
154
|
-
beforeEach(() => executor = new http.Executor(client));
|
|
155
|
-
|
|
156
|
-
describe('in legacy mode', function() {
|
|
157
|
-
test(CommandName.MAXIMIZE_WINDOW, {sessionId:'s123'}, false,
|
|
158
|
-
'POST', '/session/s123/window/current/maximize');
|
|
159
|
-
|
|
160
|
-
// This is consistent b/w legacy and W3C, just making sure.
|
|
161
|
-
test(CommandName.GET,
|
|
162
|
-
{sessionId:'s123', url: 'http://www.example.com'}, false,
|
|
163
|
-
'POST', '/session/s123/url', {url: 'http://www.example.com'});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe('in W3C mode', function() {
|
|
167
|
-
test(CommandName.MAXIMIZE_WINDOW, {sessionId:'s123'}, true,
|
|
168
|
-
'POST', '/session/s123/window/maximize');
|
|
169
|
-
|
|
170
|
-
// This is consistent b/w legacy and W3C, just making sure.
|
|
171
|
-
test(CommandName.GET,
|
|
172
|
-
{sessionId:'s123', url: 'http://www.example.com'}, true,
|
|
173
|
-
'POST', '/session/s123/url', {url: 'http://www.example.com'});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
function test(command, parameters, w3c,
|
|
177
|
-
expectedMethod, expectedUrl, opt_expectedParams) {
|
|
178
|
-
it(`command=${command}`, function() {
|
|
179
|
-
var resp = JSON.stringify({sessionId: 'abc123'});
|
|
180
|
-
send.returns(Promise.resolve(new http.Response(200, {}, resp)));
|
|
181
|
-
|
|
182
|
-
let cmd = new Command(command).setParameters(parameters);
|
|
183
|
-
executor.w3c = w3c;
|
|
184
|
-
return executor.execute(cmd).then(function() {
|
|
185
|
-
assertSent(
|
|
186
|
-
expectedMethod, expectedUrl, opt_expectedParams || {},
|
|
187
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe('response parsing', function() {
|
|
195
|
-
it('extracts value from JSON response', function() {
|
|
196
|
-
var responseObj = {
|
|
197
|
-
'status': error.ErrorCode.SUCCESS,
|
|
198
|
-
'value': 'http://www.google.com'
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
202
|
-
.setParameter('sessionId', 's123');
|
|
203
|
-
|
|
204
|
-
send.returns(Promise.resolve(
|
|
205
|
-
new http.Response(200, {}, JSON.stringify(responseObj))));
|
|
206
|
-
|
|
207
|
-
return executor.execute(command).then(function(response) {
|
|
208
|
-
assertSent('GET', '/session/s123/url', {},
|
|
209
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
210
|
-
assert.strictEqual(response, 'http://www.google.com');
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe('extracts Session from NEW_SESSION response', function() {
|
|
215
|
-
beforeEach(() => executor = new http.Executor(client));
|
|
216
|
-
|
|
217
|
-
const command = new Command(CommandName.NEW_SESSION);
|
|
218
|
-
|
|
219
|
-
describe('fails if server returns invalid response', function() {
|
|
220
|
-
describe('(empty response)', function() {
|
|
221
|
-
test(true);
|
|
222
|
-
test(false);
|
|
223
|
-
|
|
224
|
-
function test(w3c) {
|
|
225
|
-
it('w3c === ' + w3c, function() {
|
|
226
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '')));
|
|
227
|
-
executor.w3c = w3c;
|
|
228
|
-
return executor.execute(command).then(
|
|
229
|
-
() => assert.fail('expected to fail'),
|
|
230
|
-
(e) => {
|
|
231
|
-
if (!e.message.startsWith('Unable to parse')) {
|
|
232
|
-
throw e;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe('(no session ID)', function() {
|
|
240
|
-
test(true);
|
|
241
|
-
test(false);
|
|
242
|
-
|
|
243
|
-
function test(w3c) {
|
|
244
|
-
it('w3c === ' + w3c, function() {
|
|
245
|
-
let resp = {value:{name: 'Bob'}};
|
|
246
|
-
send.returns(Promise.resolve(
|
|
247
|
-
new http.Response(200, {}, JSON.stringify(resp))));
|
|
248
|
-
executor.w3c = w3c;
|
|
249
|
-
return executor.execute(command).then(
|
|
250
|
-
() => assert.fail('expected to fail'),
|
|
251
|
-
(e) => {
|
|
252
|
-
if (!e.message.startsWith('Unable to parse')) {
|
|
253
|
-
throw e;
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('handles legacy response', function() {
|
|
262
|
-
var rawResponse = {sessionId: 's123', status: 0, value: {name: 'Bob'}};
|
|
263
|
-
|
|
264
|
-
send.returns(Promise.resolve(
|
|
265
|
-
new http.Response(200, {}, JSON.stringify(rawResponse))));
|
|
266
|
-
|
|
267
|
-
assert.ok(!executor.w3c);
|
|
268
|
-
return executor.execute(command).then(function(response) {
|
|
269
|
-
assert.ok(response instanceof Session);
|
|
270
|
-
assert.equal(response.getId(), 's123');
|
|
271
|
-
|
|
272
|
-
let caps = response.getCapabilities();
|
|
273
|
-
assert.ok(caps instanceof Capabilities);
|
|
274
|
-
assert.equal(caps.get('name'), 'Bob');
|
|
275
|
-
|
|
276
|
-
assert.ok(!executor.w3c);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('auto-upgrades on W3C response', function() {
|
|
281
|
-
let rawResponse = {
|
|
282
|
-
value: {
|
|
283
|
-
sessionId: 's123',
|
|
284
|
-
value: {
|
|
285
|
-
name: 'Bob'
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
send.returns(Promise.resolve(
|
|
291
|
-
new http.Response(200, {}, JSON.stringify(rawResponse))));
|
|
292
|
-
|
|
293
|
-
assert.ok(!executor.w3c);
|
|
294
|
-
return executor.execute(command).then(function(response) {
|
|
295
|
-
assert.ok(response instanceof Session);
|
|
296
|
-
assert.equal(response.getId(), 's123');
|
|
297
|
-
|
|
298
|
-
let caps = response.getCapabilities();
|
|
299
|
-
assert.ok(caps instanceof Capabilities);
|
|
300
|
-
assert.equal(caps.get('name'), 'Bob');
|
|
301
|
-
|
|
302
|
-
assert.ok(executor.w3c);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('if w3c, does not downgrade on legacy response', function() {
|
|
307
|
-
var rawResponse = {sessionId: 's123', status: 0, value: null};
|
|
308
|
-
|
|
309
|
-
send.returns(Promise.resolve(
|
|
310
|
-
new http.Response(200, {}, JSON.stringify(rawResponse))));
|
|
311
|
-
|
|
312
|
-
executor.w3c = true;
|
|
313
|
-
return executor.execute(command).then(function(response) {
|
|
314
|
-
assert.ok(response instanceof Session);
|
|
315
|
-
assert.equal(response.getId(), 's123');
|
|
316
|
-
assert.equal(response.getCapabilities().size, 0);
|
|
317
|
-
assert.ok(executor.w3c, 'should never downgrade');
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('handles legacy new session failures', function() {
|
|
322
|
-
let rawResponse = {
|
|
323
|
-
status: error.ErrorCode.NO_SUCH_ELEMENT,
|
|
324
|
-
value: {message: 'hi'}
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
send.returns(Promise.resolve(
|
|
328
|
-
new http.Response(500, {}, JSON.stringify(rawResponse))));
|
|
329
|
-
|
|
330
|
-
return executor.execute(command)
|
|
331
|
-
.then(() => assert.fail('should have failed'),
|
|
332
|
-
e => {
|
|
333
|
-
assert.ok(e instanceof error.NoSuchElementError);
|
|
334
|
-
assert.equal(e.message, 'hi');
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it('handles w3c new session failures', function() {
|
|
339
|
-
let rawResponse =
|
|
340
|
-
{value: {error: 'no such element', message: 'oops'}};
|
|
341
|
-
|
|
342
|
-
send.returns(Promise.resolve(
|
|
343
|
-
new http.Response(500, {}, JSON.stringify(rawResponse))));
|
|
344
|
-
|
|
345
|
-
return executor.execute(command)
|
|
346
|
-
.then(() => assert.fail('should have failed'),
|
|
347
|
-
e => {
|
|
348
|
-
assert.ok(e instanceof error.NoSuchElementError);
|
|
349
|
-
assert.equal(e.message, 'oops');
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('handles JSON null', function() {
|
|
355
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
356
|
-
.setParameter('sessionId', 's123');
|
|
357
|
-
|
|
358
|
-
send.returns(Promise.resolve(new http.Response(200, {}, 'null')));
|
|
359
|
-
|
|
360
|
-
return executor.execute(command).then(function(response) {
|
|
361
|
-
assertSent('GET', '/session/s123/url', {},
|
|
362
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
363
|
-
assert.strictEqual(response, null);
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
describe('falsy values', function() {
|
|
368
|
-
test(0);
|
|
369
|
-
test(false);
|
|
370
|
-
test('');
|
|
371
|
-
|
|
372
|
-
function test(value) {
|
|
373
|
-
it(`value=${value}`, function() {
|
|
374
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
375
|
-
.setParameter('sessionId', 's123');
|
|
376
|
-
|
|
377
|
-
send.returns(Promise.resolve(
|
|
378
|
-
new http.Response(200, {},
|
|
379
|
-
JSON.stringify({status: 0, value: value}))));
|
|
380
|
-
|
|
381
|
-
return executor.execute(command).then(function(response) {
|
|
382
|
-
assertSent('GET', '/session/s123/url', {},
|
|
383
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
384
|
-
assert.strictEqual(response, value);
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it('handles non-object JSON', function() {
|
|
391
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
392
|
-
.setParameter('sessionId', 's123');
|
|
393
|
-
|
|
394
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '123')));
|
|
395
|
-
|
|
396
|
-
return executor.execute(command).then(function(response) {
|
|
397
|
-
assertSent('GET', '/session/s123/url', {},
|
|
398
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
399
|
-
assert.strictEqual(response, 123);
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it('returns body text when 2xx but not JSON', function() {
|
|
404
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
405
|
-
.setParameter('sessionId', 's123');
|
|
406
|
-
|
|
407
|
-
send.returns(Promise.resolve(
|
|
408
|
-
new http.Response(200, {}, 'hello, world\r\ngoodbye, world!')));
|
|
409
|
-
|
|
410
|
-
return executor.execute(command).then(function(response) {
|
|
411
|
-
assertSent('GET', '/session/s123/url', {},
|
|
412
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
413
|
-
assert.strictEqual(response, 'hello, world\ngoodbye, world!');
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
it('returns body text when 2xx but invalid JSON', function() {
|
|
418
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
419
|
-
.setParameter('sessionId', 's123');
|
|
420
|
-
|
|
421
|
-
send.returns(Promise.resolve(
|
|
422
|
-
new http.Response(200, {}, '[')));
|
|
423
|
-
|
|
424
|
-
return executor.execute(command).then(function(response) {
|
|
425
|
-
assertSent('GET', '/session/s123/url', {},
|
|
426
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
427
|
-
assert.strictEqual(response, '[');
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
it('returns null if no body text and 2xx', function() {
|
|
432
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
433
|
-
.setParameter('sessionId', 's123');
|
|
434
|
-
|
|
435
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '')));
|
|
436
|
-
|
|
437
|
-
return executor.execute(command).then(function(response) {
|
|
438
|
-
assertSent('GET', '/session/s123/url', {},
|
|
439
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
440
|
-
assert.strictEqual(response, null);
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it('returns normalized body text when 2xx but not JSON', function() {
|
|
445
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
446
|
-
.setParameter('sessionId', 's123');
|
|
447
|
-
|
|
448
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '\r\n\n\n\r\n')));
|
|
449
|
-
|
|
450
|
-
return executor.execute(command).then(function(response) {
|
|
451
|
-
assertSent('GET', '/session/s123/url', {},
|
|
452
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
453
|
-
assert.strictEqual(response, '\n\n\n\n');
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
it('throws UnsupportedOperationError for 404 and body not JSON',
|
|
458
|
-
function() {
|
|
459
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
460
|
-
.setParameter('sessionId', 's123');
|
|
461
|
-
|
|
462
|
-
send.returns(Promise.resolve(
|
|
463
|
-
new http.Response(404, {}, 'hello, world\r\ngoodbye, world!')));
|
|
464
|
-
|
|
465
|
-
return executor.execute(command)
|
|
466
|
-
.then(
|
|
467
|
-
() => assert.fail('should have failed'),
|
|
468
|
-
checkError(
|
|
469
|
-
error.UnsupportedOperationError,
|
|
470
|
-
'getCurrentUrl: hello, world\ngoodbye, world!'));
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it('throws WebDriverError for generic 4xx when body not JSON',
|
|
474
|
-
function() {
|
|
475
|
-
var command = new Command(CommandName.GET_CURRENT_URL)
|
|
476
|
-
.setParameter('sessionId', 's123');
|
|
477
|
-
|
|
478
|
-
send.returns(Promise.resolve(
|
|
479
|
-
new http.Response(500, {}, 'hello, world\r\ngoodbye, world!')));
|
|
480
|
-
|
|
481
|
-
return executor.execute(command)
|
|
482
|
-
.then(
|
|
483
|
-
() => assert.fail('should have failed'),
|
|
484
|
-
checkError(
|
|
485
|
-
error.WebDriverError,
|
|
486
|
-
'hello, world\ngoodbye, world!'))
|
|
487
|
-
.then(function() {
|
|
488
|
-
assertSent('GET', '/session/s123/url', {},
|
|
489
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it('canDefineNewCommands', function() {
|
|
495
|
-
executor.defineCommand('greet', 'GET', '/person/:name');
|
|
496
|
-
|
|
497
|
-
var command = new Command('greet').
|
|
498
|
-
setParameter('name', 'Bob');
|
|
499
|
-
|
|
500
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '')));
|
|
501
|
-
|
|
502
|
-
return assertSendsSuccessfully(command).then(function(response) {
|
|
503
|
-
assertSent('GET', '/person/Bob', {},
|
|
504
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
505
|
-
});
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
it('canRedefineStandardCommands', function() {
|
|
509
|
-
executor.defineCommand(CommandName.GO_BACK, 'POST', '/custom/back');
|
|
510
|
-
|
|
511
|
-
var command = new Command(CommandName.GO_BACK).
|
|
512
|
-
setParameter('times', 3);
|
|
513
|
-
|
|
514
|
-
send.returns(Promise.resolve(new http.Response(200, {}, '')));
|
|
515
|
-
|
|
516
|
-
return assertSendsSuccessfully(command).then(function(response) {
|
|
517
|
-
assertSent('POST', '/custom/back', {'times': 3},
|
|
518
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
it('accepts promised http clients', function() {
|
|
523
|
-
executor = new http.Executor(Promise.resolve(client));
|
|
524
|
-
|
|
525
|
-
var resp = JSON.stringify({sessionId: 'abc123'});
|
|
526
|
-
send.returns(Promise.resolve(new http.Response(200, {}, resp)));
|
|
527
|
-
|
|
528
|
-
let command = new Command(CommandName.NEW_SESSION);
|
|
529
|
-
return executor.execute(command).then(response => {
|
|
530
|
-
assertSent(
|
|
531
|
-
'POST', '/session', {},
|
|
532
|
-
[['Accept', 'application/json; charset=utf-8']]);
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
function entries(map) {
|
|
537
|
-
let entries = [];
|
|
538
|
-
for (let e of map.entries()) {
|
|
539
|
-
entries.push(e);
|
|
540
|
-
}
|
|
541
|
-
return entries;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
function checkError(type, message) {
|
|
545
|
-
return function(e) {
|
|
546
|
-
if (e instanceof type) {
|
|
547
|
-
assert.strictEqual(e.message, message);
|
|
548
|
-
} else {
|
|
549
|
-
throw e;
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function assertSent(method, path, data, headers) {
|
|
555
|
-
assert.ok(send.calledWith(sinon.match(function(value) {
|
|
556
|
-
assert.equal(value.method, method);
|
|
557
|
-
assert.equal(value.path, path);
|
|
558
|
-
assert.deepEqual(value.data, data);
|
|
559
|
-
assert.deepEqual(entries(value.headers), headers);
|
|
560
|
-
return true;
|
|
561
|
-
})));
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function assertSendsSuccessfully(command) {
|
|
565
|
-
return executor.execute(command).then(function(response) {
|
|
566
|
-
return response;
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function assertFailsToSend(command, opt_onError) {
|
|
571
|
-
return executor.execute(command).then(
|
|
572
|
-
() => {throw Error('should have failed')},
|
|
573
|
-
(e) => {return e});
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
});
|