selenium-webdriver 4.0.0-alpha.7 → 4.0.0-beta.3
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 +56 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +2 -0
- package/chrome.js +69 -79
- package/chromium.js +231 -164
- package/{lib/atoms/make-atoms-module.js → devtools/CDPConnection.js} +15 -9
- package/edge.js +104 -146
- package/example/chrome_android.js +45 -0
- package/example/chrome_mobile_emulation.js +46 -0
- package/example/firefox_channels.js +84 -0
- package/example/google_search.js +50 -0
- package/example/google_search_test.js +70 -0
- package/example/headless.js +63 -0
- package/example/logging.js +64 -0
- package/firefox.js +199 -200
- package/http/index.js +128 -116
- package/http/util.js +56 -64
- package/ie.js +180 -104
- package/index.js +246 -199
- package/io/exec.js +35 -40
- package/io/index.js +146 -157
- package/io/zip.js +75 -66
- package/lib/atoms/find-elements.js +123 -0
- package/lib/atoms/get-attribute.js +75 -59
- package/lib/atoms/is-displayed.js +72 -72
- package/lib/atoms/mutation-listener.js +55 -0
- package/lib/by.js +192 -65
- package/lib/capabilities.js +76 -86
- package/lib/command.js +19 -35
- package/lib/error.js +134 -168
- package/lib/http.js +308 -232
- package/lib/input.js +192 -453
- package/lib/logging.js +126 -137
- package/lib/promise.js +53 -71
- package/lib/proxy.js +31 -41
- package/lib/session.js +12 -15
- package/lib/symbols.js +3 -4
- package/lib/until.js +162 -160
- package/lib/webdriver.js +1014 -549
- package/net/index.js +30 -36
- package/net/portprober.js +30 -143
- package/opera.js +406 -0
- package/package.json +15 -7
- package/proxy.js +2 -2
- package/remote/index.js +189 -187
- package/safari.js +40 -49
- package/testing/index.js +504 -0
- package/lib/README +0 -5
- package/lib/actions.js +0 -609
package/lib/error.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// specific language governing permissions and limitations
|
|
16
16
|
// under the License.
|
|
17
17
|
|
|
18
|
-
'use strict'
|
|
18
|
+
'use strict'
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* The base WebDriver error type. This error type is only used directly when a
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
class WebDriverError extends Error {
|
|
25
25
|
/** @param {string=} opt_error the error message, if any. */
|
|
26
26
|
constructor(opt_error) {
|
|
27
|
-
super(opt_error)
|
|
27
|
+
super(opt_error)
|
|
28
28
|
|
|
29
29
|
/** @override */
|
|
30
|
-
this.name = this.constructor.name
|
|
30
|
+
this.name = this.constructor.name
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* A stacktrace reported by the remote webdriver endpoint that initially
|
|
@@ -35,11 +35,10 @@ class WebDriverError extends Error {
|
|
|
35
35
|
* end did not provide a stacktrace.
|
|
36
36
|
* @type {string}
|
|
37
37
|
*/
|
|
38
|
-
this.remoteStacktrace = ''
|
|
38
|
+
this.remoteStacktrace = ''
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
43
42
|
/**
|
|
44
43
|
* Indicates a {@linkplain ./webdriver.WebElement#click click command} could not
|
|
45
44
|
* completed because the click target is obscured by other elements on the
|
|
@@ -48,22 +47,20 @@ class WebDriverError extends Error {
|
|
|
48
47
|
class ElementClickInterceptedError extends WebDriverError {
|
|
49
48
|
/** @param {string=} opt_error the error message, if any. */
|
|
50
49
|
constructor(opt_error) {
|
|
51
|
-
super(opt_error)
|
|
50
|
+
super(opt_error)
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
|
|
56
54
|
/**
|
|
57
55
|
* An attempt was made to select an element that cannot be selected.
|
|
58
56
|
*/
|
|
59
57
|
class ElementNotSelectableError extends WebDriverError {
|
|
60
58
|
/** @param {string=} opt_error the error message, if any. */
|
|
61
59
|
constructor(opt_error) {
|
|
62
|
-
super(opt_error)
|
|
60
|
+
super(opt_error)
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
|
|
67
64
|
/**
|
|
68
65
|
* Indicates a command could not be completed because the target element is
|
|
69
66
|
* not pointer or keyboard interactable. This will often occur if an element
|
|
@@ -73,11 +70,10 @@ class ElementNotSelectableError extends WebDriverError {
|
|
|
73
70
|
class ElementNotInteractableError extends WebDriverError {
|
|
74
71
|
/** @param {string=} opt_error the error message, if any. */
|
|
75
72
|
constructor(opt_error) {
|
|
76
|
-
super(opt_error)
|
|
73
|
+
super(opt_error)
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
|
|
81
77
|
/**
|
|
82
78
|
* Indicates a navigation event caused the browser to generate a certificate
|
|
83
79
|
* warning. This is usually caused by an expired or invalid TLS certificate.
|
|
@@ -85,22 +81,20 @@ class ElementNotInteractableError extends WebDriverError {
|
|
|
85
81
|
class InsecureCertificateError extends WebDriverError {
|
|
86
82
|
/** @param {string=} opt_error the error message, if any. */
|
|
87
83
|
constructor(opt_error) {
|
|
88
|
-
super(opt_error)
|
|
84
|
+
super(opt_error)
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
|
|
93
88
|
/**
|
|
94
89
|
* The arguments passed to a command are either invalid or malformed.
|
|
95
90
|
*/
|
|
96
91
|
class InvalidArgumentError extends WebDriverError {
|
|
97
92
|
/** @param {string=} opt_error the error message, if any. */
|
|
98
93
|
constructor(opt_error) {
|
|
99
|
-
super(opt_error)
|
|
94
|
+
super(opt_error)
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
|
|
104
98
|
/**
|
|
105
99
|
* An illegal attempt was made to set a cookie under a different domain than
|
|
106
100
|
* the current page.
|
|
@@ -108,22 +102,20 @@ class InvalidArgumentError extends WebDriverError {
|
|
|
108
102
|
class InvalidCookieDomainError extends WebDriverError {
|
|
109
103
|
/** @param {string=} opt_error the error message, if any. */
|
|
110
104
|
constructor(opt_error) {
|
|
111
|
-
super(opt_error)
|
|
105
|
+
super(opt_error)
|
|
112
106
|
}
|
|
113
107
|
}
|
|
114
108
|
|
|
115
|
-
|
|
116
109
|
/**
|
|
117
110
|
* The coordinates provided to an interactions operation are invalid.
|
|
118
111
|
*/
|
|
119
112
|
class InvalidCoordinatesError extends WebDriverError {
|
|
120
113
|
/** @param {string=} opt_error the error message, if any. */
|
|
121
114
|
constructor(opt_error) {
|
|
122
|
-
super(opt_error)
|
|
115
|
+
super(opt_error)
|
|
123
116
|
}
|
|
124
117
|
}
|
|
125
118
|
|
|
126
|
-
|
|
127
119
|
/**
|
|
128
120
|
* An element command could not be completed because the element is in an
|
|
129
121
|
* invalid state, e.g. attempting to click an element that is no longer attached
|
|
@@ -132,44 +124,40 @@ class InvalidCoordinatesError extends WebDriverError {
|
|
|
132
124
|
class InvalidElementStateError extends WebDriverError {
|
|
133
125
|
/** @param {string=} opt_error the error message, if any. */
|
|
134
126
|
constructor(opt_error) {
|
|
135
|
-
super(opt_error)
|
|
127
|
+
super(opt_error)
|
|
136
128
|
}
|
|
137
129
|
}
|
|
138
130
|
|
|
139
|
-
|
|
140
131
|
/**
|
|
141
132
|
* Argument was an invalid selector.
|
|
142
133
|
*/
|
|
143
134
|
class InvalidSelectorError extends WebDriverError {
|
|
144
135
|
/** @param {string=} opt_error the error message, if any. */
|
|
145
136
|
constructor(opt_error) {
|
|
146
|
-
super(opt_error)
|
|
137
|
+
super(opt_error)
|
|
147
138
|
}
|
|
148
139
|
}
|
|
149
140
|
|
|
150
|
-
|
|
151
141
|
/**
|
|
152
142
|
* Occurs when a command is directed to a session that does not exist.
|
|
153
143
|
*/
|
|
154
144
|
class NoSuchSessionError extends WebDriverError {
|
|
155
145
|
/** @param {string=} opt_error the error message, if any. */
|
|
156
146
|
constructor(opt_error) {
|
|
157
|
-
super(opt_error)
|
|
147
|
+
super(opt_error)
|
|
158
148
|
}
|
|
159
149
|
}
|
|
160
150
|
|
|
161
|
-
|
|
162
151
|
/**
|
|
163
152
|
* An error occurred while executing JavaScript supplied by the user.
|
|
164
153
|
*/
|
|
165
154
|
class JavascriptError extends WebDriverError {
|
|
166
155
|
/** @param {string=} opt_error the error message, if any. */
|
|
167
156
|
constructor(opt_error) {
|
|
168
|
-
super(opt_error)
|
|
157
|
+
super(opt_error)
|
|
169
158
|
}
|
|
170
159
|
}
|
|
171
160
|
|
|
172
|
-
|
|
173
161
|
/**
|
|
174
162
|
* The target for mouse interaction is not in the browser’s viewport and cannot
|
|
175
163
|
* be brought into that viewport.
|
|
@@ -177,22 +165,20 @@ class JavascriptError extends WebDriverError {
|
|
|
177
165
|
class MoveTargetOutOfBoundsError extends WebDriverError {
|
|
178
166
|
/** @param {string=} opt_error the error message, if any. */
|
|
179
167
|
constructor(opt_error) {
|
|
180
|
-
super(opt_error)
|
|
168
|
+
super(opt_error)
|
|
181
169
|
}
|
|
182
170
|
}
|
|
183
171
|
|
|
184
|
-
|
|
185
172
|
/**
|
|
186
173
|
* An attempt was made to operate on a modal dialog when one was not open.
|
|
187
174
|
*/
|
|
188
175
|
class NoSuchAlertError extends WebDriverError {
|
|
189
176
|
/** @param {string=} opt_error the error message, if any. */
|
|
190
177
|
constructor(opt_error) {
|
|
191
|
-
super(opt_error)
|
|
178
|
+
super(opt_error)
|
|
192
179
|
}
|
|
193
180
|
}
|
|
194
181
|
|
|
195
|
-
|
|
196
182
|
/**
|
|
197
183
|
* Indicates a named cookie could not be found in the cookie jar for the
|
|
198
184
|
* currently selected document.
|
|
@@ -200,11 +186,10 @@ class NoSuchAlertError extends WebDriverError {
|
|
|
200
186
|
class NoSuchCookieError extends WebDriverError {
|
|
201
187
|
/** @param {string=} opt_error the error message, if any. */
|
|
202
188
|
constructor(opt_error) {
|
|
203
|
-
super(opt_error)
|
|
189
|
+
super(opt_error)
|
|
204
190
|
}
|
|
205
191
|
}
|
|
206
192
|
|
|
207
|
-
|
|
208
193
|
/**
|
|
209
194
|
* An element could not be located on the page using the given search
|
|
210
195
|
* parameters.
|
|
@@ -212,11 +197,10 @@ class NoSuchCookieError extends WebDriverError {
|
|
|
212
197
|
class NoSuchElementError extends WebDriverError {
|
|
213
198
|
/** @param {string=} opt_error the error message, if any. */
|
|
214
199
|
constructor(opt_error) {
|
|
215
|
-
super(opt_error)
|
|
200
|
+
super(opt_error)
|
|
216
201
|
}
|
|
217
202
|
}
|
|
218
203
|
|
|
219
|
-
|
|
220
204
|
/**
|
|
221
205
|
* A request to switch to a frame could not be satisfied because the frame
|
|
222
206
|
* could not be found.
|
|
@@ -224,11 +208,10 @@ class NoSuchElementError extends WebDriverError {
|
|
|
224
208
|
class NoSuchFrameError extends WebDriverError {
|
|
225
209
|
/** @param {string=} opt_error the error message, if any. */
|
|
226
210
|
constructor(opt_error) {
|
|
227
|
-
super(opt_error)
|
|
211
|
+
super(opt_error)
|
|
228
212
|
}
|
|
229
213
|
}
|
|
230
214
|
|
|
231
|
-
|
|
232
215
|
/**
|
|
233
216
|
* A request to switch to a window could not be satisfied because the window
|
|
234
217
|
* could not be found.
|
|
@@ -236,34 +219,30 @@ class NoSuchFrameError extends WebDriverError {
|
|
|
236
219
|
class NoSuchWindowError extends WebDriverError {
|
|
237
220
|
/** @param {string=} opt_error the error message, if any. */
|
|
238
221
|
constructor(opt_error) {
|
|
239
|
-
super(opt_error)
|
|
222
|
+
super(opt_error)
|
|
240
223
|
}
|
|
241
224
|
}
|
|
242
225
|
|
|
243
|
-
|
|
244
226
|
/**
|
|
245
227
|
* A script did not complete before its timeout expired.
|
|
246
228
|
*/
|
|
247
229
|
class ScriptTimeoutError extends WebDriverError {
|
|
248
230
|
/** @param {string=} opt_error the error message, if any. */
|
|
249
231
|
constructor(opt_error) {
|
|
250
|
-
super(opt_error)
|
|
232
|
+
super(opt_error)
|
|
251
233
|
}
|
|
252
234
|
}
|
|
253
235
|
|
|
254
|
-
|
|
255
236
|
/**
|
|
256
237
|
* A new session could not be created.
|
|
257
238
|
*/
|
|
258
239
|
class SessionNotCreatedError extends WebDriverError {
|
|
259
240
|
/** @param {string=} opt_error the error message, if any. */
|
|
260
241
|
constructor(opt_error) {
|
|
261
|
-
super(opt_error)
|
|
242
|
+
super(opt_error)
|
|
262
243
|
}
|
|
263
244
|
}
|
|
264
245
|
|
|
265
|
-
|
|
266
|
-
|
|
267
246
|
/**
|
|
268
247
|
* An element command failed because the referenced element is no longer
|
|
269
248
|
* attached to the DOM.
|
|
@@ -271,44 +250,40 @@ class SessionNotCreatedError extends WebDriverError {
|
|
|
271
250
|
class StaleElementReferenceError extends WebDriverError {
|
|
272
251
|
/** @param {string=} opt_error the error message, if any. */
|
|
273
252
|
constructor(opt_error) {
|
|
274
|
-
super(opt_error)
|
|
253
|
+
super(opt_error)
|
|
275
254
|
}
|
|
276
255
|
}
|
|
277
256
|
|
|
278
|
-
|
|
279
257
|
/**
|
|
280
258
|
* An operation did not complete before its timeout expired.
|
|
281
259
|
*/
|
|
282
260
|
class TimeoutError extends WebDriverError {
|
|
283
261
|
/** @param {string=} opt_error the error message, if any. */
|
|
284
262
|
constructor(opt_error) {
|
|
285
|
-
super(opt_error)
|
|
263
|
+
super(opt_error)
|
|
286
264
|
}
|
|
287
265
|
}
|
|
288
266
|
|
|
289
|
-
|
|
290
267
|
/**
|
|
291
268
|
* A request to set a cookie’s value could not be satisfied.
|
|
292
269
|
*/
|
|
293
270
|
class UnableToSetCookieError extends WebDriverError {
|
|
294
271
|
/** @param {string=} opt_error the error message, if any. */
|
|
295
272
|
constructor(opt_error) {
|
|
296
|
-
super(opt_error)
|
|
273
|
+
super(opt_error)
|
|
297
274
|
}
|
|
298
275
|
}
|
|
299
276
|
|
|
300
|
-
|
|
301
277
|
/**
|
|
302
278
|
* A screen capture operation was not possible.
|
|
303
279
|
*/
|
|
304
280
|
class UnableToCaptureScreenError extends WebDriverError {
|
|
305
281
|
/** @param {string=} opt_error the error message, if any. */
|
|
306
282
|
constructor(opt_error) {
|
|
307
|
-
super(opt_error)
|
|
283
|
+
super(opt_error)
|
|
308
284
|
}
|
|
309
285
|
}
|
|
310
286
|
|
|
311
|
-
|
|
312
287
|
/**
|
|
313
288
|
* A modal dialog was open, blocking this operation.
|
|
314
289
|
*/
|
|
@@ -318,10 +293,10 @@ class UnexpectedAlertOpenError extends WebDriverError {
|
|
|
318
293
|
* @param {string=} opt_text the text of the open dialog, if available.
|
|
319
294
|
*/
|
|
320
295
|
constructor(opt_error, opt_text) {
|
|
321
|
-
super(opt_error)
|
|
296
|
+
super(opt_error)
|
|
322
297
|
|
|
323
298
|
/** @private {(string|undefined)} */
|
|
324
|
-
this.text_ = opt_text
|
|
299
|
+
this.text_ = opt_text
|
|
325
300
|
}
|
|
326
301
|
|
|
327
302
|
/**
|
|
@@ -329,22 +304,20 @@ class UnexpectedAlertOpenError extends WebDriverError {
|
|
|
329
304
|
* if available.
|
|
330
305
|
*/
|
|
331
306
|
getAlertText() {
|
|
332
|
-
return this.text_
|
|
307
|
+
return this.text_
|
|
333
308
|
}
|
|
334
309
|
}
|
|
335
310
|
|
|
336
|
-
|
|
337
311
|
/**
|
|
338
312
|
* A command could not be executed because the remote end is not aware of it.
|
|
339
313
|
*/
|
|
340
314
|
class UnknownCommandError extends WebDriverError {
|
|
341
315
|
/** @param {string=} opt_error the error message, if any. */
|
|
342
316
|
constructor(opt_error) {
|
|
343
|
-
super(opt_error)
|
|
317
|
+
super(opt_error)
|
|
344
318
|
}
|
|
345
319
|
}
|
|
346
320
|
|
|
347
|
-
|
|
348
321
|
/**
|
|
349
322
|
* The requested command matched a known URL but did not match an method for
|
|
350
323
|
* that URL.
|
|
@@ -352,24 +325,22 @@ class UnknownCommandError extends WebDriverError {
|
|
|
352
325
|
class UnknownMethodError extends WebDriverError {
|
|
353
326
|
/** @param {string=} opt_error the error message, if any. */
|
|
354
327
|
constructor(opt_error) {
|
|
355
|
-
super(opt_error)
|
|
328
|
+
super(opt_error)
|
|
356
329
|
}
|
|
357
330
|
}
|
|
358
331
|
|
|
359
|
-
|
|
360
332
|
/**
|
|
361
333
|
* Reports an unsupported operation.
|
|
362
334
|
*/
|
|
363
335
|
class UnsupportedOperationError extends WebDriverError {
|
|
364
336
|
/** @param {string=} opt_error the error message, if any. */
|
|
365
337
|
constructor(opt_error) {
|
|
366
|
-
super(opt_error)
|
|
338
|
+
super(opt_error)
|
|
367
339
|
}
|
|
368
340
|
}
|
|
369
341
|
|
|
370
342
|
// TODO(jleyba): Define UnknownError as an alias of WebDriverError?
|
|
371
343
|
|
|
372
|
-
|
|
373
344
|
/**
|
|
374
345
|
* Enum of legacy error codes.
|
|
375
346
|
* TODO: remove this when all code paths have been switched to the new error
|
|
@@ -412,100 +383,96 @@ const ErrorCode = {
|
|
|
412
383
|
NO_SUCH_COOKIE: 62,
|
|
413
384
|
UNABLE_TO_CAPTURE_SCREEN: 63,
|
|
414
385
|
ELEMENT_CLICK_INTERCEPTED: 64,
|
|
415
|
-
METHOD_NOT_ALLOWED: 405
|
|
416
|
-
}
|
|
417
|
-
|
|
386
|
+
METHOD_NOT_ALLOWED: 405,
|
|
387
|
+
}
|
|
418
388
|
|
|
419
389
|
const LEGACY_ERROR_CODE_TO_TYPE = new Map([
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
390
|
+
[ErrorCode.NO_SUCH_SESSION, NoSuchSessionError],
|
|
391
|
+
[ErrorCode.NO_SUCH_ELEMENT, NoSuchElementError],
|
|
392
|
+
[ErrorCode.NO_SUCH_FRAME, NoSuchFrameError],
|
|
393
|
+
[ErrorCode.UNSUPPORTED_OPERATION, UnsupportedOperationError],
|
|
394
|
+
[ErrorCode.STALE_ELEMENT_REFERENCE, StaleElementReferenceError],
|
|
395
|
+
[ErrorCode.INVALID_ELEMENT_STATE, InvalidElementStateError],
|
|
396
|
+
[ErrorCode.UNKNOWN_ERROR, WebDriverError],
|
|
397
|
+
[ErrorCode.ELEMENT_NOT_SELECTABLE, ElementNotSelectableError],
|
|
398
|
+
[ErrorCode.JAVASCRIPT_ERROR, JavascriptError],
|
|
399
|
+
[ErrorCode.XPATH_LOOKUP_ERROR, InvalidSelectorError],
|
|
400
|
+
[ErrorCode.TIMEOUT, TimeoutError],
|
|
401
|
+
[ErrorCode.NO_SUCH_WINDOW, NoSuchWindowError],
|
|
402
|
+
[ErrorCode.INVALID_COOKIE_DOMAIN, InvalidCookieDomainError],
|
|
403
|
+
[ErrorCode.UNABLE_TO_SET_COOKIE, UnableToSetCookieError],
|
|
404
|
+
[ErrorCode.UNEXPECTED_ALERT_OPEN, UnexpectedAlertOpenError],
|
|
405
|
+
[ErrorCode.NO_SUCH_ALERT, NoSuchAlertError],
|
|
406
|
+
[ErrorCode.SCRIPT_TIMEOUT, ScriptTimeoutError],
|
|
407
|
+
[ErrorCode.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesError],
|
|
408
|
+
[ErrorCode.INVALID_SELECTOR_ERROR, InvalidSelectorError],
|
|
409
|
+
[ErrorCode.SESSION_NOT_CREATED, SessionNotCreatedError],
|
|
410
|
+
[ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS, MoveTargetOutOfBoundsError],
|
|
411
|
+
[ErrorCode.INVALID_XPATH_SELECTOR, InvalidSelectorError],
|
|
412
|
+
[ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPE, InvalidSelectorError],
|
|
413
|
+
[ErrorCode.ELEMENT_NOT_INTERACTABLE, ElementNotInteractableError],
|
|
414
|
+
[ErrorCode.INVALID_ARGUMENT, InvalidArgumentError],
|
|
415
|
+
[ErrorCode.NO_SUCH_COOKIE, NoSuchCookieError],
|
|
416
|
+
[ErrorCode.UNABLE_TO_CAPTURE_SCREEN, UnableToCaptureScreenError],
|
|
417
|
+
[ErrorCode.ELEMENT_CLICK_INTERCEPTED, ElementClickInterceptedError],
|
|
418
|
+
[ErrorCode.METHOD_NOT_ALLOWED, UnsupportedOperationError],
|
|
419
|
+
])
|
|
450
420
|
|
|
451
421
|
const ERROR_CODE_TO_TYPE = new Map([
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
const TYPE_TO_ERROR_CODE = new Map
|
|
422
|
+
['unknown error', WebDriverError],
|
|
423
|
+
['element click intercepted', ElementClickInterceptedError],
|
|
424
|
+
['element not interactable', ElementNotInteractableError],
|
|
425
|
+
['element not selectable', ElementNotSelectableError],
|
|
426
|
+
['insecure certificate', InsecureCertificateError],
|
|
427
|
+
['invalid argument', InvalidArgumentError],
|
|
428
|
+
['invalid cookie domain', InvalidCookieDomainError],
|
|
429
|
+
['invalid coordinates', InvalidCoordinatesError],
|
|
430
|
+
['invalid element state', InvalidElementStateError],
|
|
431
|
+
['invalid selector', InvalidSelectorError],
|
|
432
|
+
['invalid session id', NoSuchSessionError],
|
|
433
|
+
['javascript error', JavascriptError],
|
|
434
|
+
['move target out of bounds', MoveTargetOutOfBoundsError],
|
|
435
|
+
['no such alert', NoSuchAlertError],
|
|
436
|
+
['no such cookie', NoSuchCookieError],
|
|
437
|
+
['no such element', NoSuchElementError],
|
|
438
|
+
['no such frame', NoSuchFrameError],
|
|
439
|
+
['no such window', NoSuchWindowError],
|
|
440
|
+
['script timeout', ScriptTimeoutError],
|
|
441
|
+
['session not created', SessionNotCreatedError],
|
|
442
|
+
['stale element reference', StaleElementReferenceError],
|
|
443
|
+
['timeout', TimeoutError],
|
|
444
|
+
['unable to set cookie', UnableToSetCookieError],
|
|
445
|
+
['unable to capture screen', UnableToCaptureScreenError],
|
|
446
|
+
['unexpected alert open', UnexpectedAlertOpenError],
|
|
447
|
+
['unknown command', UnknownCommandError],
|
|
448
|
+
['unknown method', UnknownMethodError],
|
|
449
|
+
['unsupported operation', UnsupportedOperationError],
|
|
450
|
+
])
|
|
451
|
+
|
|
452
|
+
const TYPE_TO_ERROR_CODE = new Map()
|
|
483
453
|
ERROR_CODE_TO_TYPE.forEach((value, key) => {
|
|
484
|
-
TYPE_TO_ERROR_CODE.set(value, key)
|
|
485
|
-
})
|
|
486
|
-
|
|
487
|
-
|
|
454
|
+
TYPE_TO_ERROR_CODE.set(value, key)
|
|
455
|
+
})
|
|
488
456
|
|
|
489
457
|
/**
|
|
490
458
|
* @param {*} err The error to encode.
|
|
491
459
|
* @return {{error: string, message: string}} the encoded error.
|
|
492
460
|
*/
|
|
493
461
|
function encodeError(err) {
|
|
494
|
-
let type = WebDriverError
|
|
495
|
-
if (
|
|
496
|
-
|
|
497
|
-
|
|
462
|
+
let type = WebDriverError
|
|
463
|
+
if (
|
|
464
|
+
err instanceof WebDriverError &&
|
|
465
|
+
TYPE_TO_ERROR_CODE.has(err.constructor)
|
|
466
|
+
) {
|
|
467
|
+
type = err.constructor
|
|
498
468
|
}
|
|
499
469
|
|
|
500
|
-
let message = err instanceof Error
|
|
501
|
-
? err.message
|
|
502
|
-
: err + '';
|
|
470
|
+
let message = err instanceof Error ? err.message : err + ''
|
|
503
471
|
|
|
504
|
-
let code = /** @type {string} */(TYPE_TO_ERROR_CODE.get(type))
|
|
505
|
-
return {
|
|
472
|
+
let code = /** @type {string} */ (TYPE_TO_ERROR_CODE.get(type))
|
|
473
|
+
return { error: code, message: message }
|
|
506
474
|
}
|
|
507
475
|
|
|
508
|
-
|
|
509
476
|
/**
|
|
510
477
|
* Checks a response object from a server that adheres to the W3C WebDriver
|
|
511
478
|
* protocol.
|
|
@@ -517,10 +484,10 @@ function encodeError(err) {
|
|
|
517
484
|
*/
|
|
518
485
|
function checkResponse(data) {
|
|
519
486
|
if (data && typeof data.error === 'string') {
|
|
520
|
-
let ctor = ERROR_CODE_TO_TYPE.get(data.error) || WebDriverError
|
|
521
|
-
throw new ctor(data.message)
|
|
487
|
+
let ctor = ERROR_CODE_TO_TYPE.get(data.error) || WebDriverError
|
|
488
|
+
throw new ctor(data.message)
|
|
522
489
|
}
|
|
523
|
-
return data
|
|
490
|
+
return data
|
|
524
491
|
}
|
|
525
492
|
|
|
526
493
|
/**
|
|
@@ -533,7 +500,7 @@ function checkResponse(data) {
|
|
|
533
500
|
* @see https://w3c.github.io/webdriver/webdriver-spec.html#protocol
|
|
534
501
|
*/
|
|
535
502
|
function isErrorResponse(data) {
|
|
536
|
-
return data && typeof data === 'object' && typeof data.error === 'string'
|
|
503
|
+
return data && typeof data === 'object' && typeof data.error === 'string'
|
|
537
504
|
}
|
|
538
505
|
|
|
539
506
|
/**
|
|
@@ -546,20 +513,19 @@ function isErrorResponse(data) {
|
|
|
546
513
|
*/
|
|
547
514
|
function throwDecodedError(data) {
|
|
548
515
|
if (isErrorResponse(data)) {
|
|
549
|
-
let ctor = ERROR_CODE_TO_TYPE.get(data.error) || WebDriverError
|
|
550
|
-
let err = new ctor(data.message)
|
|
516
|
+
let ctor = ERROR_CODE_TO_TYPE.get(data.error) || WebDriverError
|
|
517
|
+
let err = new ctor(data.message)
|
|
551
518
|
// TODO(jleyba): remove whichever case is excluded from the final W3C spec.
|
|
552
519
|
if (typeof data.stacktrace === 'string') {
|
|
553
|
-
err.remoteStacktrace = data.stacktrace
|
|
520
|
+
err.remoteStacktrace = data.stacktrace
|
|
554
521
|
} else if (typeof data.stackTrace === 'string') {
|
|
555
|
-
err.remoteStacktrace = data.stackTrace
|
|
522
|
+
err.remoteStacktrace = data.stackTrace
|
|
556
523
|
}
|
|
557
|
-
throw err
|
|
524
|
+
throw err
|
|
558
525
|
}
|
|
559
|
-
throw new WebDriverError('Unknown error: ' + JSON.stringify(data))
|
|
526
|
+
throw new WebDriverError('Unknown error: ' + JSON.stringify(data))
|
|
560
527
|
}
|
|
561
528
|
|
|
562
|
-
|
|
563
529
|
/**
|
|
564
530
|
* Checks a legacy response from the Selenium 2.0 wire protocol for an error.
|
|
565
531
|
* @param {*} responseObj the response object to check.
|
|
@@ -568,37 +534,37 @@ function throwDecodedError(data) {
|
|
|
568
534
|
*/
|
|
569
535
|
function checkLegacyResponse(responseObj) {
|
|
570
536
|
// Handle the legacy Selenium error response format.
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
537
|
+
if (
|
|
538
|
+
responseObj &&
|
|
539
|
+
typeof responseObj === 'object' &&
|
|
540
|
+
typeof responseObj['status'] === 'number' &&
|
|
541
|
+
responseObj['status'] !== 0
|
|
542
|
+
) {
|
|
543
|
+
let status = responseObj['status']
|
|
544
|
+
let ctor = LEGACY_ERROR_CODE_TO_TYPE.get(status) || WebDriverError
|
|
577
545
|
|
|
578
|
-
let value = responseObj['value']
|
|
546
|
+
let value = responseObj['value']
|
|
579
547
|
|
|
580
548
|
if (!value || typeof value !== 'object') {
|
|
581
|
-
throw new ctor(value + '')
|
|
549
|
+
throw new ctor(value + '')
|
|
582
550
|
} else {
|
|
583
|
-
let message = value['message'] + ''
|
|
551
|
+
let message = value['message'] + ''
|
|
584
552
|
if (ctor !== UnexpectedAlertOpenError) {
|
|
585
|
-
throw new ctor(message)
|
|
553
|
+
throw new ctor(message)
|
|
586
554
|
}
|
|
587
555
|
|
|
588
|
-
let text = ''
|
|
556
|
+
let text = ''
|
|
589
557
|
if (value['alert'] && typeof value['alert']['text'] === 'string') {
|
|
590
|
-
text = value['alert']['text']
|
|
558
|
+
text = value['alert']['text']
|
|
591
559
|
}
|
|
592
|
-
throw new UnexpectedAlertOpenError(message, text)
|
|
560
|
+
throw new UnexpectedAlertOpenError(message, text)
|
|
593
561
|
}
|
|
594
562
|
}
|
|
595
|
-
return responseObj
|
|
563
|
+
return responseObj
|
|
596
564
|
}
|
|
597
565
|
|
|
598
|
-
|
|
599
566
|
// PUBLIC API
|
|
600
567
|
|
|
601
|
-
|
|
602
568
|
module.exports = {
|
|
603
569
|
ErrorCode,
|
|
604
570
|
|
|
@@ -636,4 +602,4 @@ module.exports = {
|
|
|
636
602
|
encodeError,
|
|
637
603
|
isErrorResponse,
|
|
638
604
|
throwDecodedError,
|
|
639
|
-
}
|
|
605
|
+
}
|