@appium/base-driver 9.17.0 → 10.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/basedriver/capabilities.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +2 -4
- package/build/lib/basedriver/capabilities.js.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +7 -25
- package/build/lib/basedriver/commands/timeout.js.map +1 -1
- package/build/lib/basedriver/core.d.ts +0 -8
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +8 -18
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/driver.js +2 -2
- package/build/lib/basedriver/driver.js.map +1 -1
- package/build/lib/basedriver/helpers.d.ts +9 -1
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +56 -142
- package/build/lib/basedriver/helpers.js.map +1 -1
- package/build/lib/basedriver/validation.d.ts +7 -0
- package/build/lib/basedriver/validation.d.ts.map +1 -0
- package/build/lib/basedriver/validation.js +130 -0
- package/build/lib/basedriver/validation.js.map +1 -0
- package/build/lib/express/middleware.d.ts +0 -6
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +12 -64
- package/build/lib/express/middleware.js.map +1 -1
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +1 -2
- package/build/lib/express/server.js.map +1 -1
- package/build/lib/helpers/capabilities.d.ts +13 -6
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js +7 -0
- package/build/lib/helpers/capabilities.js.map +1 -1
- package/build/lib/index.d.ts +1 -0
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +3 -1
- package/build/lib/index.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts +0 -8
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +1 -29
- package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
- package/build/lib/protocol/errors.d.ts +171 -277
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +201 -421
- package/build/lib/protocol/errors.js.map +1 -1
- package/build/lib/protocol/helpers.d.ts +6 -6
- package/build/lib/protocol/helpers.d.ts.map +1 -1
- package/build/lib/protocol/helpers.js +11 -7
- package/build/lib/protocol/helpers.js.map +1 -1
- package/build/lib/protocol/protocol.d.ts +5 -0
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +23 -23
- package/build/lib/protocol/protocol.js.map +1 -1
- package/build/lib/protocol/routes.d.ts +6 -715
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +16 -481
- package/build/lib/protocol/routes.js.map +1 -1
- package/build/lib/protocol/validators.d.ts +4 -7
- package/build/lib/protocol/validators.d.ts.map +1 -1
- package/build/lib/protocol/validators.js +4 -24
- package/build/lib/protocol/validators.js.map +1 -1
- package/lib/basedriver/capabilities.ts +2 -4
- package/lib/basedriver/commands/timeout.ts +11 -34
- package/lib/basedriver/core.ts +10 -19
- package/lib/basedriver/driver.ts +3 -3
- package/lib/basedriver/helpers.js +61 -167
- package/lib/basedriver/validation.ts +145 -0
- package/lib/express/middleware.js +16 -75
- package/lib/express/server.js +1 -3
- package/lib/helpers/capabilities.js +9 -4
- package/lib/index.js +2 -0
- package/lib/jsonwp-proxy/proxy.js +2 -33
- package/lib/protocol/{errors.js → errors.ts} +322 -436
- package/lib/protocol/helpers.js +12 -8
- package/lib/protocol/protocol.js +25 -23
- package/lib/protocol/routes.js +18 -491
- package/lib/protocol/validators.ts +19 -0
- package/package.json +10 -10
- package/build/lib/basedriver/desired-caps.d.ts +0 -5
- package/build/lib/basedriver/desired-caps.d.ts.map +0 -1
- package/build/lib/basedriver/desired-caps.js +0 -92
- package/build/lib/basedriver/desired-caps.js.map +0 -1
- package/lib/basedriver/desired-caps.js +0 -103
- package/lib/protocol/validators.js +0 -41
package/lib/protocol/helpers.js
CHANGED
|
@@ -7,17 +7,19 @@ import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY} from '../constants';
|
|
|
7
7
|
* so they have keys for both W3C and JSONWP protocols.
|
|
8
8
|
* The argument value is NOT mutated
|
|
9
9
|
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @returns {
|
|
10
|
+
* @param {Object | undefined} resValue The actual response value
|
|
11
|
+
* @returns {Object | null} Either modified value or the same one if
|
|
12
12
|
* nothing has been modified
|
|
13
13
|
*/
|
|
14
|
-
function formatResponseValue(resValue) {
|
|
14
|
+
export function formatResponseValue(resValue) {
|
|
15
15
|
if (_.isUndefined(resValue)) {
|
|
16
16
|
// convert undefined to null
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
// If the MJSONWP element key format (ELEMENT) was provided,
|
|
20
|
-
//
|
|
19
|
+
// If the MJSONWP element key format (ELEMENT) was provided,
|
|
20
|
+
// add a duplicate key (element-6066-11e4-a52e-4f735466cecf)
|
|
21
|
+
// If the W3C element key format (element-6066-11e4-a52e-4f735466cecf)
|
|
22
|
+
// was provided, add a duplicate key (ELEMENT)
|
|
21
23
|
return duplicateKeys(resValue, MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY);
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -28,8 +30,10 @@ function formatResponseValue(resValue) {
|
|
|
28
30
|
* @param {Object} responseBody
|
|
29
31
|
* @returns {Object} The fixed response body
|
|
30
32
|
*/
|
|
31
|
-
function
|
|
32
|
-
return _.isPlainObject(responseBody)
|
|
33
|
+
export function ensureW3cResponse(responseBody) {
|
|
34
|
+
return _.isPlainObject(responseBody)
|
|
35
|
+
? _.omit(responseBody, ['status', 'sessionId'])
|
|
36
|
+
: responseBody;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
export {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY
|
|
39
|
+
export {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY};
|
package/lib/protocol/protocol.js
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
getResponseForW3CError,
|
|
8
8
|
errorFromMJSONWPStatusCode,
|
|
9
9
|
errorFromW3CJsonCode,
|
|
10
|
+
BadParametersError,
|
|
10
11
|
} from './errors';
|
|
11
12
|
import {METHOD_MAP, NO_SESSION_ID_COMMANDS} from './routes';
|
|
12
13
|
import B from 'bluebird';
|
|
13
|
-
import {formatResponseValue,
|
|
14
|
+
import {formatResponseValue, ensureW3cResponse} from './helpers';
|
|
14
15
|
import {MAX_LOG_BODY_LENGTH, PROTOCOLS, DEFAULT_BASE_PATH} from '../constants';
|
|
15
16
|
import {isW3cCaps} from '../helpers/capabilities';
|
|
16
17
|
import log from '../basedriver/logger';
|
|
@@ -29,21 +30,32 @@ function determineProtocol(createSessionArgs) {
|
|
|
29
30
|
return _.some(createSessionArgs, isW3cCaps) ? PROTOCOLS.W3C : PROTOCOLS.MJSONWP;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {import('../basedriver/driver').BaseDriver} driver
|
|
36
|
+
* @param {string | null} [sessionId=null]
|
|
37
|
+
* @returns {keyof PROTOCOLS}
|
|
38
|
+
*/
|
|
32
39
|
function extractProtocol(driver, sessionId = null) {
|
|
33
|
-
const dstDriver = _.isFunction(driver.driverForSession)
|
|
40
|
+
const dstDriver = _.isFunction(driver.driverForSession) && sessionId
|
|
34
41
|
? driver.driverForSession(sessionId)
|
|
35
42
|
: driver;
|
|
36
43
|
if (dstDriver === driver) {
|
|
37
44
|
// Shortcircuit if the driver instance is not an umbrella driver
|
|
38
45
|
// or it is Fake driver instance, where `driver.driverForSession`
|
|
39
46
|
// always returns self instance
|
|
40
|
-
return driver.protocol;
|
|
47
|
+
return driver.protocol ?? PROTOCOLS.W3C;
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
// Extract the protocol for the current session if the given driver is the umbrella one
|
|
44
51
|
return dstDriver?.protocol ?? PROTOCOLS.W3C;
|
|
45
52
|
}
|
|
46
53
|
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {any} command
|
|
57
|
+
* @returns {boolean}
|
|
58
|
+
*/
|
|
47
59
|
function isSessionCommand(command) {
|
|
48
60
|
return !_.includes(NO_SESSION_ID_COMMANDS, command);
|
|
49
61
|
}
|
|
@@ -123,7 +135,7 @@ export function checkParams(paramSets, jsonObj, protocol) {
|
|
|
123
135
|
if (paramSets.validate) {
|
|
124
136
|
let message = paramSets.validate(jsonObj, protocol);
|
|
125
137
|
if (message) {
|
|
126
|
-
throw new errors.
|
|
138
|
+
throw new errors.InvalidArgumentError(message);
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
141
|
}
|
|
@@ -154,7 +166,7 @@ export function checkParams(paramSets, jsonObj, protocol) {
|
|
|
154
166
|
return;
|
|
155
167
|
}
|
|
156
168
|
}
|
|
157
|
-
throw new
|
|
169
|
+
throw new BadParametersError(paramSets, receivedParams);
|
|
158
170
|
}
|
|
159
171
|
|
|
160
172
|
/*
|
|
@@ -287,9 +299,9 @@ function routeConfiguringFunction(driver) {
|
|
|
287
299
|
}
|
|
288
300
|
|
|
289
301
|
function buildHandler(app, method, path, spec, driver, isSessCmd) {
|
|
290
|
-
let asyncHandler = async (req, res) => {
|
|
302
|
+
let asyncHandler = async (/** @type {import('express').Request} */ req, /** @type {import('express').Response} */ res) => {
|
|
291
303
|
let jsonObj = req.body;
|
|
292
|
-
let httpResBody = {};
|
|
304
|
+
let httpResBody = /** @type {any} */ ({});
|
|
293
305
|
let httpStatus = 200;
|
|
294
306
|
let newSessionId;
|
|
295
307
|
let currentProtocol = extractProtocol(driver, req.params.sessionId);
|
|
@@ -489,24 +501,14 @@ function buildHandler(app, method, path, spec, driver, isSessCmd) {
|
|
|
489
501
|
|
|
490
502
|
// decode the response, which is either a string or json
|
|
491
503
|
if (_.isString(httpResBody)) {
|
|
492
|
-
res.status(httpStatus)
|
|
504
|
+
res.status(httpStatus)
|
|
505
|
+
.setHeader('content-type', 'application/json; charset=utf-8')
|
|
506
|
+
.send(httpResBody);
|
|
493
507
|
} else {
|
|
494
|
-
if (newSessionId) {
|
|
495
|
-
|
|
496
|
-
httpResBody.value.sessionId = newSessionId;
|
|
497
|
-
} else {
|
|
498
|
-
httpResBody.sessionId = newSessionId;
|
|
499
|
-
}
|
|
500
|
-
} else {
|
|
501
|
-
httpResBody.sessionId = req.params.sessionId || null;
|
|
508
|
+
if (newSessionId && currentProtocol === PROTOCOLS.W3C) {
|
|
509
|
+
httpResBody.value.sessionId = newSessionId;
|
|
502
510
|
}
|
|
503
|
-
|
|
504
|
-
if (currentProtocol === PROTOCOLS.W3C) {
|
|
505
|
-
delete httpResBody.sessionId;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
httpResBody = formatStatus(httpResBody);
|
|
509
|
-
res.status(httpStatus).json(httpResBody);
|
|
511
|
+
res.status(httpStatus).json(ensureW3cResponse(httpResBody));
|
|
510
512
|
}
|
|
511
513
|
};
|
|
512
514
|
// add the method to the app
|