selenium-webdriver 4.0.0-alpha.3 → 4.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +9 -2
- package/README.md +2 -4
- package/chrome.js +19 -527
- package/chromium.js +762 -0
- package/edge.js +97 -58
- package/firefox.js +23 -5
- package/http/index.js +4 -0
- package/io/index.js +1 -1
- package/lib/actions.js +1 -1
- package/lib/atoms/get-attribute.js +1 -2
- package/lib/atoms/is-displayed.js +5 -6
- package/lib/atoms/make-atoms-module.js +17 -0
- package/lib/capabilities.js +17 -4
- package/lib/command.js +1 -0
- package/lib/http.js +8 -3
- package/lib/input.js +6 -6
- package/lib/logging.js +1 -1
- package/lib/webdriver.js +33 -3
- package/net/portprober.js +1 -1
- package/package.json +8 -9
- package/BUILD.bazel +0 -88
- package/example/chrome_android.js +0 -42
- package/example/chrome_mobile_emulation.js +0 -42
- package/example/firefox_channels.js +0 -77
- package/example/google_search.js +0 -50
- package/example/google_search_test.js +0 -72
- package/example/headless.js +0 -55
- package/example/logging.js +0 -68
- package/jasmine.json +0 -11
- package/lib/atoms/BUILD.bazel +0 -28
- package/lib/test/bootstrap_jasmine.js +0 -28
- package/lib/test/build.js +0 -156
- package/lib/test/data/actions/click.html +0 -24
- package/lib/test/data/actions/drag.html +0 -77
- package/lib/test/data/actions/record_click.html +0 -21
- package/lib/test/data/chrome/download.html +0 -2
- package/lib/test/data/firefox/webextension.xpi +0 -0
- package/lib/test/fileserver.js +0 -337
- package/lib/test/httpserver.js +0 -120
- package/lib/test/index.js +0 -87
- package/lib/test/resources.js +0 -40
- package/test/actions_test.js +0 -206
- package/test/builder_test.js +0 -106
- package/test/chrome/devtools_test.js +0 -93
- package/test/chrome/options_test.js +0 -121
- package/test/chrome/service_test.js +0 -45
- package/test/cookie_test.js +0 -210
- package/test/element_finding_test.js +0 -431
- package/test/execute_script_test.js +0 -355
- package/test/fingerprint_test.js +0 -63
- package/test/firefox_test.js +0 -233
- package/test/frame_test.js +0 -45
- package/test/http/http_test.js +0 -229
- package/test/http/util_test.js +0 -178
- package/test/io/io_test.js +0 -364
- package/test/io/zip_test.js +0 -126
- package/test/lib/by_test.js +0 -160
- package/test/lib/capabilities_test.js +0 -129
- package/test/lib/error_test.js +0 -333
- package/test/lib/http_test.js +0 -576
- package/test/lib/input_test.js +0 -1379
- package/test/lib/logging_test.js +0 -272
- package/test/lib/promise_test.js +0 -674
- package/test/lib/testutil.js +0 -90
- package/test/lib/until_test.js +0 -478
- package/test/lib/webdriver_test.js +0 -1692
- package/test/logging_test.js +0 -160
- package/test/net/index_test.js +0 -60
- package/test/net/portprober_test.js +0 -128
- package/test/page_loading_test.js +0 -156
- package/test/proxy_test.js +0 -167
- package/test/rect_test.js +0 -51
- package/test/remote_test.js +0 -98
- package/test/safari_test.js +0 -44
- package/test/stale_element_test.js +0 -60
- package/test/upload_test.js +0 -78
- package/test/window_test.js +0 -168
- package/testing/index.js +0 -498
- package/tools/init_jasmine.js +0 -7
|
@@ -1,1692 +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 {StubError, assertIsInstance, assertIsStubError, throwStubError} =
|
|
21
|
-
require('./testutil');
|
|
22
|
-
|
|
23
|
-
const error = require('../../lib/error');
|
|
24
|
-
const logging = require('../../lib/logging');
|
|
25
|
-
const promise = require('../../lib/promise');
|
|
26
|
-
const until = require('../../lib/until');
|
|
27
|
-
const {Alert, AlertPromise, WebDriver, WebElement, WebElementPromise} =
|
|
28
|
-
require('../../lib/webdriver');
|
|
29
|
-
const {Button, Key} = require('../../lib/input');
|
|
30
|
-
const {By} = require('../../lib/by');
|
|
31
|
-
const {Capabilities} = require('../../lib/capabilities');
|
|
32
|
-
const {Executor, Name} = require('../../lib/command');
|
|
33
|
-
const {Session} = require('../../lib/session');
|
|
34
|
-
|
|
35
|
-
const assert = require('assert');
|
|
36
|
-
const sinon = require('sinon');
|
|
37
|
-
|
|
38
|
-
const CName = Name;
|
|
39
|
-
|
|
40
|
-
const SESSION_ID = 'test_session_id';
|
|
41
|
-
const fail = (msg) => assert.fail(msg);
|
|
42
|
-
|
|
43
|
-
describe('WebDriver', function() {
|
|
44
|
-
const LOG = logging.getLogger('webdriver.test');
|
|
45
|
-
|
|
46
|
-
var driver;
|
|
47
|
-
|
|
48
|
-
function defer() {
|
|
49
|
-
let d = {};
|
|
50
|
-
let promise = new Promise((resolve, reject) => {
|
|
51
|
-
Object.assign(d, {resolve, reject});
|
|
52
|
-
});
|
|
53
|
-
d.promise = promise;
|
|
54
|
-
return d;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function expectedError(ctor, message) {
|
|
58
|
-
return function(e) {
|
|
59
|
-
assertIsInstance(ctor, e);
|
|
60
|
-
assert.equal(message, e.message);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
class Expectation {
|
|
65
|
-
constructor(executor, name, opt_parameters) {
|
|
66
|
-
this.executor_ = executor;
|
|
67
|
-
this.name_ = name;
|
|
68
|
-
this.times_ = 1;
|
|
69
|
-
this.sessionId_ = SESSION_ID;
|
|
70
|
-
this.check_ = null;
|
|
71
|
-
this.toDo_ = null;
|
|
72
|
-
this.withParameters(opt_parameters || {});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
anyTimes() {
|
|
76
|
-
this.times_ = Infinity;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
times(n) {
|
|
81
|
-
this.times_ = n;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
withParameters(parameters) {
|
|
86
|
-
this.parameters_ = parameters;
|
|
87
|
-
if (this.name_ !== CName.NEW_SESSION) {
|
|
88
|
-
this.parameters_['sessionId'] = this.sessionId_;
|
|
89
|
-
}
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
andReturn(code, opt_value) {
|
|
94
|
-
this.toDo_ = function(command) {
|
|
95
|
-
LOG.info('executing ' + command.getName() + '; returning ' + code);
|
|
96
|
-
return Promise.resolve(opt_value !== void(0) ? opt_value : null);
|
|
97
|
-
};
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
andReturnSuccess(opt_value) {
|
|
102
|
-
this.toDo_ = function(command) {
|
|
103
|
-
LOG.info('executing ' + command.getName() + '; returning success');
|
|
104
|
-
return Promise.resolve(opt_value !== void(0) ? opt_value : null);
|
|
105
|
-
};
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
andReturnError(error) {
|
|
110
|
-
if (typeof error === 'number') {
|
|
111
|
-
throw Error('need error type');
|
|
112
|
-
}
|
|
113
|
-
this.toDo_ = function(command) {
|
|
114
|
-
LOG.info('executing ' + command.getName() + '; returning failure');
|
|
115
|
-
return Promise.reject(error);
|
|
116
|
-
};
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
expect(name, opt_parameters) {
|
|
121
|
-
this.end();
|
|
122
|
-
return this.executor_.expect(name, opt_parameters);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
end() {
|
|
126
|
-
if (!this.toDo_) {
|
|
127
|
-
this.andReturnSuccess(null);
|
|
128
|
-
}
|
|
129
|
-
return this.executor_;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
execute(command) {
|
|
133
|
-
assert.deepEqual(command.getParameters(), this.parameters_);
|
|
134
|
-
return this.toDo_(command);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class FakeExecutor {
|
|
139
|
-
constructor() {
|
|
140
|
-
this.commands_ = new Map;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
execute(command) {
|
|
144
|
-
let expectations = this.commands_.get(command.getName());
|
|
145
|
-
if (!expectations || !expectations.length) {
|
|
146
|
-
assert.fail('unexpected command: ' + command.getName());
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
let next = expectations[0];
|
|
151
|
-
let result = next.execute(command);
|
|
152
|
-
if (next.times_ != Infinity) {
|
|
153
|
-
next.times_ -= 1;
|
|
154
|
-
if (!next.times_) {
|
|
155
|
-
expectations.shift();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
expect(commandName, opt_parameters) {
|
|
162
|
-
if (!this.commands_.has(commandName)) {
|
|
163
|
-
this.commands_.set(commandName, []);
|
|
164
|
-
}
|
|
165
|
-
let e = new Expectation(this, commandName, opt_parameters);
|
|
166
|
-
this.commands_.get(commandName).push(e);
|
|
167
|
-
return e;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
createDriver(opt_session) {
|
|
171
|
-
let session = opt_session || new Session(SESSION_ID, {});
|
|
172
|
-
return new WebDriver(session, this);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
178
|
-
//
|
|
179
|
-
// Tests
|
|
180
|
-
//
|
|
181
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
describe('testCreateSession', function() {
|
|
185
|
-
it('happyPathWithCapabilitiesHashObject', function() {
|
|
186
|
-
let aSession = new Session(SESSION_ID, {'browserName': 'firefox'});
|
|
187
|
-
let executor = new FakeExecutor().
|
|
188
|
-
expect(CName.NEW_SESSION).
|
|
189
|
-
withParameters({
|
|
190
|
-
'desiredCapabilities': {'browserName': 'firefox'},
|
|
191
|
-
'capabilities': {
|
|
192
|
-
'alwaysMatch': {'browserName': 'firefox'},
|
|
193
|
-
},
|
|
194
|
-
}).
|
|
195
|
-
andReturnSuccess(aSession).
|
|
196
|
-
end();
|
|
197
|
-
|
|
198
|
-
var driver = WebDriver.createSession(executor, {
|
|
199
|
-
'browserName': 'firefox'
|
|
200
|
-
});
|
|
201
|
-
return driver.getSession().then(v => assert.strictEqual(v, aSession));
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('happyPathWithCapabilitiesInstance', function() {
|
|
205
|
-
let aSession = new Session(SESSION_ID, {'browserName': 'firefox'});
|
|
206
|
-
let executor = new FakeExecutor().
|
|
207
|
-
expect(CName.NEW_SESSION).
|
|
208
|
-
withParameters({
|
|
209
|
-
'desiredCapabilities': {'browserName': 'firefox'},
|
|
210
|
-
'capabilities': {
|
|
211
|
-
'alwaysMatch': {'browserName': 'firefox'},
|
|
212
|
-
},
|
|
213
|
-
}).
|
|
214
|
-
andReturnSuccess(aSession).
|
|
215
|
-
end();
|
|
216
|
-
|
|
217
|
-
var driver = WebDriver.createSession(executor, Capabilities.firefox());
|
|
218
|
-
return driver.getSession().then(v => assert.strictEqual(v, aSession));
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('drops non-W3C capability names from W3C capabilities', function() {
|
|
222
|
-
let aSession = new Session(SESSION_ID, {'browserName': 'firefox'});
|
|
223
|
-
let executor = new FakeExecutor().
|
|
224
|
-
expect(CName.NEW_SESSION).
|
|
225
|
-
withParameters({
|
|
226
|
-
'desiredCapabilities': {'browserName': 'firefox', 'foo': 'bar'},
|
|
227
|
-
'capabilities': {
|
|
228
|
-
'alwaysMatch': {'browserName': 'firefox'},
|
|
229
|
-
},
|
|
230
|
-
}).
|
|
231
|
-
andReturnSuccess(aSession).
|
|
232
|
-
end();
|
|
233
|
-
|
|
234
|
-
var driver = WebDriver.createSession(executor, {
|
|
235
|
-
'browserName': 'firefox',
|
|
236
|
-
'foo': 'bar',
|
|
237
|
-
});
|
|
238
|
-
return driver.getSession().then(v => assert.strictEqual(v, aSession));
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('failsToCreateSession', function() {
|
|
242
|
-
let executor = new FakeExecutor().
|
|
243
|
-
expect(CName.NEW_SESSION).
|
|
244
|
-
withParameters({
|
|
245
|
-
'desiredCapabilities': {'browserName': 'firefox'},
|
|
246
|
-
'capabilities': {
|
|
247
|
-
'alwaysMatch': {'browserName': 'firefox'},
|
|
248
|
-
},
|
|
249
|
-
}).
|
|
250
|
-
andReturnError(new StubError()).
|
|
251
|
-
end();
|
|
252
|
-
|
|
253
|
-
var driver =
|
|
254
|
-
WebDriver.createSession(executor, {'browserName': 'firefox'});
|
|
255
|
-
return driver.getSession().then(fail, assertIsStubError);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('invokes quit callback if it fails to create a session', function() {
|
|
259
|
-
let called = false;
|
|
260
|
-
let executor = new FakeExecutor()
|
|
261
|
-
.expect(CName.NEW_SESSION)
|
|
262
|
-
.withParameters({
|
|
263
|
-
'desiredCapabilities': {'browserName': 'firefox'},
|
|
264
|
-
'capabilities': {
|
|
265
|
-
'alwaysMatch': {'browserName': 'firefox'},
|
|
266
|
-
},
|
|
267
|
-
})
|
|
268
|
-
.andReturnError(new StubError())
|
|
269
|
-
.end();
|
|
270
|
-
|
|
271
|
-
let driver =
|
|
272
|
-
WebDriver.createSession(
|
|
273
|
-
executor, {'browserName': 'firefox'}, () => called = true);
|
|
274
|
-
return driver.getSession().then(fail, err => {
|
|
275
|
-
assert.ok(called);
|
|
276
|
-
assertIsStubError(err);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('testDoesNotExecuteCommandIfSessionDoesNotResolve', function() {
|
|
282
|
-
var session = Promise.reject(new StubError);
|
|
283
|
-
return new FakeExecutor().createDriver(session)
|
|
284
|
-
.getTitle()
|
|
285
|
-
.then(_ => assert.fail('should have failed'), assertIsStubError);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('testCommandReturnValuesArePassedToFirstCallback', function() {
|
|
289
|
-
let executor = new FakeExecutor().
|
|
290
|
-
expect(CName.GET_TITLE).andReturnSuccess('Google Search').
|
|
291
|
-
end();
|
|
292
|
-
|
|
293
|
-
var driver = executor.createDriver();
|
|
294
|
-
return driver.getTitle()
|
|
295
|
-
.then(title => assert.equal('Google Search', title));
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it('testStopsCommandExecutionWhenAnErrorOccurs', function() {
|
|
299
|
-
let e = new error.NoSuchWindowError('window not found');
|
|
300
|
-
let executor = new FakeExecutor().
|
|
301
|
-
expect(CName.SWITCH_TO_WINDOW).
|
|
302
|
-
withParameters({
|
|
303
|
-
'name': 'foo',
|
|
304
|
-
'handle': 'foo'
|
|
305
|
-
}).
|
|
306
|
-
andReturnError(e).
|
|
307
|
-
end();
|
|
308
|
-
|
|
309
|
-
let driver = executor.createDriver();
|
|
310
|
-
return driver.switchTo().window('foo')
|
|
311
|
-
.then(
|
|
312
|
-
_ => driver.getTitle(), // mock should blow if this gets executed
|
|
313
|
-
v => assert.strictEqual(v, e));
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('testReportsErrorWhenExecutingCommandsAfterExecutingAQuit', function() {
|
|
317
|
-
let executor = new FakeExecutor().
|
|
318
|
-
expect(CName.QUIT).
|
|
319
|
-
end();
|
|
320
|
-
|
|
321
|
-
let verifyError = expectedError(
|
|
322
|
-
error.NoSuchSessionError,
|
|
323
|
-
'This driver instance does not have a valid session ID ' +
|
|
324
|
-
'(did you call WebDriver.quit()?) and may no longer be used.');
|
|
325
|
-
|
|
326
|
-
let driver = executor.createDriver();
|
|
327
|
-
return driver.quit()
|
|
328
|
-
.then(_ => driver.get('http://www.google.com'))
|
|
329
|
-
.then(assert.fail, verifyError);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
describe('returningAPromise', function() {
|
|
333
|
-
it('fromACallback', function() {
|
|
334
|
-
let executor = new FakeExecutor().
|
|
335
|
-
expect(CName.GET_TITLE).
|
|
336
|
-
expect(CName.GET_CURRENT_URL).
|
|
337
|
-
andReturnSuccess('http://www.google.com').
|
|
338
|
-
end();
|
|
339
|
-
|
|
340
|
-
var driver = executor.createDriver();
|
|
341
|
-
return driver.getTitle().
|
|
342
|
-
then(function() {
|
|
343
|
-
return driver.getCurrentUrl();
|
|
344
|
-
}).
|
|
345
|
-
then(function(value) {
|
|
346
|
-
assert.equal('http://www.google.com', value);
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it('fromAnErrbackSuppressesTheError', function() {
|
|
351
|
-
let executor = new FakeExecutor().
|
|
352
|
-
expect(CName.SWITCH_TO_WINDOW, {
|
|
353
|
-
'name': 'foo',
|
|
354
|
-
'handle': 'foo'
|
|
355
|
-
}).
|
|
356
|
-
andReturnError(new StubError()).
|
|
357
|
-
expect(CName.GET_CURRENT_URL).
|
|
358
|
-
andReturnSuccess('http://www.google.com').
|
|
359
|
-
end();
|
|
360
|
-
|
|
361
|
-
var driver = executor.createDriver();
|
|
362
|
-
return driver.switchTo().window('foo').
|
|
363
|
-
catch(function(e) {
|
|
364
|
-
assertIsStubError(e);
|
|
365
|
-
return driver.getCurrentUrl();
|
|
366
|
-
}).
|
|
367
|
-
then(url => assert.equal('http://www.google.com', url));
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
describe('WebElementPromise', function() {
|
|
372
|
-
let driver = new FakeExecutor().createDriver();
|
|
373
|
-
|
|
374
|
-
it('resolvesWhenUnderlyingElementDoes', function() {
|
|
375
|
-
let el = new WebElement(driver, {'ELEMENT': 'foo'});
|
|
376
|
-
return new WebElementPromise(driver, Promise.resolve(el))
|
|
377
|
-
.then(e => assert.strictEqual(e, el));
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it('resolvesBeforeCallbacksOnWireValueTrigger', function() {
|
|
381
|
-
var el = defer();
|
|
382
|
-
|
|
383
|
-
var element = new WebElementPromise(driver, el.promise);
|
|
384
|
-
var messages = [];
|
|
385
|
-
|
|
386
|
-
let steps = [
|
|
387
|
-
element.then(_ => messages.push('element resolved')),
|
|
388
|
-
element.getId().then(_ => messages.push('wire value resolved'))
|
|
389
|
-
];
|
|
390
|
-
|
|
391
|
-
el.resolve(new WebElement(driver, {'ELEMENT': 'foo'}));
|
|
392
|
-
return Promise.all(steps).then(function() {
|
|
393
|
-
assert.deepEqual([
|
|
394
|
-
'element resolved',
|
|
395
|
-
'wire value resolved'
|
|
396
|
-
], messages);
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it('isRejectedIfUnderlyingIdIsRejected', function() {
|
|
401
|
-
let element =
|
|
402
|
-
new WebElementPromise(driver, Promise.reject(new StubError));
|
|
403
|
-
return element.then(fail, assertIsStubError);
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
describe('executeScript', function() {
|
|
408
|
-
it('nullReturnValue', function() {
|
|
409
|
-
let executor = new FakeExecutor().
|
|
410
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
411
|
-
withParameters({
|
|
412
|
-
'script': 'return document.body;',
|
|
413
|
-
'args': []
|
|
414
|
-
}).
|
|
415
|
-
andReturnSuccess(null).
|
|
416
|
-
end();
|
|
417
|
-
|
|
418
|
-
var driver = executor.createDriver();
|
|
419
|
-
return driver.executeScript('return document.body;')
|
|
420
|
-
.then((result) => assert.equal(null, result));
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
it('primitiveReturnValue', function() {
|
|
424
|
-
let executor = new FakeExecutor().
|
|
425
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
426
|
-
withParameters({
|
|
427
|
-
'script': 'return document.body;',
|
|
428
|
-
'args': []
|
|
429
|
-
}).
|
|
430
|
-
andReturnSuccess(123).
|
|
431
|
-
end();
|
|
432
|
-
|
|
433
|
-
var driver = executor.createDriver();
|
|
434
|
-
return driver.executeScript('return document.body;')
|
|
435
|
-
.then((result) => assert.equal(123, result));
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
it('webElementReturnValue', function() {
|
|
439
|
-
var json = WebElement.buildId('foo');
|
|
440
|
-
|
|
441
|
-
let executor = new FakeExecutor().
|
|
442
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
443
|
-
withParameters({
|
|
444
|
-
'script': 'return document.body;',
|
|
445
|
-
'args': []
|
|
446
|
-
}).
|
|
447
|
-
andReturnSuccess(json).
|
|
448
|
-
end();
|
|
449
|
-
|
|
450
|
-
var driver = executor.createDriver();
|
|
451
|
-
return driver.executeScript('return document.body;')
|
|
452
|
-
.then((element) => element.getId())
|
|
453
|
-
.then((id) => assert.equal(id, 'foo'));
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
it('arrayReturnValue', function() {
|
|
457
|
-
var json = [WebElement.buildId('foo')];
|
|
458
|
-
|
|
459
|
-
let executor = new FakeExecutor().
|
|
460
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
461
|
-
withParameters({
|
|
462
|
-
'script': 'return document.body;',
|
|
463
|
-
'args': []
|
|
464
|
-
}).
|
|
465
|
-
andReturnSuccess(json).
|
|
466
|
-
end();
|
|
467
|
-
|
|
468
|
-
var driver = executor.createDriver();
|
|
469
|
-
return driver.executeScript('return document.body;')
|
|
470
|
-
.then(function(array) {
|
|
471
|
-
assert.equal(1, array.length);
|
|
472
|
-
return array[0].getId();
|
|
473
|
-
})
|
|
474
|
-
.then((id) => assert.equal('foo', id));
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it('objectReturnValue', function() {
|
|
478
|
-
var json = {'foo': WebElement.buildId('foo')};
|
|
479
|
-
|
|
480
|
-
let executor = new FakeExecutor().
|
|
481
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
482
|
-
withParameters({
|
|
483
|
-
'script': 'return document.body;',
|
|
484
|
-
'args': []
|
|
485
|
-
}).
|
|
486
|
-
andReturnSuccess(json).
|
|
487
|
-
end();
|
|
488
|
-
|
|
489
|
-
var driver = executor.createDriver();
|
|
490
|
-
var callback;
|
|
491
|
-
return driver.executeScript('return document.body;')
|
|
492
|
-
.then((obj) => obj['foo'].getId())
|
|
493
|
-
.then((id) => assert.equal(id, 'foo'));
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
it('scriptAsFunction', function() {
|
|
497
|
-
let executor = new FakeExecutor().
|
|
498
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
499
|
-
withParameters({
|
|
500
|
-
'script': 'return (' + function() {} +
|
|
501
|
-
').apply(null, arguments);',
|
|
502
|
-
'args': []
|
|
503
|
-
}).
|
|
504
|
-
andReturnSuccess(null).
|
|
505
|
-
end();
|
|
506
|
-
|
|
507
|
-
var driver = executor.createDriver();
|
|
508
|
-
return driver.executeScript(function() {});
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it('simpleArgumentConversion', function() {
|
|
512
|
-
let executor = new FakeExecutor().
|
|
513
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
514
|
-
withParameters({
|
|
515
|
-
'script': 'return 1;',
|
|
516
|
-
'args': ['abc', 123, true, [123, {'foo': 'bar'}]]
|
|
517
|
-
}).
|
|
518
|
-
andReturnSuccess(null).
|
|
519
|
-
end();
|
|
520
|
-
|
|
521
|
-
var driver = executor.createDriver();
|
|
522
|
-
return driver.executeScript(
|
|
523
|
-
'return 1;', 'abc', 123, true, [123, {'foo': 'bar'}]);
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
it('webElementArgumentConversion', function() {
|
|
527
|
-
var elementJson = WebElement.buildId('fefifofum');
|
|
528
|
-
|
|
529
|
-
let executor = new FakeExecutor().
|
|
530
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
531
|
-
withParameters({
|
|
532
|
-
'script': 'return 1;',
|
|
533
|
-
'args': [elementJson]
|
|
534
|
-
}).
|
|
535
|
-
andReturnSuccess(null).
|
|
536
|
-
end();
|
|
537
|
-
|
|
538
|
-
var driver = executor.createDriver();
|
|
539
|
-
return driver.executeScript('return 1;',
|
|
540
|
-
new WebElement(driver, 'fefifofum'));
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
it('webElementPromiseArgumentConversion', function() {
|
|
544
|
-
var elementJson = WebElement.buildId('bar');
|
|
545
|
-
|
|
546
|
-
let executor = new FakeExecutor().
|
|
547
|
-
expect(CName.FIND_ELEMENT,
|
|
548
|
-
{'using': 'css selector', 'value': '*[id="foo"]'}).
|
|
549
|
-
andReturnSuccess(elementJson).
|
|
550
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
551
|
-
withParameters({
|
|
552
|
-
'script': 'return 1;',
|
|
553
|
-
'args': [elementJson]
|
|
554
|
-
}).
|
|
555
|
-
andReturnSuccess(null).
|
|
556
|
-
end();
|
|
557
|
-
|
|
558
|
-
var driver = executor.createDriver();
|
|
559
|
-
var element = driver.findElement(By.id('foo'));
|
|
560
|
-
return driver.executeScript('return 1;', element);
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
it('argumentConversion', function() {
|
|
564
|
-
var elementJson = WebElement.buildId('fefifofum');
|
|
565
|
-
|
|
566
|
-
let executor = new FakeExecutor().
|
|
567
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
568
|
-
withParameters({
|
|
569
|
-
'script': 'return 1;',
|
|
570
|
-
'args': ['abc', 123, true, elementJson, [123, {'foo': 'bar'}]]
|
|
571
|
-
}).
|
|
572
|
-
andReturnSuccess(null).
|
|
573
|
-
end();
|
|
574
|
-
|
|
575
|
-
var driver = executor.createDriver();
|
|
576
|
-
var element = new WebElement(driver, 'fefifofum');
|
|
577
|
-
return driver.executeScript('return 1;',
|
|
578
|
-
'abc', 123, true, element, [123, {'foo': 'bar'}]);
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
it('scriptReturnsAnError', function() {
|
|
582
|
-
let executor = new FakeExecutor().
|
|
583
|
-
expect(CName.EXECUTE_SCRIPT).
|
|
584
|
-
withParameters({
|
|
585
|
-
'script': 'throw Error(arguments[0]);',
|
|
586
|
-
'args': ['bam']
|
|
587
|
-
}).
|
|
588
|
-
andReturnError(new StubError).
|
|
589
|
-
end();
|
|
590
|
-
var driver = executor.createDriver();
|
|
591
|
-
return driver.executeScript('throw Error(arguments[0]);', 'bam').
|
|
592
|
-
then(fail, assertIsStubError);
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
it('failsIfArgumentIsARejectedPromise', function() {
|
|
596
|
-
let executor = new FakeExecutor();
|
|
597
|
-
|
|
598
|
-
var arg = Promise.reject(new StubError);
|
|
599
|
-
arg.catch(function() {}); // Suppress default handler.
|
|
600
|
-
|
|
601
|
-
var driver = executor.createDriver();
|
|
602
|
-
return driver.executeScript(function() {}, arg).
|
|
603
|
-
then(fail, assertIsStubError);
|
|
604
|
-
});
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
describe('executeAsyncScript', function() {
|
|
608
|
-
it('failsIfArgumentIsARejectedPromise', function() {
|
|
609
|
-
var arg = Promise.reject(new StubError);
|
|
610
|
-
arg.catch(function() {}); // Suppress default handler.
|
|
611
|
-
|
|
612
|
-
var driver = new FakeExecutor().createDriver();
|
|
613
|
-
return driver.executeAsyncScript(function() {}, arg).
|
|
614
|
-
then(fail, assertIsStubError);
|
|
615
|
-
});
|
|
616
|
-
});
|
|
617
|
-
|
|
618
|
-
describe('findElement', function() {
|
|
619
|
-
it('elementNotFound', function() {
|
|
620
|
-
let executor = new FakeExecutor().
|
|
621
|
-
expect(CName.FIND_ELEMENT,
|
|
622
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
623
|
-
andReturnError(new StubError).
|
|
624
|
-
end();
|
|
625
|
-
|
|
626
|
-
var driver = executor.createDriver();
|
|
627
|
-
return driver.findElement(By.id('foo'))
|
|
628
|
-
.then(assert.fail, assertIsStubError);
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
it('elementNotFoundInACallback', function() {
|
|
632
|
-
let executor = new FakeExecutor().
|
|
633
|
-
expect(CName.FIND_ELEMENT,
|
|
634
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
635
|
-
andReturnError(new StubError).
|
|
636
|
-
end();
|
|
637
|
-
|
|
638
|
-
var driver = executor.createDriver();
|
|
639
|
-
return Promise.resolve()
|
|
640
|
-
.then(_ => driver.findElement(By.id('foo')))
|
|
641
|
-
.then(assert.fail, assertIsStubError);
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
it('elementFound', function() {
|
|
645
|
-
let executor = new FakeExecutor().
|
|
646
|
-
expect(CName.FIND_ELEMENT,
|
|
647
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
648
|
-
andReturnSuccess(WebElement.buildId('bar')).
|
|
649
|
-
expect(CName.CLICK_ELEMENT, {'id': WebElement.buildId('bar')}).
|
|
650
|
-
andReturnSuccess().
|
|
651
|
-
end();
|
|
652
|
-
|
|
653
|
-
var driver = executor.createDriver();
|
|
654
|
-
var element = driver.findElement(By.id('foo'));
|
|
655
|
-
return element.click();
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
it('canUseElementInCallback', function() {
|
|
659
|
-
let executor = new FakeExecutor().
|
|
660
|
-
expect(CName.FIND_ELEMENT,
|
|
661
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
662
|
-
andReturnSuccess(WebElement.buildId('bar')).
|
|
663
|
-
expect(CName.CLICK_ELEMENT, {'id': WebElement.buildId('bar')}).
|
|
664
|
-
andReturnSuccess().
|
|
665
|
-
end();
|
|
666
|
-
|
|
667
|
-
var driver = executor.createDriver();
|
|
668
|
-
return driver.findElement(By.id('foo')).then(e => e.click());
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
it('byJs', function() {
|
|
672
|
-
let executor = new FakeExecutor().
|
|
673
|
-
expect(CName.EXECUTE_SCRIPT, {
|
|
674
|
-
'script': 'return document.body',
|
|
675
|
-
'args': []
|
|
676
|
-
}).
|
|
677
|
-
andReturnSuccess(WebElement.buildId('bar')).
|
|
678
|
-
expect(CName.CLICK_ELEMENT, {'id': WebElement.buildId('bar')}).
|
|
679
|
-
end();
|
|
680
|
-
|
|
681
|
-
var driver = executor.createDriver();
|
|
682
|
-
return driver.findElement(By.js('return document.body'))
|
|
683
|
-
.then(e => e.click());
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
it('byJs_returnsNonWebElementValue', function() {
|
|
687
|
-
let executor = new FakeExecutor().
|
|
688
|
-
expect(CName.EXECUTE_SCRIPT, {'script': 'return 123', 'args': []}).
|
|
689
|
-
andReturnSuccess(123).
|
|
690
|
-
end();
|
|
691
|
-
|
|
692
|
-
var driver = executor.createDriver();
|
|
693
|
-
return driver.findElement(By.js('return 123'))
|
|
694
|
-
.then(assert.fail, function(e) {
|
|
695
|
-
assertIsInstance(TypeError, e);
|
|
696
|
-
assert.equal(
|
|
697
|
-
'Custom locator did not return a WebElement', e.message);
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
it('byJs_canPassArguments', function() {
|
|
702
|
-
var script = 'return document.getElementsByTagName(arguments[0]);';
|
|
703
|
-
let executor = new FakeExecutor().
|
|
704
|
-
expect(CName.EXECUTE_SCRIPT, {
|
|
705
|
-
'script': script,
|
|
706
|
-
'args': ['div']
|
|
707
|
-
}).
|
|
708
|
-
andReturnSuccess(WebElement.buildId('one')).
|
|
709
|
-
end();
|
|
710
|
-
var driver = executor.createDriver();
|
|
711
|
-
return driver.findElement(By.js(script, 'div'));
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
it('customLocator', function() {
|
|
715
|
-
let executor = new FakeExecutor().
|
|
716
|
-
expect(CName.FIND_ELEMENTS, {'using': 'css selector', 'value': 'a'}).
|
|
717
|
-
andReturnSuccess([
|
|
718
|
-
WebElement.buildId('foo'),
|
|
719
|
-
WebElement.buildId('bar')]).
|
|
720
|
-
expect(CName.CLICK_ELEMENT, {'id': WebElement.buildId('foo')}).
|
|
721
|
-
andReturnSuccess().
|
|
722
|
-
end();
|
|
723
|
-
|
|
724
|
-
var driver = executor.createDriver();
|
|
725
|
-
var element = driver.findElement(function(d) {
|
|
726
|
-
assert.equal(driver, d);
|
|
727
|
-
return d.findElements(By.tagName('a'));
|
|
728
|
-
});
|
|
729
|
-
return element.click();
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
it('customLocatorThrowsIfresultIsNotAWebElement', function() {
|
|
733
|
-
var driver = new FakeExecutor().createDriver();
|
|
734
|
-
return driver.findElement(_ => 1)
|
|
735
|
-
.then(assert.fail, function(e) {
|
|
736
|
-
assertIsInstance(TypeError, e);
|
|
737
|
-
assert.equal(
|
|
738
|
-
'Custom locator did not return a WebElement', e.message);
|
|
739
|
-
});
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
describe('findElements', function() {
|
|
744
|
-
it('returnsMultipleElements', function() {
|
|
745
|
-
var ids = ['foo', 'bar', 'baz'];
|
|
746
|
-
let executor = new FakeExecutor().
|
|
747
|
-
expect(CName.FIND_ELEMENTS, {'using':'css selector', 'value':'a'}).
|
|
748
|
-
andReturnSuccess(ids.map(WebElement.buildId)).
|
|
749
|
-
end();
|
|
750
|
-
|
|
751
|
-
var driver = executor.createDriver();
|
|
752
|
-
return driver.findElements(By.tagName('a'))
|
|
753
|
-
.then(function(elements) {
|
|
754
|
-
return Promise.all(elements.map(function(e) {
|
|
755
|
-
assert.ok(e instanceof WebElement);
|
|
756
|
-
return e.getId();
|
|
757
|
-
}));
|
|
758
|
-
})
|
|
759
|
-
.then((actual) => assert.deepEqual(ids, actual));
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
it('byJs', function() {
|
|
763
|
-
var ids = ['foo', 'bar', 'baz'];
|
|
764
|
-
let executor = new FakeExecutor().
|
|
765
|
-
expect(CName.EXECUTE_SCRIPT, {
|
|
766
|
-
'script': 'return document.getElementsByTagName("div");',
|
|
767
|
-
'args': []
|
|
768
|
-
}).
|
|
769
|
-
andReturnSuccess(ids.map(WebElement.buildId)).
|
|
770
|
-
end();
|
|
771
|
-
|
|
772
|
-
var driver = executor.createDriver();
|
|
773
|
-
|
|
774
|
-
return driver.
|
|
775
|
-
findElements(By.js('return document.getElementsByTagName("div");')).
|
|
776
|
-
then(function(elements) {
|
|
777
|
-
return Promise.all(elements.map(function(e) {
|
|
778
|
-
assert.ok(e instanceof WebElement);
|
|
779
|
-
return e.getId();
|
|
780
|
-
}));
|
|
781
|
-
}).
|
|
782
|
-
then((actual) => assert.deepEqual(ids, actual));
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
it('byJs_filtersOutNonWebElementResponses', function() {
|
|
786
|
-
var ids = ['foo', 'bar', 'baz'];
|
|
787
|
-
var json = [
|
|
788
|
-
WebElement.buildId(ids[0]),
|
|
789
|
-
123,
|
|
790
|
-
'a',
|
|
791
|
-
false,
|
|
792
|
-
WebElement.buildId(ids[1]),
|
|
793
|
-
{'not a web element': 1},
|
|
794
|
-
WebElement.buildId(ids[2])
|
|
795
|
-
];
|
|
796
|
-
let executor = new FakeExecutor().
|
|
797
|
-
expect(CName.EXECUTE_SCRIPT, {
|
|
798
|
-
'script': 'return document.getElementsByTagName("div");',
|
|
799
|
-
'args': []
|
|
800
|
-
}).
|
|
801
|
-
andReturnSuccess(json).
|
|
802
|
-
end();
|
|
803
|
-
|
|
804
|
-
var driver = executor.createDriver();
|
|
805
|
-
return driver.findElements(By.js('return document.getElementsByTagName("div");')).
|
|
806
|
-
then(function(elements) {
|
|
807
|
-
return Promise.all(elements.map(function(e) {
|
|
808
|
-
assert.ok(e instanceof WebElement);
|
|
809
|
-
return e.getId();
|
|
810
|
-
}));
|
|
811
|
-
}).
|
|
812
|
-
then((actual) => assert.deepEqual(ids, actual));
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
it('byJs_convertsSingleWebElementResponseToArray', function() {
|
|
816
|
-
let executor = new FakeExecutor().
|
|
817
|
-
expect(CName.EXECUTE_SCRIPT, {
|
|
818
|
-
'script': 'return document.getElementsByTagName("div");',
|
|
819
|
-
'args': []
|
|
820
|
-
}).
|
|
821
|
-
andReturnSuccess(WebElement.buildId('foo')).
|
|
822
|
-
end();
|
|
823
|
-
|
|
824
|
-
var driver = executor.createDriver();
|
|
825
|
-
return driver.
|
|
826
|
-
findElements(By.js('return document.getElementsByTagName("div");')).
|
|
827
|
-
then(function(elements) {
|
|
828
|
-
return Promise.all(elements.map(function(e) {
|
|
829
|
-
assert.ok(e instanceof WebElement);
|
|
830
|
-
return e.getId();
|
|
831
|
-
}));
|
|
832
|
-
}).
|
|
833
|
-
then((actual) => assert.deepEqual(['foo'], actual));
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
it('byJs_canPassScriptArguments', function() {
|
|
837
|
-
var script = 'return document.getElementsByTagName(arguments[0]);';
|
|
838
|
-
let executor = new FakeExecutor().
|
|
839
|
-
expect(CName.EXECUTE_SCRIPT, {
|
|
840
|
-
'script': script,
|
|
841
|
-
'args': ['div']
|
|
842
|
-
}).
|
|
843
|
-
andReturnSuccess([
|
|
844
|
-
WebElement.buildId('one'),
|
|
845
|
-
WebElement.buildId('two')
|
|
846
|
-
]).
|
|
847
|
-
end();
|
|
848
|
-
|
|
849
|
-
var driver = executor.createDriver();
|
|
850
|
-
return driver.findElements(By.js(script, 'div'))
|
|
851
|
-
then(function(elements) {
|
|
852
|
-
return Promise.all(elements.map(function(e) {
|
|
853
|
-
assert.ok(e instanceof WebElement);
|
|
854
|
-
return e.getId();
|
|
855
|
-
}));
|
|
856
|
-
}).
|
|
857
|
-
then((actual) => assert.deepEqual(['one', 'two'], actual));
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
describe('sendKeys', function() {
|
|
862
|
-
it('convertsVarArgsIntoStrings_simpleArgs', function() {
|
|
863
|
-
let executor = new FakeExecutor().
|
|
864
|
-
expect(CName.SEND_KEYS_TO_ELEMENT,
|
|
865
|
-
{'id': WebElement.buildId('one'),
|
|
866
|
-
'text': '12abc3',
|
|
867
|
-
'value':'12abc3'.split('')}).
|
|
868
|
-
andReturnSuccess().
|
|
869
|
-
end();
|
|
870
|
-
|
|
871
|
-
var driver = executor.createDriver();
|
|
872
|
-
var element = new WebElement(driver, 'one');
|
|
873
|
-
return element.sendKeys(1, 2, 'abc', 3);
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
it('convertsVarArgsIntoStrings_promisedArgs', function() {
|
|
877
|
-
let executor = new FakeExecutor().
|
|
878
|
-
expect(CName.FIND_ELEMENT,
|
|
879
|
-
{'using':'css selector', 'value':'*[id="foo"]'}).
|
|
880
|
-
andReturnSuccess(WebElement.buildId('one')).
|
|
881
|
-
expect(CName.SEND_KEYS_TO_ELEMENT,
|
|
882
|
-
{'id':WebElement.buildId('one'),
|
|
883
|
-
'text': 'abc123def',
|
|
884
|
-
'value':'abc123def'.split('')}).
|
|
885
|
-
andReturnSuccess().
|
|
886
|
-
end();
|
|
887
|
-
|
|
888
|
-
var driver = executor.createDriver();
|
|
889
|
-
var element = driver.findElement(By.id('foo'));
|
|
890
|
-
return element.sendKeys(
|
|
891
|
-
Promise.resolve('abc'),
|
|
892
|
-
123,
|
|
893
|
-
Promise.resolve('def'));
|
|
894
|
-
});
|
|
895
|
-
|
|
896
|
-
it('sendKeysWithAFileDetector', function() {
|
|
897
|
-
let executor = new FakeExecutor().
|
|
898
|
-
expect(CName.FIND_ELEMENT,
|
|
899
|
-
{'using':'css selector', 'value':'*[id="foo"]'}).
|
|
900
|
-
andReturnSuccess(WebElement.buildId('one')).
|
|
901
|
-
expect(CName.SEND_KEYS_TO_ELEMENT,
|
|
902
|
-
{'id': WebElement.buildId('one'),
|
|
903
|
-
'text': 'modified/path',
|
|
904
|
-
'value':'modified/path'.split('')}).
|
|
905
|
-
andReturnSuccess().
|
|
906
|
-
end();
|
|
907
|
-
|
|
908
|
-
let driver = executor.createDriver();
|
|
909
|
-
let handleFile = function(d, path) {
|
|
910
|
-
assert.strictEqual(driver, d);
|
|
911
|
-
assert.equal(path, 'original/path');
|
|
912
|
-
return Promise.resolve('modified/path');
|
|
913
|
-
};
|
|
914
|
-
driver.setFileDetector({handleFile});
|
|
915
|
-
|
|
916
|
-
return driver.findElement(By.id('foo')).sendKeys('original/', 'path');
|
|
917
|
-
});
|
|
918
|
-
});
|
|
919
|
-
|
|
920
|
-
describe("switchTo()", function() {
|
|
921
|
-
describe("window", function() {
|
|
922
|
-
it('should return a resolved promise when the window is found', function() {
|
|
923
|
-
let executor = new FakeExecutor().
|
|
924
|
-
expect(CName.SWITCH_TO_WINDOW).
|
|
925
|
-
withParameters({
|
|
926
|
-
'name': 'foo',
|
|
927
|
-
'handle': 'foo'
|
|
928
|
-
}).
|
|
929
|
-
andReturnSuccess().
|
|
930
|
-
end();
|
|
931
|
-
|
|
932
|
-
return executor.createDriver().switchTo().window('foo');
|
|
933
|
-
});
|
|
934
|
-
|
|
935
|
-
it('should propagate exceptions', function() {
|
|
936
|
-
let e = new error.NoSuchWindowError('window not found');
|
|
937
|
-
let executor = new FakeExecutor().
|
|
938
|
-
expect(CName.SWITCH_TO_WINDOW).
|
|
939
|
-
withParameters({
|
|
940
|
-
'name': 'foo',
|
|
941
|
-
'handle': 'foo'
|
|
942
|
-
}).
|
|
943
|
-
andReturnError(e).
|
|
944
|
-
end();
|
|
945
|
-
|
|
946
|
-
return executor.createDriver()
|
|
947
|
-
.switchTo().window('foo')
|
|
948
|
-
.then(assert.fail, v => assert.strictEqual(v, e));
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
describe('elementEquality', function() {
|
|
954
|
-
it('isReflexive', function() {
|
|
955
|
-
var a = new WebElement(new FakeExecutor().createDriver(), 'foo');
|
|
956
|
-
return WebElement.equals(a, a).then(assert.ok);
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
it('failsIfAnInputElementCouldNotBeFound', function() {
|
|
960
|
-
let id = Promise.reject(new StubError);
|
|
961
|
-
|
|
962
|
-
var driver = new FakeExecutor().createDriver();
|
|
963
|
-
var a = new WebElement(driver, 'foo');
|
|
964
|
-
var b = new WebElementPromise(driver, id);
|
|
965
|
-
|
|
966
|
-
return WebElement.equals(a, b).then(fail, assertIsStubError);
|
|
967
|
-
});
|
|
968
|
-
});
|
|
969
|
-
|
|
970
|
-
describe('waiting', function() {
|
|
971
|
-
it('on a condition that always returns true', function() {
|
|
972
|
-
let executor = new FakeExecutor();
|
|
973
|
-
let driver = executor.createDriver();
|
|
974
|
-
let count = 0;
|
|
975
|
-
function condition() {
|
|
976
|
-
count++;
|
|
977
|
-
return true;
|
|
978
|
-
}
|
|
979
|
-
return driver.wait(condition, 1)
|
|
980
|
-
.then(() => assert.equal(1, count));
|
|
981
|
-
});
|
|
982
|
-
|
|
983
|
-
it('on a simple counting condition', function() {
|
|
984
|
-
let executor = new FakeExecutor();
|
|
985
|
-
let driver = executor.createDriver();
|
|
986
|
-
let count = 0;
|
|
987
|
-
function condition() {
|
|
988
|
-
return ++count === 3;
|
|
989
|
-
}
|
|
990
|
-
return driver.wait(condition, 250)
|
|
991
|
-
.then(() => assert.equal(3, count));
|
|
992
|
-
});
|
|
993
|
-
|
|
994
|
-
it('on a condition that returns a promise that resolves to true after a short timeout', function() {
|
|
995
|
-
let executor = new FakeExecutor();
|
|
996
|
-
let driver = executor.createDriver();
|
|
997
|
-
|
|
998
|
-
let count = 0;
|
|
999
|
-
function condition() {
|
|
1000
|
-
count += 1;
|
|
1001
|
-
return new Promise(resolve => {
|
|
1002
|
-
setTimeout(() => resolve(true), 50);
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
return driver.wait(condition, 75)
|
|
1007
|
-
.then(() => assert.equal(1, count));
|
|
1008
|
-
});
|
|
1009
|
-
|
|
1010
|
-
it('on a condition that returns a promise', function() {
|
|
1011
|
-
let executor = new FakeExecutor();
|
|
1012
|
-
let driver = executor.createDriver();
|
|
1013
|
-
|
|
1014
|
-
let count = 0;
|
|
1015
|
-
function condition() {
|
|
1016
|
-
count += 1;
|
|
1017
|
-
return new Promise(resolve => {
|
|
1018
|
-
setTimeout(() => resolve(count === 3), 25);
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
return driver.wait(condition, 100, null, 25)
|
|
1023
|
-
.then(() => assert.equal(3, count));
|
|
1024
|
-
});
|
|
1025
|
-
|
|
1026
|
-
it('fails if condition throws', function() {
|
|
1027
|
-
let executor = new FakeExecutor();
|
|
1028
|
-
let driver = executor.createDriver();
|
|
1029
|
-
return driver.wait(throwStubError, 0, 'goes boom')
|
|
1030
|
-
.then(fail, assertIsStubError);
|
|
1031
|
-
});
|
|
1032
|
-
|
|
1033
|
-
it('fails if condition returns a rejected promise', function() {
|
|
1034
|
-
let executor = new FakeExecutor();
|
|
1035
|
-
let driver = executor.createDriver();
|
|
1036
|
-
function condition() {
|
|
1037
|
-
return new Promise((_, reject) => reject(new StubError));
|
|
1038
|
-
}
|
|
1039
|
-
return driver.wait(condition, 0, 'goes boom')
|
|
1040
|
-
.then(fail, assertIsStubError);
|
|
1041
|
-
});
|
|
1042
|
-
|
|
1043
|
-
it('waits forever on a zero timeout', function() {
|
|
1044
|
-
let done = false;
|
|
1045
|
-
setTimeout(() => done = true, 150);
|
|
1046
|
-
|
|
1047
|
-
let executor = new FakeExecutor();
|
|
1048
|
-
let driver = executor.createDriver();
|
|
1049
|
-
let waitResult = driver.wait(() => done, 0);
|
|
1050
|
-
|
|
1051
|
-
return driver.sleep(75).then(function() {
|
|
1052
|
-
assert.ok(!done);
|
|
1053
|
-
return driver.sleep(100);
|
|
1054
|
-
}).then(function() {
|
|
1055
|
-
assert.ok(done);
|
|
1056
|
-
return waitResult;
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
|
|
1060
|
-
it('waits forever if timeout omitted', function() {
|
|
1061
|
-
let done = false;
|
|
1062
|
-
setTimeout(() => done = true, 150);
|
|
1063
|
-
|
|
1064
|
-
let executor = new FakeExecutor();
|
|
1065
|
-
let driver = executor.createDriver();
|
|
1066
|
-
let waitResult = driver.wait(() => done);
|
|
1067
|
-
|
|
1068
|
-
return driver.sleep(75).then(function() {
|
|
1069
|
-
assert.ok(!done);
|
|
1070
|
-
return driver.sleep(100);
|
|
1071
|
-
}).then(function() {
|
|
1072
|
-
assert.ok(done);
|
|
1073
|
-
return waitResult;
|
|
1074
|
-
});
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
it('times out when timer expires', function() {
|
|
1078
|
-
let executor = new FakeExecutor();
|
|
1079
|
-
let driver = executor.createDriver();
|
|
1080
|
-
|
|
1081
|
-
let count = 0;
|
|
1082
|
-
let wait = driver.wait(function() {
|
|
1083
|
-
count += 1;
|
|
1084
|
-
let ms = count === 2 ? 65 : 5;
|
|
1085
|
-
return promise.delayed(ms).then(function() {
|
|
1086
|
-
return false;
|
|
1087
|
-
});
|
|
1088
|
-
}, 60, 'counting to 3')
|
|
1089
|
-
|
|
1090
|
-
return wait.then(fail, function(e) {
|
|
1091
|
-
assert.equal(2, count);
|
|
1092
|
-
assert.ok(e instanceof error.TimeoutError, 'Unexpected error: ' + e);
|
|
1093
|
-
assert.ok(
|
|
1094
|
-
/^counting to 3\nWait timed out after \d+ms$/.test(e.message));
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
it('requires condition to be a promise or function', function() {
|
|
1099
|
-
let executor = new FakeExecutor();
|
|
1100
|
-
let driver = executor.createDriver();
|
|
1101
|
-
assert.throws(() => driver.wait(1234, 0));
|
|
1102
|
-
});
|
|
1103
|
-
|
|
1104
|
-
it('promise that does not resolve before timeout', function() {
|
|
1105
|
-
let d = defer();
|
|
1106
|
-
|
|
1107
|
-
let executor = new FakeExecutor();
|
|
1108
|
-
let driver = executor.createDriver();
|
|
1109
|
-
return driver.wait(d.promise, 5).then(fail, e => {
|
|
1110
|
-
assert.ok(e instanceof error.TimeoutError, 'Unexpected error: ' + e);
|
|
1111
|
-
assert.ok(
|
|
1112
|
-
/Timed out waiting for promise to resolve after \d+ms/
|
|
1113
|
-
.test(e.message),
|
|
1114
|
-
'unexpected error message: ' + e.message);
|
|
1115
|
-
});
|
|
1116
|
-
});
|
|
1117
|
-
|
|
1118
|
-
it('unbounded wait on promise resolution', function() {
|
|
1119
|
-
let messages = [];
|
|
1120
|
-
let d = defer();
|
|
1121
|
-
|
|
1122
|
-
let executor = new FakeExecutor();
|
|
1123
|
-
let driver = executor.createDriver();
|
|
1124
|
-
let waitResult = driver.wait(d.promise).then(function(value) {
|
|
1125
|
-
messages.push('b');
|
|
1126
|
-
assert.equal(1234, value);
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
|
-
setTimeout(() => messages.push('a'), 5);
|
|
1130
|
-
return driver.sleep(10).then(function() {
|
|
1131
|
-
assert.deepEqual(['a'], messages);
|
|
1132
|
-
d.resolve(1234);
|
|
1133
|
-
return waitResult;
|
|
1134
|
-
}).then(function() {
|
|
1135
|
-
assert.deepEqual(['a', 'b'], messages);
|
|
1136
|
-
});
|
|
1137
|
-
});
|
|
1138
|
-
|
|
1139
|
-
describe('supports custom wait functions', function() {
|
|
1140
|
-
it('waitSucceeds', function() {
|
|
1141
|
-
let executor = new FakeExecutor().
|
|
1142
|
-
expect(CName.FIND_ELEMENTS,
|
|
1143
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
1144
|
-
andReturnSuccess([]).
|
|
1145
|
-
times(2).
|
|
1146
|
-
expect(CName.FIND_ELEMENTS,
|
|
1147
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
1148
|
-
andReturnSuccess([WebElement.buildId('bar')]).
|
|
1149
|
-
end();
|
|
1150
|
-
|
|
1151
|
-
var driver = executor.createDriver();
|
|
1152
|
-
return driver.wait(function() {
|
|
1153
|
-
return driver.findElements(By.id('foo')).then(els => els.length > 0);
|
|
1154
|
-
}, 200, null, 25);
|
|
1155
|
-
});
|
|
1156
|
-
|
|
1157
|
-
it('waitTimesout_timeoutCaught', function() {
|
|
1158
|
-
let executor = new FakeExecutor().
|
|
1159
|
-
expect(CName.FIND_ELEMENTS,
|
|
1160
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
1161
|
-
andReturnSuccess([]).
|
|
1162
|
-
anyTimes().
|
|
1163
|
-
end();
|
|
1164
|
-
|
|
1165
|
-
var driver = executor.createDriver();
|
|
1166
|
-
return driver.wait(function() {
|
|
1167
|
-
return driver.findElements(By.id('foo')).then(els => els.length > 0);
|
|
1168
|
-
}, 25).then(fail, function(e) {
|
|
1169
|
-
assert.equal('Wait timed out after ',
|
|
1170
|
-
e.message.substring(0, 'Wait timed out after '.length));
|
|
1171
|
-
});
|
|
1172
|
-
});
|
|
1173
|
-
});
|
|
1174
|
-
|
|
1175
|
-
describe('supports condition objects', function() {
|
|
1176
|
-
it('wait succeeds', function() {
|
|
1177
|
-
let executor = new FakeExecutor()
|
|
1178
|
-
.expect(CName.FIND_ELEMENTS,
|
|
1179
|
-
{using: 'css selector', value: '*[id="foo"]'})
|
|
1180
|
-
.andReturnSuccess([])
|
|
1181
|
-
.times(2)
|
|
1182
|
-
.expect(CName.FIND_ELEMENTS,
|
|
1183
|
-
{using: 'css selector', value: '*[id="foo"]'})
|
|
1184
|
-
.andReturnSuccess([WebElement.buildId('bar')])
|
|
1185
|
-
.end();
|
|
1186
|
-
|
|
1187
|
-
let driver = executor.createDriver();
|
|
1188
|
-
return driver.wait(until.elementLocated(By.id('foo')), 200, null, 25);
|
|
1189
|
-
});
|
|
1190
|
-
|
|
1191
|
-
it('wait times out', function() {
|
|
1192
|
-
let executor = new FakeExecutor()
|
|
1193
|
-
.expect(CName.FIND_ELEMENTS,
|
|
1194
|
-
{using: 'css selector', value: '*[id="foo"]'})
|
|
1195
|
-
.andReturnSuccess([])
|
|
1196
|
-
.anyTimes()
|
|
1197
|
-
.end();
|
|
1198
|
-
|
|
1199
|
-
let driver = executor.createDriver();
|
|
1200
|
-
return driver.wait(until.elementLocated(By.id('foo')), 5)
|
|
1201
|
-
.then(fail, err => assert.ok(err instanceof error.TimeoutError));
|
|
1202
|
-
});
|
|
1203
|
-
});
|
|
1204
|
-
|
|
1205
|
-
describe('supports promise objects', function() {
|
|
1206
|
-
it('wait succeeds', function() {
|
|
1207
|
-
let promise = new Promise(resolve => {
|
|
1208
|
-
setTimeout(() => resolve(1), 10);
|
|
1209
|
-
});
|
|
1210
|
-
|
|
1211
|
-
let driver = new FakeExecutor().createDriver();
|
|
1212
|
-
return driver.wait(promise, 200).then(v => assert.equal(v, 1));
|
|
1213
|
-
});
|
|
1214
|
-
|
|
1215
|
-
it('wait times out', function() {
|
|
1216
|
-
let promise = new Promise(resolve => {/* never resolves */});
|
|
1217
|
-
|
|
1218
|
-
let driver = new FakeExecutor().createDriver();
|
|
1219
|
-
return driver.wait(promise, 5)
|
|
1220
|
-
.then(fail, err => assert.ok(err instanceof error.TimeoutError));
|
|
1221
|
-
});
|
|
1222
|
-
|
|
1223
|
-
it('wait fails if promise is rejected', function() {
|
|
1224
|
-
let err = Error('boom');
|
|
1225
|
-
let driver = new FakeExecutor().createDriver();
|
|
1226
|
-
return driver.wait(Promise.reject(err), 5)
|
|
1227
|
-
.then(fail, e => assert.strictEqual(e, err));
|
|
1228
|
-
});
|
|
1229
|
-
});
|
|
1230
|
-
|
|
1231
|
-
it('fails if not supported condition type provided', function() {
|
|
1232
|
-
let driver = new FakeExecutor().createDriver();
|
|
1233
|
-
assert.throws(() => driver.wait({}, 5), TypeError);
|
|
1234
|
-
});
|
|
1235
|
-
});
|
|
1236
|
-
|
|
1237
|
-
describe('alert handling', function() {
|
|
1238
|
-
it('alertResolvesWhenPromisedTextResolves', function() {
|
|
1239
|
-
let driver = new FakeExecutor().createDriver();
|
|
1240
|
-
let deferredText = defer();
|
|
1241
|
-
|
|
1242
|
-
let alert = new AlertPromise(driver, deferredText.promise);
|
|
1243
|
-
|
|
1244
|
-
deferredText.resolve(new Alert(driver, 'foo'));
|
|
1245
|
-
return alert.getText().then(text => assert.equal(text, 'foo'));
|
|
1246
|
-
});
|
|
1247
|
-
|
|
1248
|
-
it('cannotSwitchToAlertThatIsNotPresent', function() {
|
|
1249
|
-
let e = new error.NoSuchAlertError;
|
|
1250
|
-
let executor = new FakeExecutor()
|
|
1251
|
-
.expect(CName.GET_ALERT_TEXT)
|
|
1252
|
-
.andReturnError(e)
|
|
1253
|
-
.end();
|
|
1254
|
-
|
|
1255
|
-
return executor.createDriver()
|
|
1256
|
-
.switchTo().alert()
|
|
1257
|
-
.then(assert.fail, v => assert.strictEqual(v, e));
|
|
1258
|
-
});
|
|
1259
|
-
|
|
1260
|
-
it('commandsFailIfAlertNotPresent', function() {
|
|
1261
|
-
let e = new error.NoSuchAlertError;
|
|
1262
|
-
let executor = new FakeExecutor()
|
|
1263
|
-
.expect(CName.GET_ALERT_TEXT)
|
|
1264
|
-
.andReturnError(e)
|
|
1265
|
-
.end();
|
|
1266
|
-
|
|
1267
|
-
var driver = executor.createDriver();
|
|
1268
|
-
var alert = driver.switchTo().alert();
|
|
1269
|
-
|
|
1270
|
-
var expectError = (v) => assert.strictEqual(v, e);
|
|
1271
|
-
|
|
1272
|
-
return alert.getText()
|
|
1273
|
-
.then(fail, expectedError)
|
|
1274
|
-
.then(() => alert.accept())
|
|
1275
|
-
.then(fail, expectedError)
|
|
1276
|
-
.then(() => alert.dismiss())
|
|
1277
|
-
.then(fail, expectError)
|
|
1278
|
-
.then(() => alert.sendKeys('hi'))
|
|
1279
|
-
.then(fail, expectError);
|
|
1280
|
-
});
|
|
1281
|
-
});
|
|
1282
|
-
|
|
1283
|
-
it('testFetchingLogs', function() {
|
|
1284
|
-
let executor = new FakeExecutor().
|
|
1285
|
-
expect(CName.GET_LOG, {'type': 'browser'}).
|
|
1286
|
-
andReturnSuccess([
|
|
1287
|
-
{'level': 'INFO', 'message': 'hello', 'timestamp': 1234},
|
|
1288
|
-
{'level': 'DEBUG', 'message': 'abc123', 'timestamp': 5678}
|
|
1289
|
-
]).
|
|
1290
|
-
end();
|
|
1291
|
-
|
|
1292
|
-
var driver = executor.createDriver();
|
|
1293
|
-
return driver.manage().logs().get('browser').then(function(entries) {
|
|
1294
|
-
assert.equal(2, entries.length);
|
|
1295
|
-
|
|
1296
|
-
assert.ok(entries[0] instanceof logging.Entry);
|
|
1297
|
-
assert.equal(logging.Level.INFO.value, entries[0].level.value);
|
|
1298
|
-
assert.equal('hello', entries[0].message);
|
|
1299
|
-
assert.equal(1234, entries[0].timestamp);
|
|
1300
|
-
|
|
1301
|
-
assert.ok(entries[1] instanceof logging.Entry);
|
|
1302
|
-
assert.equal(logging.Level.DEBUG.value, entries[1].level.value);
|
|
1303
|
-
assert.equal('abc123', entries[1].message);
|
|
1304
|
-
assert.equal(5678, entries[1].timestamp);
|
|
1305
|
-
});
|
|
1306
|
-
});
|
|
1307
|
-
|
|
1308
|
-
it('testCommandsFailIfInitialSessionCreationFailed', function() {
|
|
1309
|
-
var session = Promise.reject(new StubError);
|
|
1310
|
-
|
|
1311
|
-
var driver = new FakeExecutor().createDriver(session);
|
|
1312
|
-
var navigateResult = driver.get('some-url').then(fail, assertIsStubError);
|
|
1313
|
-
var quitResult = driver.quit().then(fail, assertIsStubError);
|
|
1314
|
-
return Promise.all([navigateResult, quitResult]);
|
|
1315
|
-
});
|
|
1316
|
-
|
|
1317
|
-
it('testWebElementCommandsFailIfInitialDriverCreationFailed', function() {
|
|
1318
|
-
var session = Promise.reject(new StubError);
|
|
1319
|
-
var driver = new FakeExecutor().createDriver(session);
|
|
1320
|
-
return driver.findElement(By.id('foo')).click().
|
|
1321
|
-
then(fail, assertIsStubError);
|
|
1322
|
-
});
|
|
1323
|
-
|
|
1324
|
-
it('testWebElementCommansFailIfElementCouldNotBeFound', function() {
|
|
1325
|
-
let e = new error.NoSuchElementError('Unable to find element');
|
|
1326
|
-
let executor = new FakeExecutor().
|
|
1327
|
-
expect(CName.FIND_ELEMENT,
|
|
1328
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
1329
|
-
andReturnError(e).
|
|
1330
|
-
end();
|
|
1331
|
-
|
|
1332
|
-
var driver = executor.createDriver();
|
|
1333
|
-
return driver.findElement(By.id('foo')).click()
|
|
1334
|
-
.then(fail, v => assert.strictEqual(v, e));
|
|
1335
|
-
});
|
|
1336
|
-
|
|
1337
|
-
it('testCannotFindChildElementsIfParentCouldNotBeFound', function() {
|
|
1338
|
-
let e = new error.NoSuchElementError('Unable to find element');
|
|
1339
|
-
let executor = new FakeExecutor().
|
|
1340
|
-
expect(CName.FIND_ELEMENT,
|
|
1341
|
-
{using: 'css selector', value: '*[id="foo"]'}).
|
|
1342
|
-
andReturnError(e).
|
|
1343
|
-
end();
|
|
1344
|
-
|
|
1345
|
-
var driver = executor.createDriver();
|
|
1346
|
-
return driver.findElement(By.id('foo'))
|
|
1347
|
-
.findElement(By.id('bar'))
|
|
1348
|
-
.findElement(By.id('baz'))
|
|
1349
|
-
.then(fail, v => assert.strictEqual(v, e));
|
|
1350
|
-
});
|
|
1351
|
-
|
|
1352
|
-
describe('actions()', function() {
|
|
1353
|
-
describe('move()', function() {
|
|
1354
|
-
it('no origin', function() {
|
|
1355
|
-
let executor = new FakeExecutor()
|
|
1356
|
-
.expect(CName.ACTIONS, {
|
|
1357
|
-
actions: [{
|
|
1358
|
-
type: 'pointer',
|
|
1359
|
-
id: 'default mouse',
|
|
1360
|
-
parameters: {
|
|
1361
|
-
pointerType: 'mouse'
|
|
1362
|
-
},
|
|
1363
|
-
actions: [{
|
|
1364
|
-
duration: 100,
|
|
1365
|
-
origin: 'viewport',
|
|
1366
|
-
type: 'pointerMove',
|
|
1367
|
-
x: 0,
|
|
1368
|
-
y: 125
|
|
1369
|
-
}]
|
|
1370
|
-
}]
|
|
1371
|
-
})
|
|
1372
|
-
.andReturnSuccess()
|
|
1373
|
-
.end();
|
|
1374
|
-
|
|
1375
|
-
let driver = executor.createDriver();
|
|
1376
|
-
return driver.actions().move({x: 0, y: 125}).perform();
|
|
1377
|
-
});
|
|
1378
|
-
|
|
1379
|
-
it('origin = element', function() {
|
|
1380
|
-
let executor = new FakeExecutor()
|
|
1381
|
-
.expect(CName.FIND_ELEMENT,
|
|
1382
|
-
{using: 'css selector', value: '*[id="foo"]'})
|
|
1383
|
-
.andReturnSuccess(WebElement.buildId('abc123'))
|
|
1384
|
-
.expect(CName.ACTIONS, {
|
|
1385
|
-
actions: [{
|
|
1386
|
-
type: 'pointer',
|
|
1387
|
-
id: 'default mouse',
|
|
1388
|
-
parameters: {
|
|
1389
|
-
pointerType: 'mouse'
|
|
1390
|
-
},
|
|
1391
|
-
actions: [{
|
|
1392
|
-
duration: 100,
|
|
1393
|
-
origin: WebElement.buildId('abc123'),
|
|
1394
|
-
type: 'pointerMove',
|
|
1395
|
-
x: 0,
|
|
1396
|
-
y: 125
|
|
1397
|
-
}]
|
|
1398
|
-
}]
|
|
1399
|
-
})
|
|
1400
|
-
.end();
|
|
1401
|
-
|
|
1402
|
-
let driver = executor.createDriver();
|
|
1403
|
-
let element = driver.findElement(By.id('foo'));
|
|
1404
|
-
return driver.actions().move({x: 0, y: 125, origin: element}).perform();
|
|
1405
|
-
});
|
|
1406
|
-
});
|
|
1407
|
-
});
|
|
1408
|
-
|
|
1409
|
-
describe('manage()', function() {
|
|
1410
|
-
describe('setTimeouts()', function() {
|
|
1411
|
-
describe('throws if no timeouts are specified', function() {
|
|
1412
|
-
let driver;
|
|
1413
|
-
before(() => driver = new FakeExecutor().createDriver());
|
|
1414
|
-
|
|
1415
|
-
it('; no arguments', function() {
|
|
1416
|
-
assert.throws(() => driver.manage().setTimeouts(), TypeError);
|
|
1417
|
-
});
|
|
1418
|
-
|
|
1419
|
-
it('; ignores unrecognized timeout keys', function() {
|
|
1420
|
-
assert.throws(
|
|
1421
|
-
() => driver.manage().setTimeouts({foo: 123}), TypeError);
|
|
1422
|
-
});
|
|
1423
|
-
|
|
1424
|
-
it('; ignores positional arguments', function() {
|
|
1425
|
-
assert.throws(
|
|
1426
|
-
() => driver.manage().setTimeouts(1234, 56), TypeError);
|
|
1427
|
-
});
|
|
1428
|
-
});
|
|
1429
|
-
|
|
1430
|
-
describe('throws timeout is not a number, null, or undefined', () => {
|
|
1431
|
-
let driver;
|
|
1432
|
-
before(() => driver = new FakeExecutor().createDriver());
|
|
1433
|
-
|
|
1434
|
-
function checkError(e) {
|
|
1435
|
-
return e instanceof TypeError
|
|
1436
|
-
&& /expected "(script|pageLoad|implicit)" to be a number/.test(
|
|
1437
|
-
e.message);
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
it('script', function() {
|
|
1441
|
-
assert.throws(
|
|
1442
|
-
() => driver.manage().setTimeouts({script: 'abc'}),
|
|
1443
|
-
checkError);
|
|
1444
|
-
});
|
|
1445
|
-
|
|
1446
|
-
it('pageLoad', function() {
|
|
1447
|
-
assert.throws(
|
|
1448
|
-
() => driver.manage().setTimeouts({pageLoad: 'abc'}),
|
|
1449
|
-
checkError);
|
|
1450
|
-
});
|
|
1451
|
-
|
|
1452
|
-
it('implicit', function() {
|
|
1453
|
-
assert.throws(
|
|
1454
|
-
() => driver.manage().setTimeouts({implicit: 'abc'}),
|
|
1455
|
-
checkError);
|
|
1456
|
-
});
|
|
1457
|
-
});
|
|
1458
|
-
|
|
1459
|
-
it('can set multiple timeouts', function() {
|
|
1460
|
-
let executor = new FakeExecutor()
|
|
1461
|
-
.expect(CName.SET_TIMEOUT, {script:1, pageLoad: 2, implicit: 3})
|
|
1462
|
-
.andReturnSuccess()
|
|
1463
|
-
.end();
|
|
1464
|
-
let driver = executor.createDriver();
|
|
1465
|
-
return driver.manage()
|
|
1466
|
-
.setTimeouts({script: 1, pageLoad: 2, implicit: 3});
|
|
1467
|
-
});
|
|
1468
|
-
|
|
1469
|
-
it('falls back to legacy wire format if W3C version fails', () => {
|
|
1470
|
-
let executor = new FakeExecutor()
|
|
1471
|
-
.expect(CName.SET_TIMEOUT, {implicit: 3})
|
|
1472
|
-
.andReturnError(Error('oops'))
|
|
1473
|
-
.expect(CName.SET_TIMEOUT, {type: 'implicit', ms: 3})
|
|
1474
|
-
.andReturnSuccess()
|
|
1475
|
-
.end();
|
|
1476
|
-
let driver = executor.createDriver();
|
|
1477
|
-
return driver.manage().setTimeouts({implicit: 3});
|
|
1478
|
-
});
|
|
1479
|
-
});
|
|
1480
|
-
});
|
|
1481
|
-
|
|
1482
|
-
describe('wire format', function() {
|
|
1483
|
-
const FAKE_DRIVER = new FakeExecutor().createDriver();
|
|
1484
|
-
|
|
1485
|
-
describe('can serialize', function() {
|
|
1486
|
-
function runSerializeTest(input, want) {
|
|
1487
|
-
let executor = new FakeExecutor().
|
|
1488
|
-
expect(CName.NEW_SESSION).
|
|
1489
|
-
withParameters({
|
|
1490
|
-
'desiredCapabilities': {'serialize-test': want},
|
|
1491
|
-
'capabilities': {'alwaysMatch': {}},
|
|
1492
|
-
}).
|
|
1493
|
-
andReturnSuccess({'browserName': 'firefox'}).
|
|
1494
|
-
end();
|
|
1495
|
-
// We stuff the value to be serialized inside of a capabilities object,
|
|
1496
|
-
// using a non-W3C key so that the value gets dropped from the W3C
|
|
1497
|
-
// capabilities object.
|
|
1498
|
-
return WebDriver.createSession(executor, {'serialize-test': input})
|
|
1499
|
-
.getSession();
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
it('function as a string', function() {
|
|
1503
|
-
function foo() { return 'foo'; }
|
|
1504
|
-
return runSerializeTest(foo, '' + foo);
|
|
1505
|
-
});
|
|
1506
|
-
|
|
1507
|
-
it('object with toJSON()', function() {
|
|
1508
|
-
return runSerializeTest(
|
|
1509
|
-
new Date(605728511546),
|
|
1510
|
-
'1989-03-12T17:55:11.546Z');
|
|
1511
|
-
});
|
|
1512
|
-
|
|
1513
|
-
it('Session', function() {
|
|
1514
|
-
return runSerializeTest(new Session('foo', {}), 'foo');
|
|
1515
|
-
});
|
|
1516
|
-
|
|
1517
|
-
it('Capabilities', function() {
|
|
1518
|
-
var prefs = new logging.Preferences();
|
|
1519
|
-
prefs.setLevel(logging.Type.BROWSER, logging.Level.DEBUG);
|
|
1520
|
-
|
|
1521
|
-
var caps = Capabilities.chrome();
|
|
1522
|
-
caps.setLoggingPrefs(prefs);
|
|
1523
|
-
|
|
1524
|
-
return runSerializeTest(
|
|
1525
|
-
caps,
|
|
1526
|
-
{
|
|
1527
|
-
'browserName': 'chrome',
|
|
1528
|
-
'loggingPrefs': {'browser': 'DEBUG'}
|
|
1529
|
-
});
|
|
1530
|
-
});
|
|
1531
|
-
|
|
1532
|
-
it('WebElement', function() {
|
|
1533
|
-
return runSerializeTest(
|
|
1534
|
-
new WebElement(FAKE_DRIVER, 'fefifofum'),
|
|
1535
|
-
WebElement.buildId('fefifofum'));
|
|
1536
|
-
});
|
|
1537
|
-
|
|
1538
|
-
it('WebElementPromise', function() {
|
|
1539
|
-
return runSerializeTest(
|
|
1540
|
-
new WebElementPromise(
|
|
1541
|
-
FAKE_DRIVER,
|
|
1542
|
-
Promise.resolve(new WebElement(FAKE_DRIVER, 'fefifofum'))),
|
|
1543
|
-
WebElement.buildId('fefifofum'));
|
|
1544
|
-
});
|
|
1545
|
-
|
|
1546
|
-
describe('an array', function() {
|
|
1547
|
-
it('with Serializable', function() {
|
|
1548
|
-
return runSerializeTest([new Session('foo', {})], ['foo']);
|
|
1549
|
-
});
|
|
1550
|
-
|
|
1551
|
-
it('with WebElement', function() {
|
|
1552
|
-
return runSerializeTest(
|
|
1553
|
-
[new WebElement(FAKE_DRIVER, 'fefifofum')],
|
|
1554
|
-
[WebElement.buildId('fefifofum')]);
|
|
1555
|
-
});
|
|
1556
|
-
|
|
1557
|
-
it('with WebElementPromise', function() {
|
|
1558
|
-
return runSerializeTest(
|
|
1559
|
-
[new WebElementPromise(
|
|
1560
|
-
FAKE_DRIVER,
|
|
1561
|
-
Promise.resolve(new WebElement(FAKE_DRIVER, 'fefifofum')))],
|
|
1562
|
-
[WebElement.buildId('fefifofum')]);
|
|
1563
|
-
});
|
|
1564
|
-
|
|
1565
|
-
it('complex array', function() {
|
|
1566
|
-
var expected = [
|
|
1567
|
-
'abc', 123, true, WebElement.buildId('fefifofum'),
|
|
1568
|
-
[123, {'foo': 'bar'}]
|
|
1569
|
-
];
|
|
1570
|
-
|
|
1571
|
-
var element = new WebElement(FAKE_DRIVER, 'fefifofum');
|
|
1572
|
-
var input = ['abc', 123, true, element, [123, {'foo': 'bar'}]];
|
|
1573
|
-
return runSerializeTest(input, expected);
|
|
1574
|
-
});
|
|
1575
|
-
|
|
1576
|
-
it('nested promises', function() {
|
|
1577
|
-
return runSerializeTest(
|
|
1578
|
-
['abc', Promise.resolve([123, Promise.resolve(true)])],
|
|
1579
|
-
['abc', [123, true]]);
|
|
1580
|
-
});
|
|
1581
|
-
});
|
|
1582
|
-
|
|
1583
|
-
describe('an object', function() {
|
|
1584
|
-
it('literal', function() {
|
|
1585
|
-
var expected = {sessionId: 'foo'};
|
|
1586
|
-
return runSerializeTest({sessionId: 'foo'}, expected);
|
|
1587
|
-
});
|
|
1588
|
-
|
|
1589
|
-
it('with sub-objects', function() {
|
|
1590
|
-
var expected = {sessionId: {value: 'foo'}};
|
|
1591
|
-
return runSerializeTest({sessionId: {value: 'foo'}}, expected);
|
|
1592
|
-
});
|
|
1593
|
-
|
|
1594
|
-
it('with values that have toJSON', function() {
|
|
1595
|
-
return runSerializeTest(
|
|
1596
|
-
{a: {b: new Date(605728511546)}},
|
|
1597
|
-
{a: {b: '1989-03-12T17:55:11.546Z'}});
|
|
1598
|
-
});
|
|
1599
|
-
|
|
1600
|
-
it('with a Session', function() {
|
|
1601
|
-
return runSerializeTest(
|
|
1602
|
-
{a: new Session('foo', {})},
|
|
1603
|
-
{a: 'foo'});
|
|
1604
|
-
});
|
|
1605
|
-
|
|
1606
|
-
it('nested', function() {
|
|
1607
|
-
var elementJson = WebElement.buildId('fefifofum');
|
|
1608
|
-
var expected = {
|
|
1609
|
-
'script': 'return 1',
|
|
1610
|
-
'args': ['abc', 123, true, elementJson, [123, {'foo': 'bar'}]],
|
|
1611
|
-
'sessionId': 'foo'
|
|
1612
|
-
};
|
|
1613
|
-
|
|
1614
|
-
var element = new WebElement(FAKE_DRIVER, 'fefifofum');
|
|
1615
|
-
var parameters = {
|
|
1616
|
-
'script': 'return 1',
|
|
1617
|
-
'args':['abc', 123, true, element, [123, {'foo': 'bar'}]],
|
|
1618
|
-
'sessionId': new Session('foo', {})
|
|
1619
|
-
};
|
|
1620
|
-
|
|
1621
|
-
return runSerializeTest(parameters, expected);
|
|
1622
|
-
});
|
|
1623
|
-
|
|
1624
|
-
it('nested promises', function() {
|
|
1625
|
-
const input = {
|
|
1626
|
-
'struct': Promise.resolve({
|
|
1627
|
-
'element': new WebElementPromise(
|
|
1628
|
-
FAKE_DRIVER,
|
|
1629
|
-
Promise.resolve(new WebElement(FAKE_DRIVER, 'fefifofum')))
|
|
1630
|
-
})
|
|
1631
|
-
};
|
|
1632
|
-
|
|
1633
|
-
const want = {
|
|
1634
|
-
'struct': {
|
|
1635
|
-
'element': WebElement.buildId('fefifofum')
|
|
1636
|
-
}
|
|
1637
|
-
};
|
|
1638
|
-
|
|
1639
|
-
return runSerializeTest(input, want);
|
|
1640
|
-
});
|
|
1641
|
-
});
|
|
1642
|
-
});
|
|
1643
|
-
|
|
1644
|
-
describe('can deserialize', function() {
|
|
1645
|
-
function runDeserializeTest(original, want) {
|
|
1646
|
-
let executor = new FakeExecutor()
|
|
1647
|
-
.expect(CName.GET_CURRENT_URL)
|
|
1648
|
-
.andReturnSuccess(original)
|
|
1649
|
-
.end();
|
|
1650
|
-
let driver = executor.createDriver();
|
|
1651
|
-
return driver.getCurrentUrl().then(function(got) {
|
|
1652
|
-
assert.deepEqual(got, want);
|
|
1653
|
-
});
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
it('primitives', function() {
|
|
1657
|
-
return Promise.all([
|
|
1658
|
-
runDeserializeTest(1, 1),
|
|
1659
|
-
runDeserializeTest('', ''),
|
|
1660
|
-
runDeserializeTest(true, true),
|
|
1661
|
-
runDeserializeTest(undefined, undefined),
|
|
1662
|
-
runDeserializeTest(null, null)
|
|
1663
|
-
]);
|
|
1664
|
-
});
|
|
1665
|
-
|
|
1666
|
-
it('simple object', function() {
|
|
1667
|
-
return runDeserializeTest(
|
|
1668
|
-
{sessionId: 'foo'},
|
|
1669
|
-
{sessionId: 'foo'});
|
|
1670
|
-
});
|
|
1671
|
-
|
|
1672
|
-
it('nested object', function() {
|
|
1673
|
-
return runDeserializeTest(
|
|
1674
|
-
{'foo': {'bar': 123}},
|
|
1675
|
-
{'foo': {'bar': 123}});
|
|
1676
|
-
});
|
|
1677
|
-
|
|
1678
|
-
it('array', function() {
|
|
1679
|
-
return runDeserializeTest(
|
|
1680
|
-
[{'foo': {'bar': 123}}],
|
|
1681
|
-
[{'foo': {'bar': 123}}]);
|
|
1682
|
-
});
|
|
1683
|
-
|
|
1684
|
-
it('passes through function properties', function() {
|
|
1685
|
-
function bar() {}
|
|
1686
|
-
return runDeserializeTest(
|
|
1687
|
-
[{foo: {'bar': 123}, func: bar}],
|
|
1688
|
-
[{foo: {'bar': 123}, func: bar}]);
|
|
1689
|
-
});
|
|
1690
|
-
});
|
|
1691
|
-
});
|
|
1692
|
-
});
|