@appium/base-driver 10.2.0 → 10.2.2
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/LICENSE +201 -0
- package/build/lib/basedriver/capabilities.js +7 -7
- package/build/lib/basedriver/capabilities.js.map +1 -1
- package/build/lib/basedriver/commands/event.d.ts +1 -1
- package/build/lib/basedriver/commands/event.d.ts.map +1 -1
- package/build/lib/basedriver/commands/execute.d.ts +1 -1
- package/build/lib/basedriver/commands/execute.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.d.ts +1 -1
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/mixin.d.ts +1 -1
- package/build/lib/basedriver/commands/mixin.d.ts.map +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.d.ts +14 -23
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js +11 -26
- package/build/lib/basedriver/device-settings.js.map +1 -1
- package/build/lib/basedriver/helpers.d.ts +36 -57
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +148 -239
- package/build/lib/basedriver/helpers.js.map +1 -1
- package/build/lib/basedriver/logger.d.ts +1 -2
- package/build/lib/basedriver/logger.d.ts.map +1 -1
- package/build/lib/basedriver/logger.js +2 -2
- package/build/lib/basedriver/logger.js.map +1 -1
- package/build/lib/basedriver/validation.d.ts.map +1 -1
- package/build/lib/basedriver/validation.js +3 -3
- package/build/lib/basedriver/validation.js.map +1 -1
- package/build/lib/constants.d.ts +1 -1
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/express/crash.d.ts +8 -2
- package/build/lib/express/crash.d.ts.map +1 -1
- package/build/lib/express/crash.js +6 -0
- package/build/lib/express/crash.js.map +1 -1
- package/build/lib/express/express-logging.d.ts +12 -2
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +34 -26
- package/build/lib/express/express-logging.js.map +1 -1
- package/build/lib/express/idempotency.d.ts +4 -10
- package/build/lib/express/idempotency.d.ts.map +1 -1
- package/build/lib/express/idempotency.js +69 -73
- package/build/lib/express/idempotency.js.map +1 -1
- package/build/lib/express/logger.d.ts +1 -2
- package/build/lib/express/logger.d.ts.map +1 -1
- package/build/lib/express/logger.js +2 -2
- package/build/lib/express/logger.js.map +1 -1
- package/build/lib/express/middleware.d.ts +37 -41
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +48 -60
- package/build/lib/express/middleware.js.map +1 -1
- package/build/lib/express/server.d.ts +57 -101
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +51 -128
- package/build/lib/express/server.js.map +1 -1
- package/build/lib/express/static.d.ts +10 -5
- package/build/lib/express/static.d.ts.map +1 -1
- package/build/lib/express/static.js +32 -42
- package/build/lib/express/static.js.map +1 -1
- package/build/lib/express/websocket.d.ts +22 -6
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js +10 -15
- package/build/lib/express/websocket.js.map +1 -1
- package/build/lib/helpers/capabilities.d.ts +4 -16
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js +36 -48
- package/build/lib/helpers/capabilities.js.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts +42 -78
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.js +87 -139
- package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +2 -2
- package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
- package/build/lib/jsonwp-status/status.d.ts +113 -158
- package/build/lib/jsonwp-status/status.d.ts.map +1 -1
- package/build/lib/jsonwp-status/status.js +10 -14
- package/build/lib/jsonwp-status/status.js.map +1 -1
- package/build/lib/protocol/bidi-commands.d.ts +31 -36
- package/build/lib/protocol/bidi-commands.d.ts.map +1 -1
- package/build/lib/protocol/bidi-commands.js +5 -5
- package/build/lib/protocol/bidi-commands.js.map +1 -1
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/helpers.d.ts +7 -11
- package/build/lib/protocol/helpers.d.ts.map +1 -1
- package/build/lib/protocol/helpers.js +5 -9
- package/build/lib/protocol/helpers.js.map +1 -1
- package/build/lib/protocol/index.d.ts +4 -21
- package/build/lib/protocol/index.d.ts.map +1 -1
- package/build/lib/protocol/index.js.map +1 -1
- package/build/lib/protocol/protocol.d.ts +15 -1
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +50 -20
- package/build/lib/protocol/protocol.js.map +1 -1
- package/build/lib/protocol/routes.d.ts +8 -15
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +18 -33
- package/build/lib/protocol/routes.js.map +1 -1
- package/lib/basedriver/capabilities.ts +1 -1
- package/lib/basedriver/commands/event.ts +2 -2
- package/lib/basedriver/commands/execute.ts +2 -2
- package/lib/basedriver/commands/find.ts +2 -2
- package/lib/basedriver/commands/mixin.ts +1 -1
- package/lib/basedriver/commands/timeout.ts +2 -2
- package/lib/basedriver/{device-settings.js → device-settings.ts} +24 -35
- package/lib/basedriver/{helpers.js → helpers.ts} +208 -266
- package/lib/basedriver/logger.ts +3 -0
- package/lib/basedriver/validation.ts +2 -2
- package/lib/constants.ts +1 -1
- package/lib/express/crash.ts +15 -0
- package/lib/express/express-logging.ts +84 -0
- package/lib/express/{idempotency.js → idempotency.ts} +105 -89
- package/lib/express/logger.ts +3 -0
- package/lib/express/middleware.ts +187 -0
- package/lib/express/{server.js → server.ts} +175 -167
- package/lib/express/static.ts +77 -0
- package/lib/express/websocket.ts +81 -0
- package/lib/helpers/capabilities.ts +83 -0
- package/lib/jsonwp-proxy/protocol-converter.ts +284 -0
- package/lib/jsonwp-proxy/proxy.js +1 -1
- package/lib/jsonwp-status/{status.js → status.ts} +12 -15
- package/lib/protocol/{bidi-commands.js → bidi-commands.ts} +7 -5
- package/lib/protocol/errors.ts +1 -1
- package/lib/protocol/{helpers.js → helpers.ts} +8 -11
- package/lib/protocol/protocol.ts +57 -26
- package/lib/protocol/{routes.js → routes.ts} +29 -40
- package/package.json +11 -11
- package/tsconfig.json +3 -1
- package/lib/basedriver/logger.js +0 -4
- package/lib/express/crash.js +0 -11
- package/lib/express/express-logging.js +0 -60
- package/lib/express/logger.js +0 -4
- package/lib/express/middleware.js +0 -171
- package/lib/express/static.js +0 -76
- package/lib/express/websocket.js +0 -79
- package/lib/helpers/capabilities.js +0 -93
- package/lib/jsonwp-proxy/protocol-converter.js +0 -317
- /package/lib/protocol/{index.js → index.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../lib/helpers/capabilities.
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../lib/helpers/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAG5F;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,eAAe,CAAC,WAAW,CAAC,CAqB7E;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,EAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,qBAAqB,EAAE,CAAC,EACxB,GAAG,EAAE,YAAY,GAChB,YAAY,CAAC,CAAC,CAAC,CA6CjB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @ts-check
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
4
|
};
|
|
@@ -10,76 +9,65 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
10
9
|
/**
|
|
11
10
|
* Determine whether the given argument is valid
|
|
12
11
|
* W3C capabilities instance.
|
|
13
|
-
*
|
|
14
|
-
* @param {any} caps
|
|
15
|
-
* @returns {caps is import('@appium/types').W3CCapabilities}
|
|
16
12
|
*/
|
|
17
13
|
function isW3cCaps(caps) {
|
|
18
14
|
if (!lodash_1.default.isPlainObject(caps)) {
|
|
19
15
|
return false;
|
|
20
16
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
lodash_1.default.
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const c = caps;
|
|
18
|
+
const isFirstMatchValid = () => lodash_1.default.isArray(c.firstMatch) &&
|
|
19
|
+
!lodash_1.default.isEmpty(c.firstMatch) &&
|
|
20
|
+
lodash_1.default.every(c.firstMatch, lodash_1.default.isPlainObject);
|
|
21
|
+
const isAlwaysMatchValid = () => lodash_1.default.isPlainObject(c.alwaysMatch);
|
|
22
|
+
if (lodash_1.default.has(c, 'firstMatch') && lodash_1.default.has(c, 'alwaysMatch')) {
|
|
26
23
|
return isFirstMatchValid() && isAlwaysMatchValid();
|
|
27
24
|
}
|
|
28
|
-
if (lodash_1.default.has(
|
|
25
|
+
if (lodash_1.default.has(c, 'firstMatch')) {
|
|
29
26
|
return isFirstMatchValid();
|
|
30
27
|
}
|
|
31
|
-
if (lodash_1.default.has(
|
|
28
|
+
if (lodash_1.default.has(c, 'alwaysMatch')) {
|
|
32
29
|
return isAlwaysMatchValid();
|
|
33
30
|
}
|
|
34
31
|
return false;
|
|
35
32
|
}
|
|
36
33
|
/**
|
|
37
|
-
*
|
|
38
|
-
* @template {Constraints} C
|
|
39
|
-
* @param {any} oldCaps
|
|
40
|
-
* @param {C} desiredCapConstraints
|
|
41
|
-
* @param {AppiumLogger} log
|
|
42
|
-
* @returns {Capabilities<C>}
|
|
34
|
+
* Normalize capability values according to constraints (e.g. string 'true' → boolean).
|
|
43
35
|
*/
|
|
44
36
|
function fixCaps(oldCaps, desiredCapConstraints, log) {
|
|
45
|
-
|
|
37
|
+
const caps = lodash_1.default.clone(oldCaps);
|
|
38
|
+
const logCastWarning = (prefix) => log.warn(`${prefix}. This may cause unexpected behavior`);
|
|
46
39
|
// boolean capabilities can be passed in as strings 'false' and 'true'
|
|
47
40
|
// which we want to translate into boolean values
|
|
48
|
-
|
|
49
|
-
for (
|
|
50
|
-
|
|
51
|
-
if (lodash_1.default.isString(value)) {
|
|
52
|
-
|
|
53
|
-
if (value === 'true' || value === 'false') {
|
|
54
|
-
log.warn(`Capability '${cap}' changed from string to boolean. This may cause unexpected behavior`);
|
|
55
|
-
caps[cap] = value === 'true';
|
|
56
|
-
}
|
|
41
|
+
const booleanCaps = lodash_1.default.keys(lodash_1.default.pickBy(desiredCapConstraints, (k) => k.isBoolean === true));
|
|
42
|
+
for (const cap of booleanCaps) {
|
|
43
|
+
const value = oldCaps[cap];
|
|
44
|
+
if (!lodash_1.default.isString(value)) {
|
|
45
|
+
continue;
|
|
57
46
|
}
|
|
47
|
+
if (!['true', 'false'].includes(value.toLowerCase())) {
|
|
48
|
+
logCastWarning(`String capability '${cap}' ('${value}') cannot be converted to a boolean`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
logCastWarning(`Capability '${cap}' changed from string '${value}' to boolean`);
|
|
52
|
+
caps[cap] = value.toLowerCase() === 'true';
|
|
58
53
|
}
|
|
59
54
|
// int capabilities are often sent in as strings by frameworks
|
|
60
|
-
|
|
61
|
-
for (
|
|
62
|
-
|
|
63
|
-
if (lodash_1.default.isString(value)) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
55
|
+
const intCaps = lodash_1.default.keys(lodash_1.default.pickBy(desiredCapConstraints, (k) => k.isNumber === true));
|
|
56
|
+
for (const cap of intCaps) {
|
|
57
|
+
const value = oldCaps[cap];
|
|
58
|
+
if (!lodash_1.default.isString(value)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const intValue = parseInt(value, 10);
|
|
62
|
+
const floatValue = parseFloat(value);
|
|
63
|
+
const newValue = floatValue !== intValue ? floatValue : intValue;
|
|
64
|
+
if (Number.isNaN(newValue)) {
|
|
65
|
+
logCastWarning(`String capability '${cap}' ('${value}') cannot be converted to a number`);
|
|
66
|
+
continue;
|
|
71
67
|
}
|
|
68
|
+
logCastWarning(`Capability '${cap}' changed from string '${value}' to number ${newValue}`);
|
|
69
|
+
caps[cap] = newValue;
|
|
72
70
|
}
|
|
73
71
|
return caps;
|
|
74
72
|
}
|
|
75
|
-
/**
|
|
76
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
77
|
-
* @typedef {import('@appium/types').AppiumLogger} AppiumLogger
|
|
78
|
-
* @typedef {import('@appium/types').StringRecord} StringRecord
|
|
79
|
-
* @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
|
|
80
|
-
*/
|
|
81
|
-
/**
|
|
82
|
-
* @template {Constraints} C
|
|
83
|
-
* @typedef {import('@appium/types').Capabilities<C>} Capabilities
|
|
84
|
-
*/
|
|
85
73
|
//# sourceMappingURL=capabilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../lib/helpers/capabilities.
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../lib/helpers/capabilities.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,89 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import type { AppiumLogger, HTTPBody, ProxyResponse } from '@appium/types';
|
|
2
|
+
export type ProxyFunction = (url: string, method: string, body?: HTTPBody) => Promise<[ProxyResponse, HTTPBody]>;
|
|
3
|
+
export declare const COMMAND_URLS_CONFLICTS: readonly [{
|
|
4
|
+
readonly commandNames: readonly ["execute", "executeAsync"];
|
|
5
|
+
readonly jsonwpConverter: (url: string) => string;
|
|
6
|
+
readonly w3cConverter: (url: string) => string;
|
|
7
|
+
}, {
|
|
8
|
+
readonly commandNames: readonly ["getElementScreenshot"];
|
|
9
|
+
readonly jsonwpConverter: (url: string) => string;
|
|
10
|
+
readonly w3cConverter: (url: string) => string;
|
|
11
|
+
}, {
|
|
12
|
+
readonly commandNames: readonly ["getWindowHandles", "getWindowHandle"];
|
|
13
|
+
readonly jsonwpConverter: (url: string) => string;
|
|
14
|
+
readonly w3cConverter: (url: string) => string;
|
|
15
|
+
}, {
|
|
16
|
+
readonly commandNames: readonly ["getProperty"];
|
|
17
|
+
readonly jsonwpConverter: (w3cUrl: string) => string;
|
|
18
|
+
readonly w3cConverter: (jsonwpUrl: string) => string;
|
|
19
|
+
}];
|
|
20
|
+
export declare class ProtocolConverter {
|
|
15
21
|
proxyFunc: ProxyFunction;
|
|
16
|
-
_downstreamProtocol
|
|
17
|
-
|
|
18
|
-
get log(): import("@appium/types").AppiumLogger;
|
|
19
|
-
set downstreamProtocol(value: any);
|
|
20
|
-
get downstreamProtocol(): any;
|
|
21
|
-
/**
|
|
22
|
-
* W3C /timeouts can take as many as 3 timeout types at once, MJSONWP /timeouts only takes one
|
|
23
|
-
* at a time. So if we're using W3C and proxying to MJSONWP and there's more than one timeout type
|
|
24
|
-
* provided in the request, we need to do 3 proxies and combine the result
|
|
25
|
-
*
|
|
26
|
-
* @param {Object} body Request body
|
|
27
|
-
* @return {Object[]} Array of W3C + MJSONWP compatible timeout objects
|
|
28
|
-
*/
|
|
29
|
-
getTimeoutRequestObjects(body: any): any[];
|
|
30
|
-
/**
|
|
31
|
-
* Proxy an array of timeout objects and merge the result
|
|
32
|
-
* @param {string} url Endpoint url
|
|
33
|
-
* @param {string} method Endpoint method
|
|
34
|
-
* @param {import('@appium/types').HTTPBody} body Request body
|
|
35
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
36
|
-
*/
|
|
37
|
-
proxySetTimeouts(url: string, method: string, body: import("@appium/types").HTTPBody): Promise<[import("@appium/types").ProxyResponse, import("@appium/types").HTTPBody]>;
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {string} url
|
|
41
|
-
* @param {string} method
|
|
42
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
43
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
44
|
-
*/
|
|
45
|
-
proxySetWindow(url: string, method: string, body: import("@appium/types").HTTPBody): Promise<[import("@appium/types").ProxyResponse, import("@appium/types").HTTPBody]>;
|
|
22
|
+
private _downstreamProtocol;
|
|
23
|
+
private readonly _log;
|
|
46
24
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @param
|
|
49
|
-
* @param {string} method
|
|
50
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
51
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
25
|
+
* @param proxyFunc - Function to perform the actual proxy request
|
|
26
|
+
* @param log - Logger instance, or null to use the default
|
|
52
27
|
*/
|
|
53
|
-
|
|
28
|
+
constructor(proxyFunc: ProxyFunction, log?: AppiumLogger | null);
|
|
29
|
+
get log(): AppiumLogger;
|
|
30
|
+
set downstreamProtocol(value: string | null | undefined);
|
|
31
|
+
get downstreamProtocol(): string | null | undefined;
|
|
54
32
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @param {string} method
|
|
58
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
59
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
33
|
+
* Handle "crossing" endpoints for the case when upstream and downstream
|
|
34
|
+
* drivers operate different protocols.
|
|
60
35
|
*/
|
|
61
|
-
|
|
36
|
+
convertAndProxy(commandName: string, url: string, method: string, body?: HTTPBody): Promise<[ProxyResponse, HTTPBody]>;
|
|
62
37
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
67
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
68
|
-
*/
|
|
69
|
-
proxyPerformActions(url: string, method: string, body: import("@appium/types").HTTPBody): Promise<[import("@appium/types").ProxyResponse, import("@appium/types").HTTPBody]>;
|
|
70
|
-
/**
|
|
71
|
-
*
|
|
72
|
-
* @param {string} url
|
|
73
|
-
* @param {string} method
|
|
74
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
38
|
+
* W3C /timeouts can take as many as 3 timeout types at once, MJSONWP /timeouts only takes one
|
|
39
|
+
* at a time. So if we're using W3C and proxying to MJSONWP and there's more than one timeout type
|
|
40
|
+
* provided in the request, we need to do 3 proxies and combine the result.
|
|
75
41
|
*/
|
|
76
|
-
|
|
42
|
+
private getTimeoutRequestObjects;
|
|
77
43
|
/**
|
|
78
|
-
*
|
|
79
|
-
* when upstream and downstream drivers operate different protocols
|
|
80
|
-
*
|
|
81
|
-
* @param {string} commandName
|
|
82
|
-
* @param {string} url
|
|
83
|
-
* @param {string} method
|
|
84
|
-
* @param {import('@appium/types').HTTPBody} [body]
|
|
85
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
44
|
+
* Proxy an array of timeout objects and merge the result.
|
|
86
45
|
*/
|
|
87
|
-
|
|
46
|
+
private proxySetTimeouts;
|
|
47
|
+
private proxySetWindow;
|
|
48
|
+
private proxySetValue;
|
|
49
|
+
private proxySetFrame;
|
|
50
|
+
private proxyPerformActions;
|
|
51
|
+
private proxyReleaseActions;
|
|
88
52
|
}
|
|
89
53
|
//# sourceMappingURL=protocol-converter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-converter.d.ts","sourceRoot":"","sources":["../../../lib/jsonwp-proxy/protocol-converter.
|
|
1
|
+
{"version":3,"file":"protocol-converter.d.ts","sourceRoot":"","sources":["../../../lib/jsonwp-proxy/protocol-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAMzE,MAAM,MAAM,aAAa,GAAG,CAC1B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,QAAQ,KACZ,OAAO,CAAC,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAExC,eAAO,MAAM,sBAAsB;;oCAGR,MAAM;iCAET,MAAM;;;oCAKH,MAAM;iCACT,MAAM;;;oCAIL,MAAM;iCAKT,MAAM;;;uCAQE,MAAM;uCAKN,MAAM;EAE1B,CAAC;AAKX,qBAAa,iBAAiB;IASnB,SAAS,EAAE,aAAa;IARjC,OAAO,CAAC,mBAAmB,CAAmC;IAC9D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsB;IAE3C;;;OAGG;gBAEM,SAAS,EAAE,aAAa,EAC/B,GAAG,GAAE,YAAY,GAAG,IAAW;IAKjC,IAAI,GAAG,IAAI,YAAY,CAEtB;IAED,IAAI,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAEtD;IAED,IAAI,kBAAkB,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS,CAElD;IAED;;;OAGG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,QAAQ,GACd,OAAO,CAAC,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IA8CrC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IA6BhC;;OAEG;YACW,gBAAgB;YA+BhB,cAAc;YAwBd,aAAa;YAoBb,aAAa;YAeb,mBAAmB;YAgBnB,mBAAmB;CAMlC"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.COMMAND_URLS_CONFLICTS = void 0;
|
|
6
|
+
exports.ProtocolConverter = exports.COMMAND_URLS_CONFLICTS = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const support_1 = require("@appium/support");
|
|
9
9
|
const helpers_1 = require("../basedriver/helpers");
|
|
@@ -36,23 +36,24 @@ exports.COMMAND_URLS_CONFLICTS = [
|
|
|
36
36
|
commandNames: ['getProperty'],
|
|
37
37
|
jsonwpConverter: (w3cUrl) => {
|
|
38
38
|
const w3cPropertyRegex = /\/element\/([^/]+)\/property\/([^/]+)/;
|
|
39
|
-
|
|
40
|
-
return jsonwpUrl;
|
|
39
|
+
return w3cUrl.replace(w3cPropertyRegex, '/element/$1/attribute/$2');
|
|
41
40
|
},
|
|
42
|
-
|
|
41
|
+
// Don't convert JSONWP URL to W3C. W3C accepts /attribute and /property
|
|
42
|
+
w3cConverter: (jsonwpUrl) => jsonwpUrl,
|
|
43
43
|
},
|
|
44
44
|
];
|
|
45
45
|
const { MJSONWP, W3C } = constants_1.PROTOCOLS;
|
|
46
46
|
const DEFAULT_LOG = support_1.logger.getLogger('Protocol Converter');
|
|
47
47
|
class ProtocolConverter {
|
|
48
|
+
proxyFunc;
|
|
49
|
+
_downstreamProtocol = null;
|
|
50
|
+
_log;
|
|
48
51
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param
|
|
51
|
-
* @param {import('@appium/types').AppiumLogger | null} [log=null]
|
|
52
|
+
* @param proxyFunc - Function to perform the actual proxy request
|
|
53
|
+
* @param log - Logger instance, or null to use the default
|
|
52
54
|
*/
|
|
53
55
|
constructor(proxyFunc, log = null) {
|
|
54
56
|
this.proxyFunc = proxyFunc;
|
|
55
|
-
this._downstreamProtocol = null;
|
|
56
57
|
this._log = log;
|
|
57
58
|
}
|
|
58
59
|
get log() {
|
|
@@ -64,48 +65,88 @@ class ProtocolConverter {
|
|
|
64
65
|
get downstreamProtocol() {
|
|
65
66
|
return this._downstreamProtocol;
|
|
66
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle "crossing" endpoints for the case when upstream and downstream
|
|
70
|
+
* drivers operate different protocols.
|
|
71
|
+
*/
|
|
72
|
+
async convertAndProxy(commandName, url, method, body) {
|
|
73
|
+
if (!this.downstreamProtocol) {
|
|
74
|
+
return await this.proxyFunc(url, method, body);
|
|
75
|
+
}
|
|
76
|
+
// Same url, but different arguments
|
|
77
|
+
switch (commandName) {
|
|
78
|
+
case 'timeouts':
|
|
79
|
+
return await this.proxySetTimeouts(url, method, body);
|
|
80
|
+
case 'setWindow':
|
|
81
|
+
return await this.proxySetWindow(url, method, body);
|
|
82
|
+
case 'setValue':
|
|
83
|
+
return await this.proxySetValue(url, method, body);
|
|
84
|
+
case 'performActions':
|
|
85
|
+
return await this.proxyPerformActions(url, method, body);
|
|
86
|
+
case 'releaseActions':
|
|
87
|
+
return await this.proxyReleaseActions(url, method);
|
|
88
|
+
case 'setFrame':
|
|
89
|
+
return await this.proxySetFrame(url, method, body);
|
|
90
|
+
default:
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
// Same arguments, but different URLs
|
|
94
|
+
for (const { commandNames, jsonwpConverter, w3cConverter } of exports.COMMAND_URLS_CONFLICTS) {
|
|
95
|
+
if (!commandNames.includes(commandName)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const rewrittenUrl = this.downstreamProtocol === MJSONWP ? jsonwpConverter(url) : w3cConverter(url);
|
|
99
|
+
if (rewrittenUrl === url) {
|
|
100
|
+
this.log.debug(`Did not know how to rewrite the original URL '${url}' for ${this.downstreamProtocol} protocol`);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
this.log.info(`Rewrote the original URL '${url}' to '${rewrittenUrl}' for ${this.downstreamProtocol} protocol`);
|
|
104
|
+
return await this.proxyFunc(rewrittenUrl, method, body);
|
|
105
|
+
}
|
|
106
|
+
// No matches found. Proceed normally
|
|
107
|
+
return await this.proxyFunc(url, method, body);
|
|
108
|
+
}
|
|
67
109
|
/**
|
|
68
110
|
* W3C /timeouts can take as many as 3 timeout types at once, MJSONWP /timeouts only takes one
|
|
69
111
|
* at a time. So if we're using W3C and proxying to MJSONWP and there's more than one timeout type
|
|
70
|
-
* provided in the request, we need to do 3 proxies and combine the result
|
|
71
|
-
*
|
|
72
|
-
* @param {Object} body Request body
|
|
73
|
-
* @return {Object[]} Array of W3C + MJSONWP compatible timeout objects
|
|
112
|
+
* provided in the request, we need to do 3 proxies and combine the result.
|
|
74
113
|
*/
|
|
75
114
|
getTimeoutRequestObjects(body) {
|
|
76
|
-
if (
|
|
115
|
+
if (lodash_1.default.isNil(body)) {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
const bodyObj = support_1.util.safeJsonParse(body) ?? {};
|
|
119
|
+
if (this.downstreamProtocol === W3C && lodash_1.default.has(bodyObj, 'ms') && lodash_1.default.has(bodyObj, 'type')) {
|
|
77
120
|
const typeToW3C = (x) => (x === 'page load' ? 'pageLoad' : x);
|
|
78
121
|
return [
|
|
79
122
|
{
|
|
80
|
-
[typeToW3C(
|
|
123
|
+
[typeToW3C(bodyObj.type)]: bodyObj.ms,
|
|
81
124
|
},
|
|
82
125
|
];
|
|
83
126
|
}
|
|
84
|
-
if (this.downstreamProtocol === MJSONWP && (!lodash_1.default.has(
|
|
127
|
+
if (this.downstreamProtocol === MJSONWP && (!lodash_1.default.has(bodyObj, 'ms') || !lodash_1.default.has(bodyObj, 'type'))) {
|
|
85
128
|
const typeToJSONWP = (x) => (x === 'pageLoad' ? 'page load' : x);
|
|
86
|
-
return
|
|
129
|
+
return lodash_1.default.toPairs(bodyObj)
|
|
87
130
|
// Only transform the entry if ms value is a valid positive float number
|
|
88
131
|
.filter((pair) => /^\d+(?:[.,]\d*?)?$/.test(`${pair[1]}`))
|
|
89
|
-
.map(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
ms: pair[1],
|
|
93
|
-
};
|
|
132
|
+
.map((pair) => ({
|
|
133
|
+
type: typeToJSONWP(pair[0]),
|
|
134
|
+
ms: pair[1],
|
|
94
135
|
}));
|
|
95
136
|
}
|
|
96
|
-
return [
|
|
137
|
+
return [bodyObj];
|
|
97
138
|
}
|
|
98
139
|
/**
|
|
99
|
-
* Proxy an array of timeout objects and merge the result
|
|
100
|
-
* @param {string} url Endpoint url
|
|
101
|
-
* @param {string} method Endpoint method
|
|
102
|
-
* @param {import('@appium/types').HTTPBody} body Request body
|
|
103
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
140
|
+
* Proxy an array of timeout objects and merge the result.
|
|
104
141
|
*/
|
|
105
142
|
async proxySetTimeouts(url, method, body) {
|
|
106
|
-
let response, resBody;
|
|
107
143
|
const timeoutRequestObjects = this.getTimeoutRequestObjects(body);
|
|
144
|
+
if (timeoutRequestObjects.length === 0) {
|
|
145
|
+
return await this.proxyFunc(url, method, body);
|
|
146
|
+
}
|
|
108
147
|
this.log.debug(`Will send the following request bodies to /timeouts: ${JSON.stringify(timeoutRequestObjects)}`);
|
|
148
|
+
let response;
|
|
149
|
+
let resBody;
|
|
109
150
|
for (const timeoutObj of timeoutRequestObjects) {
|
|
110
151
|
[response, resBody] = await this.proxyFunc(url, method, timeoutObj);
|
|
111
152
|
// If we got a non-MJSONWP response, return the result, nothing left to do
|
|
@@ -118,47 +159,28 @@ class ProtocolConverter {
|
|
|
118
159
|
}
|
|
119
160
|
// ...Otherwise, continue to the next timeouts call
|
|
120
161
|
}
|
|
121
|
-
return [
|
|
162
|
+
return [response, resBody];
|
|
122
163
|
}
|
|
123
|
-
/**
|
|
124
|
-
*
|
|
125
|
-
* @param {string} url
|
|
126
|
-
* @param {string} method
|
|
127
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
128
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
129
|
-
*/
|
|
130
164
|
async proxySetWindow(url, method, body) {
|
|
131
165
|
const bodyObj = support_1.util.safeJsonParse(body);
|
|
132
166
|
if (lodash_1.default.isPlainObject(bodyObj)) {
|
|
167
|
+
const obj = bodyObj;
|
|
133
168
|
if (this.downstreamProtocol === W3C && lodash_1.default.has(bodyObj, 'name') && !lodash_1.default.has(bodyObj, 'handle')) {
|
|
134
|
-
this.log.debug(`Copied 'name' value '${
|
|
135
|
-
return await this.proxyFunc(url, method, {
|
|
136
|
-
... /** @type {import('@appium/types').StringRecord} */(bodyObj),
|
|
137
|
-
handle: /** @type {import('@appium/types').StringRecord} */ (bodyObj).name,
|
|
138
|
-
});
|
|
169
|
+
this.log.debug(`Copied 'name' value '${obj.name}' to 'handle' as per W3C spec`);
|
|
170
|
+
return await this.proxyFunc(url, method, { ...obj, handle: obj.name });
|
|
139
171
|
}
|
|
140
172
|
if (this.downstreamProtocol === MJSONWP &&
|
|
141
173
|
lodash_1.default.has(bodyObj, 'handle') &&
|
|
142
174
|
!lodash_1.default.has(bodyObj, 'name')) {
|
|
143
|
-
this.log.debug(`Copied 'handle' value '${
|
|
144
|
-
return await this.proxyFunc(url, method, {
|
|
145
|
-
... /** @type {import('@appium/types').StringRecord} */(bodyObj),
|
|
146
|
-
name: /** @type {import('@appium/types').StringRecord} */ (bodyObj).handle,
|
|
147
|
-
});
|
|
175
|
+
this.log.debug(`Copied 'handle' value '${obj.handle}' to 'name' as per JSONWP spec`);
|
|
176
|
+
return await this.proxyFunc(url, method, { ...obj, name: obj.handle });
|
|
148
177
|
}
|
|
149
178
|
}
|
|
150
179
|
return await this.proxyFunc(url, method, body);
|
|
151
180
|
}
|
|
152
|
-
/**
|
|
153
|
-
*
|
|
154
|
-
* @param {string} url
|
|
155
|
-
* @param {string} method
|
|
156
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
157
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
158
|
-
*/
|
|
159
181
|
async proxySetValue(url, method, body) {
|
|
160
182
|
const bodyObj = support_1.util.safeJsonParse(body);
|
|
161
|
-
if (lodash_1.default.isPlainObject(bodyObj) && (support_1.util.hasValue(bodyObj
|
|
183
|
+
if (lodash_1.default.isPlainObject(bodyObj) && (support_1.util.hasValue(bodyObj?.text) || support_1.util.hasValue(bodyObj?.value))) {
|
|
162
184
|
let { text, value } = bodyObj;
|
|
163
185
|
if (support_1.util.hasValue(text) && !support_1.util.hasValue(value)) {
|
|
164
186
|
value = lodash_1.default.isString(text) ? [...text] : lodash_1.default.isArray(text) ? text : [];
|
|
@@ -168,104 +190,30 @@ class ProtocolConverter {
|
|
|
168
190
|
text = lodash_1.default.isArray(value) ? value.join('') : lodash_1.default.isString(value) ? value : '';
|
|
169
191
|
this.log.debug(`Added 'text' property to 'setValue' request body`);
|
|
170
192
|
}
|
|
171
|
-
return await this.proxyFunc(url, method, {
|
|
172
|
-
...bodyObj,
|
|
173
|
-
text,
|
|
174
|
-
value,
|
|
175
|
-
});
|
|
193
|
+
return await this.proxyFunc(url, method, { ...bodyObj, text, value });
|
|
176
194
|
}
|
|
177
195
|
return await this.proxyFunc(url, method, body);
|
|
178
196
|
}
|
|
179
|
-
/**
|
|
180
|
-
*
|
|
181
|
-
* @param {string} url
|
|
182
|
-
* @param {string} method
|
|
183
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
184
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
185
|
-
*/
|
|
186
197
|
async proxySetFrame(url, method, body) {
|
|
187
198
|
const bodyObj = support_1.util.safeJsonParse(body);
|
|
188
|
-
|
|
189
|
-
|
|
199
|
+
if (lodash_1.default.has(bodyObj, 'id') && lodash_1.default.isPlainObject(bodyObj.id)) {
|
|
200
|
+
return await this.proxyFunc(url, method, {
|
|
190
201
|
...bodyObj,
|
|
191
202
|
id: (0, helpers_1.duplicateKeys)(bodyObj.id, constants_1.MJSONWP_ELEMENT_KEY, constants_1.W3C_ELEMENT_KEY),
|
|
192
|
-
})
|
|
193
|
-
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return await this.proxyFunc(url, method, body);
|
|
194
206
|
}
|
|
195
|
-
/**
|
|
196
|
-
*
|
|
197
|
-
* @param {string} url
|
|
198
|
-
* @param {string} method
|
|
199
|
-
* @param {import('@appium/types').HTTPBody} body
|
|
200
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
201
|
-
*/
|
|
202
207
|
async proxyPerformActions(url, method, body) {
|
|
203
208
|
const bodyObj = support_1.util.safeJsonParse(body);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
209
|
+
if (lodash_1.default.isPlainObject(bodyObj)) {
|
|
210
|
+
return await this.proxyFunc(url, method, (0, helpers_1.duplicateKeys)(bodyObj, constants_1.MJSONWP_ELEMENT_KEY, constants_1.W3C_ELEMENT_KEY));
|
|
211
|
+
}
|
|
212
|
+
return await this.proxyFunc(url, method, body);
|
|
207
213
|
}
|
|
208
|
-
/**
|
|
209
|
-
*
|
|
210
|
-
* @param {string} url
|
|
211
|
-
* @param {string} method
|
|
212
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
213
|
-
*/
|
|
214
214
|
async proxyReleaseActions(url, method) {
|
|
215
215
|
return await this.proxyFunc(url, method);
|
|
216
216
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Handle "crossing" endpoints for the case
|
|
219
|
-
* when upstream and downstream drivers operate different protocols
|
|
220
|
-
*
|
|
221
|
-
* @param {string} commandName
|
|
222
|
-
* @param {string} url
|
|
223
|
-
* @param {string} method
|
|
224
|
-
* @param {import('@appium/types').HTTPBody} [body]
|
|
225
|
-
* @returns {Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>}
|
|
226
|
-
*/
|
|
227
|
-
async convertAndProxy(commandName, url, method, body) {
|
|
228
|
-
if (!this.downstreamProtocol) {
|
|
229
|
-
return await this.proxyFunc(url, method, body);
|
|
230
|
-
}
|
|
231
|
-
// Same url, but different arguments
|
|
232
|
-
switch (commandName) {
|
|
233
|
-
case 'timeouts':
|
|
234
|
-
return await this.proxySetTimeouts(url, method, body);
|
|
235
|
-
case 'setWindow':
|
|
236
|
-
return await this.proxySetWindow(url, method, body);
|
|
237
|
-
case 'setValue':
|
|
238
|
-
return await this.proxySetValue(url, method, body);
|
|
239
|
-
case 'performActions':
|
|
240
|
-
return await this.proxyPerformActions(url, method, body);
|
|
241
|
-
case 'releaseActions':
|
|
242
|
-
return await this.proxyReleaseActions(url, method);
|
|
243
|
-
case 'setFrame':
|
|
244
|
-
return await this.proxySetFrame(url, method, body);
|
|
245
|
-
default:
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
// Same arguments, but different URLs
|
|
249
|
-
for (const { commandNames, jsonwpConverter, w3cConverter } of exports.COMMAND_URLS_CONFLICTS) {
|
|
250
|
-
if (!commandNames.includes(commandName)) {
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
const rewrittenUrl = this.downstreamProtocol === MJSONWP ? jsonwpConverter(url) : w3cConverter(url);
|
|
254
|
-
if (rewrittenUrl === url) {
|
|
255
|
-
this.log.debug(`Did not know how to rewrite the original URL '${url}' ` +
|
|
256
|
-
`for ${this.downstreamProtocol} protocol`);
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
this.log.info(`Rewrote the original URL '${url}' to '${rewrittenUrl}' ` +
|
|
260
|
-
`for ${this.downstreamProtocol} protocol`);
|
|
261
|
-
return await this.proxyFunc(rewrittenUrl, method, body);
|
|
262
|
-
}
|
|
263
|
-
// No matches found. Proceed normally
|
|
264
|
-
return await this.proxyFunc(url, method, body);
|
|
265
|
-
}
|
|
266
217
|
}
|
|
267
|
-
exports.
|
|
268
|
-
/**
|
|
269
|
-
* @typedef {(url: string, method: string, body?: import('@appium/types').HTTPBody) => Promise<[import('@appium/types').ProxyResponse, import('@appium/types').HTTPBody]>} ProxyFunction
|
|
270
|
-
*/
|
|
218
|
+
exports.ProtocolConverter = ProtocolConverter;
|
|
271
219
|
//# sourceMappingURL=protocol-converter.js.map
|