@appium/base-driver 9.14.1 → 9.15.0
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/core.d.ts +4 -10
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +4 -68
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/extension-core.d.ts +16 -0
- package/build/lib/basedriver/extension-core.d.ts.map +1 -0
- package/build/lib/basedriver/extension-core.js +103 -0
- package/build/lib/basedriver/extension-core.js.map +1 -0
- package/build/lib/basedriver/helpers.d.ts +2 -2
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +1 -1
- package/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +5 -1
- package/build/lib/index.js.map +1 -1
- package/lib/basedriver/core.ts +6 -96
- package/lib/basedriver/extension-core.ts +128 -0
- package/lib/basedriver/helpers.js +1 -1
- package/lib/index.js +3 -0
- package/package.json +4 -4
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { AppiumLogger, Constraints, Core, Driver, DriverOpts, EventHistory, HTTPMethod, InitialOpts, Protocol, RouteMatcher, StringRecord
|
|
1
|
+
import type { AppiumLogger, Constraints, Core, Driver, DriverOpts, EventHistory, HTTPMethod, InitialOpts, Protocol, RouteMatcher, StringRecord } from '@appium/types';
|
|
2
2
|
import AsyncLock from 'async-lock';
|
|
3
3
|
import { DeviceSettings } from './device-settings';
|
|
4
4
|
import * as helpers from './helpers';
|
|
5
|
-
|
|
5
|
+
import { ExtensionCore } from './extension-core';
|
|
6
|
+
export declare class DriverCore<const C extends Constraints, Settings extends StringRecord = StringRecord> extends ExtensionCore implements Core<C, Settings> {
|
|
6
7
|
/**
|
|
7
8
|
* Make the basedriver version available so for any driver which inherits from this package, we
|
|
8
9
|
* know which version of basedriver it inherited from
|
|
@@ -31,9 +32,8 @@ export declare class DriverCore<const C extends Constraints, Settings extends St
|
|
|
31
32
|
managedDrivers: Driver[];
|
|
32
33
|
noCommandTimer: NodeJS.Timeout | null;
|
|
33
34
|
protected _eventHistory: EventHistory;
|
|
34
|
-
eventEmitter: NodeJS.EventEmitter;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* TODO: remove this._log and use this.log instead
|
|
37
37
|
*/
|
|
38
38
|
protected _log: AppiumLogger;
|
|
39
39
|
shutdownUnexpectedly: boolean;
|
|
@@ -47,11 +47,7 @@ export declare class DriverCore<const C extends Constraints, Settings extends St
|
|
|
47
47
|
*/
|
|
48
48
|
settings: DeviceSettings<Settings>;
|
|
49
49
|
protocol?: Protocol;
|
|
50
|
-
bidiEventSubs: Record<string, string[]>;
|
|
51
|
-
doesSupportBidi: boolean;
|
|
52
|
-
bidiCommands: BidiModuleMap;
|
|
53
50
|
constructor(opts?: InitialOpts, shouldValidateCaps?: boolean);
|
|
54
|
-
get log(): AppiumLogger;
|
|
55
51
|
/**
|
|
56
52
|
* Set a callback handler if needed to execute a custom piece of code
|
|
57
53
|
* when the driver is shut down unexpectedly. Multiple calls to this method
|
|
@@ -160,7 +156,5 @@ export declare class DriverCore<const C extends Constraints, Settings extends St
|
|
|
160
156
|
addManagedDriver(driver: Driver): void;
|
|
161
157
|
getManagedDrivers(): Driver<Constraints, StringRecord, StringRecord, import("@appium/types").DefaultCreateSessionResult<Constraints>, void, StringRecord>[];
|
|
162
158
|
clearNewCommandTimeout(): Promise<void>;
|
|
163
|
-
updateBidiCommands(cmds: BidiModuleMap): void;
|
|
164
|
-
executeBidiCommand(bidiCmd: string, bidiParams: StringRecord): Promise<BiDiResultData>;
|
|
165
159
|
}
|
|
166
160
|
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../lib/basedriver/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"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AE,MAAM,GAAG,OAAO;IAIpC;;;;;;;;;;;;OAYG;IAEH,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO;IAoB5F;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAI/B,iBAAiB;IAIX,sBAAsB;CAO7B"}
|
|
@@ -37,24 +37,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.DriverCore = void 0;
|
|
40
|
-
const support_1 = require("@appium/support");
|
|
41
40
|
const async_lock_1 = __importDefault(require("async-lock"));
|
|
42
41
|
const lodash_1 = __importDefault(require("lodash"));
|
|
43
|
-
const node_events_1 = require("node:events");
|
|
44
42
|
const node_os_1 = __importDefault(require("node:os"));
|
|
45
43
|
const constants_1 = require("../constants");
|
|
46
44
|
const protocol_1 = require("../protocol");
|
|
47
45
|
const device_settings_1 = require("./device-settings");
|
|
48
46
|
const helpers = __importStar(require("./helpers"));
|
|
49
|
-
const
|
|
47
|
+
const extension_core_1 = require("./extension-core");
|
|
50
48
|
const NEW_COMMAND_TIMEOUT_MS = 60 * 1000;
|
|
51
49
|
const ON_UNEXPECTED_SHUTDOWN_EVENT = 'onUnexpectedShutdown';
|
|
52
50
|
const ALL_DRIVERS_MATCH = '*';
|
|
53
51
|
const FEATURE_NAME_SEPARATOR = ':';
|
|
54
|
-
class DriverCore {
|
|
52
|
+
class DriverCore extends extension_core_1.ExtensionCore {
|
|
55
53
|
constructor(opts = {}, shouldValidateCaps = true) {
|
|
56
|
-
|
|
57
|
-
this._log =
|
|
54
|
+
super();
|
|
55
|
+
this._log = this.log; // TODO: remove references to this._log and use this.log instead
|
|
58
56
|
// setup state
|
|
59
57
|
this.opts = opts;
|
|
60
58
|
// use a custom tmp dir to avoid losing data and app when computer is
|
|
@@ -77,15 +75,9 @@ class DriverCore {
|
|
|
77
75
|
this.managedDrivers = [];
|
|
78
76
|
this.noCommandTimer = null;
|
|
79
77
|
this._eventHistory = { commands: [] };
|
|
80
|
-
this.eventEmitter = new node_events_1.EventEmitter();
|
|
81
78
|
this.shutdownUnexpectedly = false;
|
|
82
79
|
this.commandsQueueGuard = new async_lock_1.default();
|
|
83
80
|
this.settings = new device_settings_1.DeviceSettings();
|
|
84
|
-
this.bidiEventSubs = {};
|
|
85
|
-
this.doesSupportBidi = false;
|
|
86
|
-
}
|
|
87
|
-
get log() {
|
|
88
|
-
return this._log;
|
|
89
81
|
}
|
|
90
82
|
/**
|
|
91
83
|
* Set a callback handler if needed to execute a custom piece of code
|
|
@@ -332,62 +324,6 @@ class DriverCore {
|
|
|
332
324
|
this.noCommandTimer = null;
|
|
333
325
|
}
|
|
334
326
|
}
|
|
335
|
-
updateBidiCommands(cmds) {
|
|
336
|
-
const overlappingKeys = lodash_1.default.intersection(Object.keys(cmds), Object.keys(this.bidiCommands));
|
|
337
|
-
if (overlappingKeys.length) {
|
|
338
|
-
this.log.warn(`Overwriting existing bidi modules: ${JSON.stringify(overlappingKeys)}. This may not be intended!`);
|
|
339
|
-
}
|
|
340
|
-
this.bidiCommands = {
|
|
341
|
-
...this.bidiCommands,
|
|
342
|
-
...cmds,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
async executeBidiCommand(bidiCmd, bidiParams) {
|
|
346
|
-
const [moduleName, methodName] = bidiCmd.split('.');
|
|
347
|
-
// if we don't get a valid format for bidi command name, reject
|
|
348
|
-
if (!moduleName || !methodName) {
|
|
349
|
-
throw new protocol_1.errors.UnknownCommandError(`Did not receive a valid BiDi module and method name ` +
|
|
350
|
-
`of the form moduleName.methodName. Instead received ` +
|
|
351
|
-
`'${moduleName}.${methodName}'`);
|
|
352
|
-
}
|
|
353
|
-
// if the command module or method isn't part of our spec, reject
|
|
354
|
-
if (!this.bidiCommands[moduleName] || !this.bidiCommands[moduleName][methodName]) {
|
|
355
|
-
throw new protocol_1.errors.UnknownCommandError();
|
|
356
|
-
}
|
|
357
|
-
const { command, params } = this.bidiCommands[moduleName][methodName];
|
|
358
|
-
// if the command method isn't part of our spec, also reject
|
|
359
|
-
if (!command) {
|
|
360
|
-
throw new protocol_1.errors.UnknownCommandError();
|
|
361
|
-
}
|
|
362
|
-
// If the driver doesn't have this command, it must not be implemented
|
|
363
|
-
if (!this[command]) {
|
|
364
|
-
throw new protocol_1.errors.NotYetImplementedError();
|
|
365
|
-
}
|
|
366
|
-
// TODO improve param parsing and error messages along the lines of what we have in the http
|
|
367
|
-
// handlers
|
|
368
|
-
const args = [];
|
|
369
|
-
if (params?.required?.length) {
|
|
370
|
-
for (const requiredParam of params.required) {
|
|
371
|
-
if (lodash_1.default.isUndefined(bidiParams[requiredParam])) {
|
|
372
|
-
throw new protocol_1.errors.InvalidArgumentError(`The ${requiredParam} parameter was required but you omitted it`);
|
|
373
|
-
}
|
|
374
|
-
args.push(bidiParams[requiredParam]);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
if (params?.optional?.length) {
|
|
378
|
-
for (const optionalParam of params.optional) {
|
|
379
|
-
args.push(bidiParams[optionalParam]);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
const logParams = lodash_1.default.truncate(JSON.stringify(bidiParams), { length: constants_1.MAX_LOG_BODY_LENGTH });
|
|
383
|
-
this.log.debug(`Executing bidi command '${bidiCmd}' with params ${logParams} by passing to driver ` +
|
|
384
|
-
`method '${command}'`);
|
|
385
|
-
const response = await this[command](...args);
|
|
386
|
-
const finalResponse = lodash_1.default.isUndefined(response) ? {} : response;
|
|
387
|
-
this.log.debug(`Responding to bidi command '${bidiCmd}' with ` +
|
|
388
|
-
`${lodash_1.default.truncate(JSON.stringify(finalResponse), { length: constants_1.MAX_LOG_BODY_LENGTH })}`);
|
|
389
|
-
return finalResponse;
|
|
390
|
-
}
|
|
391
327
|
}
|
|
392
328
|
exports.DriverCore = DriverCore;
|
|
393
329
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../lib/basedriver/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../lib/basedriver/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,4DAAmC;AACnC,oDAAuB;AACvB,sDAAyB;AACzB,4CAGsB;AACtB,0CAAmC;AACnC,uDAAiD;AACjD,mDAAqC;AACrC,qDAA+C;AAE/C,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,MAAM,4BAA4B,GAAG,sBAAsB,CAAC;AAE5D,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,MAAa,UACX,SAAQ,8BAAa;IAmErB,YAAY,OAAiC,EAAE,EAAE,kBAAkB,GAAG,IAAI;QACxE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,gEAAgE;QAGtF,cAAc;QACd,IAAI,CAAC,IAAI,GAAG,IAAqB,CAAC;QAElC,qEAAqE;QACrE,YAAY;QACZ,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,iBAAE,CAAC,MAAM,EAAE,CAAC;QAEjF,wBAAwB;QACxB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAE7C,gCAAgC;QAChC,IAAI,CAAC,WAAW,GAAG,gBAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAErC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;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f,CAAC;IAED;;;OAGG;IACH,gBAAgB,CAAC,MAAc;QAC7B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;IACH,CAAC;;AA9XH,gCAgYC;AA7XC;;;GAGG;AACI,sBAAW,GAAG,OAAO,CAAC,cAAc,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AppiumLogger, BidiModuleMap, BiDiResultData, StringRecord } from '@appium/types';
|
|
2
|
+
export declare class ExtensionCore {
|
|
3
|
+
bidiEventSubs: Record<string, string[]>;
|
|
4
|
+
bidiCommands: BidiModuleMap;
|
|
5
|
+
_logPrefix?: string;
|
|
6
|
+
protected _log: AppiumLogger;
|
|
7
|
+
readonly eventEmitter: NodeJS.EventEmitter;
|
|
8
|
+
constructor(logPrefix?: string);
|
|
9
|
+
get log(): AppiumLogger;
|
|
10
|
+
updateLogPrefix(logPrefix: string): void;
|
|
11
|
+
updateBidiCommands(cmds: BidiModuleMap): void;
|
|
12
|
+
doesBidiCommandExist(moduleName: string, methodName: string): boolean;
|
|
13
|
+
ensureBidiCommandExists(moduleName: string, methodName: string): void;
|
|
14
|
+
executeBidiCommand(bidiCmd: string, bidiParams: StringRecord, next?: () => Promise<any>, driver?: ExtensionCore): Promise<BiDiResultData>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=extension-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-core.d.ts","sourceRoot":"","sources":["../../../lib/basedriver/extension-core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,YAAY,EACb,MAAM,eAAe,CAAC;AASvB,qBAAa,aAAa;IACxB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,YAAY,EAAE,aAAa,CAAkC;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC;IAE7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC;gBAG/B,SAAS,CAAC,EAAE,MAAM;IAM9B,IAAI,GAAG,IAAI,YAAY,CAKtB;IAED,eAAe,CAAC,SAAS,EAAE,MAAM;IAIjC,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;IAW7C,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IASrE,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IA2B/D,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;CAsChJ"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ExtensionCore = void 0;
|
|
7
|
+
const support_1 = require("@appium/support");
|
|
8
|
+
const node_events_1 = require("node:events");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const protocol_1 = require("../protocol");
|
|
11
|
+
const bidi_commands_1 = require("../protocol/bidi-commands");
|
|
12
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
13
|
+
const helpers_1 = require("./helpers");
|
|
14
|
+
class ExtensionCore {
|
|
15
|
+
constructor(logPrefix) {
|
|
16
|
+
this.bidiCommands = bidi_commands_1.BIDI_COMMANDS;
|
|
17
|
+
this._logPrefix = logPrefix;
|
|
18
|
+
this.bidiEventSubs = {};
|
|
19
|
+
this.eventEmitter = new node_events_1.EventEmitter();
|
|
20
|
+
}
|
|
21
|
+
get log() {
|
|
22
|
+
if (!this._log) {
|
|
23
|
+
this.updateLogPrefix(this._logPrefix ?? (0, helpers_1.generateDriverLogPrefix)(this));
|
|
24
|
+
}
|
|
25
|
+
return this._log;
|
|
26
|
+
}
|
|
27
|
+
updateLogPrefix(logPrefix) {
|
|
28
|
+
this._log = support_1.logger.getLogger(logPrefix);
|
|
29
|
+
}
|
|
30
|
+
updateBidiCommands(cmds) {
|
|
31
|
+
const overlappingKeys = lodash_1.default.intersection(Object.keys(cmds), Object.keys(this.bidiCommands));
|
|
32
|
+
if (overlappingKeys.length) {
|
|
33
|
+
this.log.warn(`Overwriting existing bidi modules: ${JSON.stringify(overlappingKeys)}. This may not be intended!`);
|
|
34
|
+
}
|
|
35
|
+
this.bidiCommands = {
|
|
36
|
+
...this.bidiCommands,
|
|
37
|
+
...cmds,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
doesBidiCommandExist(moduleName, methodName) {
|
|
41
|
+
try {
|
|
42
|
+
this.ensureBidiCommandExists(moduleName, methodName);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
ensureBidiCommandExists(moduleName, methodName) {
|
|
50
|
+
// if we don't get a valid format for bidi command name, reject
|
|
51
|
+
if (!moduleName || !methodName) {
|
|
52
|
+
throw new protocol_1.errors.UnknownCommandError(`Did not receive a valid BiDi module and method name ` +
|
|
53
|
+
`of the form moduleName.methodName. Instead received ` +
|
|
54
|
+
`'${moduleName}.${methodName}'`);
|
|
55
|
+
}
|
|
56
|
+
// if the command module or method isn't part of our spec, reject
|
|
57
|
+
if (!this.bidiCommands[moduleName] || !this.bidiCommands[moduleName][methodName]) {
|
|
58
|
+
throw new protocol_1.errors.UnknownCommandError();
|
|
59
|
+
}
|
|
60
|
+
const { command } = this.bidiCommands[moduleName][methodName];
|
|
61
|
+
// if the command method isn't part of our spec, also reject
|
|
62
|
+
if (!command) {
|
|
63
|
+
throw new protocol_1.errors.UnknownCommandError();
|
|
64
|
+
}
|
|
65
|
+
// If the driver doesn't have this command, it must not be implemented
|
|
66
|
+
if (!this[command]) {
|
|
67
|
+
throw new protocol_1.errors.NotYetImplementedError();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async executeBidiCommand(bidiCmd, bidiParams, next, driver) {
|
|
71
|
+
const handlerType = (next && driver) ? 'plugin' : 'driver';
|
|
72
|
+
const [moduleName, methodName] = bidiCmd.split('.');
|
|
73
|
+
this.ensureBidiCommandExists(moduleName, methodName);
|
|
74
|
+
const { command, params } = this.bidiCommands[moduleName][methodName];
|
|
75
|
+
// TODO improve param parsing and error messages along the lines of what we have in the http
|
|
76
|
+
// handlers
|
|
77
|
+
const args = [];
|
|
78
|
+
if (params?.required?.length) {
|
|
79
|
+
for (const requiredParam of params.required) {
|
|
80
|
+
if (lodash_1.default.isUndefined(bidiParams[requiredParam])) {
|
|
81
|
+
throw new protocol_1.errors.InvalidArgumentError(`The ${requiredParam} parameter was required but you omitted it`);
|
|
82
|
+
}
|
|
83
|
+
args.push(bidiParams[requiredParam]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (params?.optional?.length) {
|
|
87
|
+
for (const optionalParam of params.optional) {
|
|
88
|
+
args.push(bidiParams[optionalParam]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const logParams = lodash_1.default.truncate(JSON.stringify(bidiParams), { length: constants_1.MAX_LOG_BODY_LENGTH });
|
|
92
|
+
this.log.debug(`Executing bidi command '${bidiCmd}' with params ${logParams} by passing to ${handlerType} ` +
|
|
93
|
+
`method '${command}'`);
|
|
94
|
+
// call the handler with the signature appropriate to extension type (plugin or driver)
|
|
95
|
+
const response = (next && driver) ? await this[command](next, driver, ...args) : await this[command](...args);
|
|
96
|
+
const finalResponse = lodash_1.default.isUndefined(response) ? {} : response;
|
|
97
|
+
this.log.debug(`Responding to bidi command '${bidiCmd}' with ` +
|
|
98
|
+
`${lodash_1.default.truncate(JSON.stringify(finalResponse), { length: constants_1.MAX_LOG_BODY_LENGTH })}`);
|
|
99
|
+
return finalResponse;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ExtensionCore = ExtensionCore;
|
|
103
|
+
//# sourceMappingURL=extension-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-core.js","sourceRoot":"","sources":["../../../lib/basedriver/extension-core.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAuC;AACvC,6CAAyC;AAOzC,4CAEsB;AACtB,0CAAmC;AACnC,6DAAwD;AACxD,oDAAuB;AACvB,uCAAkD;AAElD,MAAa,aAAa;IASxB,YAAY,SAAkB;QAP9B,iBAAY,GAAkB,6BAA8B,CAAC;QAQ3D,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAC;IACzC,CAAC;IAED,IAAI,GAAG;QACL,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,IAAI,IAAA,iCAAuB,EAAC,IAAI,CAAC,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,eAAe,CAAC,SAAiB;QAC/B,IAAI,CAAC,IAAI,GAAG,gBAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC1C,C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AAQ,EAAE,CAAC;gBAC5C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,MAAM,SAAS,GAAG,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,EAAC,MAAM,EAAE,+BAAmB,EAAC,CAAC,CAAC;QACxF,IAAI,CAAC,GAAG,CAAC,KAAK,CACZ,2BAA2B,OAAO,iBAAiB,SAAS,kBAAkB,WAAW,GAAG;YAC1F,WAAW,OAAO,GAAG,CACxB,CAAC;QACF,uFAAuF;QACvF,MAAM,QAAQ,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QAC9G,MAAM,aAAa,GAAG,gBAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC9D,IAAI,CAAC,GAAG,CAAC,KAAK,CACZ,+BAA+B,OAAO,SAAS;YAC/C,GAAG,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,EAAC,MAAM,EAAE,+BAAmB,EAAC,CAAC,EAAE,CAC9E,CAAC;QACF,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AA/GD,sCA+GC"}
|
|
@@ -30,12 +30,12 @@ export function parseCapsArray(cap: string | Array<string>): any[];
|
|
|
30
30
|
/**
|
|
31
31
|
* Generate a string that uniquely describes driver instance
|
|
32
32
|
*
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {object} obj driver instance
|
|
34
34
|
* @param {string?} [sessionId=null] session identifier (if exists).
|
|
35
35
|
* This parameter is deprecated and is not used.
|
|
36
36
|
* @returns {string}
|
|
37
37
|
*/
|
|
38
|
-
export function generateDriverLogPrefix(obj:
|
|
38
|
+
export function generateDriverLogPrefix(obj: object, sessionId?: string | null): string;
|
|
39
39
|
export const BASEDRIVER_VER: string;
|
|
40
40
|
declare const _default: {
|
|
41
41
|
configureApp: typeof configureApp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../lib/basedriver/helpers.js"],"names":[],"mappings":"AA+DA;;;;GAIG;AACH,kCAHW,MAAM,YACN,MAAM,GAAC,MAAM,EAAE,GAAC,OAAO,eAAe,EAAE,mBAAmB,gBAuQrE;AAED;;;GAGG;AACH,uCAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;;;;;GASG;AACH,qCAJW,GAAC,4CA2BX;AAED;;;;;GAKG;AACH,oCAFW,MAAM,GAAC,KAAK,QAAQ,SAoB9B;AAED;;;;;;;GAOG;AAEH,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../lib/basedriver/helpers.js"],"names":[],"mappings":"AA+DA;;;;GAIG;AACH,kCAHW,MAAM,YACN,MAAM,GAAC,MAAM,EAAE,GAAC,OAAO,eAAe,EAAE,mBAAmB,gBAuQrE;AAED;;;GAGG;AACH,uCAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;;;;;GASG;AACH,qCAJW,GAAC,4CA2BX;AAED;;;;;GAKG;AACH,oCAFW,MAAM,GAAC,KAAK,QAAQ,SAoB9B;AAED;;;;;;;GAOG;AAEH,6CANW,MAAM,cACN,MAAM,OAAC,GAEL,MAAM,CAKlB;;;;;;;;;;;kBAwTa,IAAI,OAAC;eACL,OAAO;YACP,MAAM,OAAC;UACP,MAAM,OAAC;;;;;;;;;YAKP,MAAM;;;;YACN,OAAO,QAAQ,EAAE,QAAQ;;;;aACzB,OAAO,OAAO,EAAE,uBAAuB,GAAG,OAAO,OAAO,EAAE,oBAAoB"}
|
|
@@ -379,7 +379,7 @@ function parseCapsArray(cap) {
|
|
|
379
379
|
/**
|
|
380
380
|
* Generate a string that uniquely describes driver instance
|
|
381
381
|
*
|
|
382
|
-
* @param {
|
|
382
|
+
* @param {object} obj driver instance
|
|
383
383
|
* @param {string?} [sessionId=null] session identifier (if exists).
|
|
384
384
|
* This parameter is deprecated and is not used.
|
|
385
385
|
* @returns {string}
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ExtensionCore } from "./basedriver/extension-core";
|
|
1
2
|
export { DriverCore } from "./basedriver/core";
|
|
2
3
|
export { DeviceSettings } from "./basedriver/device-settings";
|
|
3
4
|
export { BaseDriver };
|
|
@@ -6,6 +7,7 @@ export * from "./protocol";
|
|
|
6
7
|
export { errorFromMJSONWPStatusCode as errorFromCode } from "./protocol";
|
|
7
8
|
export { STATIC_DIR } from "./express/static";
|
|
8
9
|
export { DEFAULT_WS_PATHNAME_PREFIX } from "./express/websocket";
|
|
10
|
+
export { generateDriverLogPrefix } from "./basedriver/helpers";
|
|
9
11
|
export type ServerOpts = import("./express/server").ServerOpts;
|
|
10
12
|
import { BaseDriver } from './basedriver/driver';
|
|
11
13
|
export { MAX_LOG_BODY_LENGTH, DEFAULT_BASE_PATH, PROTOCOLS, W3C_ELEMENT_KEY } from "./constants";
|
package/build/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":";;;;;;;;;;yBAsDa,OAAO,kBAAkB,EAAE,UAAU;2BAzCzB,qBAAqB"}
|
package/build/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DEFAULT_WS_PATHNAME_PREFIX = exports.promoteAppiumOptionsForObject = exports.promoteAppiumOptions = exports.validateCaps = exports.isStandardCap = exports.processCapabilities = exports.STANDARD_CAPS = exports.PREFIXED_APPIUM_OPTS_CAP = exports.statusCodes = exports.getSummaryByCode = exports.WebDriverProxy = exports.JWProxy = exports.normalizeBasePath = exports.server = exports.STATIC_DIR = exports.errorFromCode = exports.W3C_ELEMENT_KEY = exports.PROTOCOLS = exports.DEFAULT_BASE_PATH = exports.MAX_LOG_BODY_LENGTH = exports.BaseDriver = exports.DeviceSettings = exports.DriverCore = void 0;
|
|
20
|
+
exports.generateDriverLogPrefix = exports.DEFAULT_WS_PATHNAME_PREFIX = exports.promoteAppiumOptionsForObject = exports.promoteAppiumOptions = exports.validateCaps = exports.isStandardCap = exports.processCapabilities = exports.STANDARD_CAPS = exports.PREFIXED_APPIUM_OPTS_CAP = exports.statusCodes = exports.getSummaryByCode = exports.WebDriverProxy = exports.JWProxy = exports.normalizeBasePath = exports.server = exports.STATIC_DIR = exports.errorFromCode = exports.W3C_ELEMENT_KEY = exports.PROTOCOLS = exports.DEFAULT_BASE_PATH = exports.MAX_LOG_BODY_LENGTH = exports.BaseDriver = exports.DeviceSettings = exports.DriverCore = exports.ExtensionCore = void 0;
|
|
21
21
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
22
22
|
try {
|
|
23
23
|
bluebird_1.default.config({
|
|
@@ -29,6 +29,8 @@ catch {
|
|
|
29
29
|
// cancellation not being able to be enabled after promise has been configured
|
|
30
30
|
}
|
|
31
31
|
// BaseDriver exports
|
|
32
|
+
var extension_core_1 = require("./basedriver/extension-core");
|
|
33
|
+
Object.defineProperty(exports, "ExtensionCore", { enumerable: true, get: function () { return extension_core_1.ExtensionCore; } });
|
|
32
34
|
const driver_1 = require("./basedriver/driver");
|
|
33
35
|
Object.defineProperty(exports, "BaseDriver", { enumerable: true, get: function () { return driver_1.BaseDriver; } });
|
|
34
36
|
var core_1 = require("./basedriver/core");
|
|
@@ -73,6 +75,8 @@ Object.defineProperty(exports, "promoteAppiumOptionsForObject", { enumerable: tr
|
|
|
73
75
|
// Web socket helpers
|
|
74
76
|
var websocket_1 = require("./express/websocket");
|
|
75
77
|
Object.defineProperty(exports, "DEFAULT_WS_PATHNAME_PREFIX", { enumerable: true, get: function () { return websocket_1.DEFAULT_WS_PATHNAME_PREFIX; } });
|
|
78
|
+
var helpers_1 = require("./basedriver/helpers");
|
|
79
|
+
Object.defineProperty(exports, "generateDriverLogPrefix", { enumerable: true, get: function () { return helpers_1.generateDriverLogPrefix; } });
|
|
76
80
|
/**
|
|
77
81
|
* @typedef {import('./express/server').ServerOpts} ServerOpts
|
|
78
82
|
*/
|
package/build/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,wDAAyB;AAEzB,IAAI,CAAC;IACH,kBAAC,CAAC,MAAM,CAAC;QACP,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAAC,MAAM,CAAC;IACP,0FAA0F;IAC1F,8EAA8E;AAChF,CAAC;AAED,qBAAqB;AACrB,gDAA+C;AAIvC,2FAJA,mBAAU,OAIA;AAHlB,0CAA6C;AAArC,kGAAA,UAAU,OAAA;AAClB,gEAA4D;AAApD,iHAAA,cAAc,OAAA;AAGtB,kBAAe,mBAAU,CAAC;AAC1B,yCAA+F;AAAvF,gHAAA,mBAAmB,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,4GAAA,eAAe,OAAA;AAE1E,kBAAkB;AAClB,6CAA2B;AAC3B,uCAAuE;AAA/D,yGAAA,0BAA0B,OAAiB;AAEnD,kBAAkB;AAClB,2CAA4C;AAApC,oGAAA,UAAU,OAAA;AAClB,2CAA2D;AA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AA4C;AAApC,oGAAA,UAAU,OAAA;AAClB,2CAA2D;AAAnD,gGAAA,MAAM,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAEjC,uBAAuB;AACvB,sFAAsF;AACtF,8CAA6C;AAArC,gGAAA,OAAO,OAAA;AACf,8CAA+D;AAAvD,uGAAA,OAAO,OAAkB;AAEjC,wBAAwB;AACxB,iDAA8E;AAAtE,0GAAA,gBAAgB,OAAA;AAAE,qGAAA,KAAK,OAAe;AAE9C,0BAA0B;AAC1B,0DAQmC;AAPjC,wHAAA,wBAAwB,OAAA;AACxB,6GAAA,aAAa,OAAA;AACb,mHAAA,mBAAmB,OAAA;AACnB,6GAAA,aAAa,OAAA;AACb,4GAAA,YAAY,OAAA;AACZ,oHAAA,oBAAoB,OAAA;AACpB,6HAAA,6BAA6B,OAAA;AAG/B,qBAAqB;AACrB,iDAA+D;AAAvD,uHAAA,0BAA0B,OAAA;AAElC,gDAA6D;AAArD,kHAAA,uBAAuB,OAAA;AAE/B;;GAEG"}
|
package/lib/basedriver/core.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {logger} from '@appium/support';
|
|
2
1
|
import type {
|
|
3
2
|
AppiumLogger,
|
|
4
3
|
Constraints,
|
|
@@ -11,22 +10,18 @@ import type {
|
|
|
11
10
|
Protocol,
|
|
12
11
|
RouteMatcher,
|
|
13
12
|
StringRecord,
|
|
14
|
-
BidiModuleMap,
|
|
15
|
-
BiDiResultData,
|
|
16
13
|
} from '@appium/types';
|
|
17
14
|
import AsyncLock from 'async-lock';
|
|
18
15
|
import _ from 'lodash';
|
|
19
|
-
import {EventEmitter} from 'node:events';
|
|
20
16
|
import os from 'node:os';
|
|
21
17
|
import {
|
|
22
18
|
DEFAULT_BASE_PATH,
|
|
23
19
|
PROTOCOLS,
|
|
24
|
-
MAX_LOG_BODY_LENGTH,
|
|
25
20
|
} from '../constants';
|
|
26
21
|
import {errors} from '../protocol';
|
|
27
22
|
import {DeviceSettings} from './device-settings';
|
|
28
23
|
import * as helpers from './helpers';
|
|
29
|
-
import {
|
|
24
|
+
import {ExtensionCore} from './extension-core';
|
|
30
25
|
|
|
31
26
|
const NEW_COMMAND_TIMEOUT_MS = 60 * 1000;
|
|
32
27
|
|
|
@@ -36,7 +31,7 @@ const ALL_DRIVERS_MATCH = '*';
|
|
|
36
31
|
const FEATURE_NAME_SEPARATOR = ':';
|
|
37
32
|
|
|
38
33
|
export class DriverCore<const C extends Constraints, Settings extends StringRecord = StringRecord>
|
|
39
|
-
implements Core<C, Settings>
|
|
34
|
+
extends ExtensionCore implements Core<C, Settings>
|
|
40
35
|
{
|
|
41
36
|
/**
|
|
42
37
|
* Make the basedriver version available so for any driver which inherits from this package, we
|
|
@@ -82,11 +77,8 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
82
77
|
|
|
83
78
|
protected _eventHistory: EventHistory;
|
|
84
79
|
|
|
85
|
-
// used to handle driver events
|
|
86
|
-
eventEmitter: NodeJS.EventEmitter;
|
|
87
|
-
|
|
88
80
|
/**
|
|
89
|
-
*
|
|
81
|
+
* TODO: remove this._log and use this.log instead
|
|
90
82
|
*/
|
|
91
83
|
protected _log: AppiumLogger;
|
|
92
84
|
|
|
@@ -106,14 +98,10 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
106
98
|
|
|
107
99
|
protocol?: Protocol;
|
|
108
100
|
|
|
109
|
-
bidiEventSubs: Record<string, string[]>;
|
|
110
|
-
|
|
111
|
-
doesSupportBidi: boolean;
|
|
112
|
-
|
|
113
|
-
bidiCommands: BidiModuleMap = BIDI_COMMANDS as BidiModuleMap;
|
|
114
|
-
|
|
115
101
|
constructor(opts: InitialOpts = <InitialOpts>{}, shouldValidateCaps = true) {
|
|
116
|
-
|
|
102
|
+
super();
|
|
103
|
+
this._log = this.log; // TODO: remove references to this._log and use this.log instead
|
|
104
|
+
|
|
117
105
|
|
|
118
106
|
// setup state
|
|
119
107
|
this.opts = opts as DriverOpts<C>;
|
|
@@ -141,16 +129,9 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
141
129
|
this.managedDrivers = [];
|
|
142
130
|
this.noCommandTimer = null;
|
|
143
131
|
this._eventHistory = {commands: []};
|
|
144
|
-
this.eventEmitter = new EventEmitter();
|
|
145
132
|
this.shutdownUnexpectedly = false;
|
|
146
133
|
this.commandsQueueGuard = new AsyncLock();
|
|
147
134
|
this.settings = new DeviceSettings();
|
|
148
|
-
this.bidiEventSubs = {};
|
|
149
|
-
this.doesSupportBidi = false;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
get log() {
|
|
153
|
-
return this._log;
|
|
154
135
|
}
|
|
155
136
|
|
|
156
137
|
/**
|
|
@@ -433,75 +414,4 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
433
414
|
}
|
|
434
415
|
}
|
|
435
416
|
|
|
436
|
-
updateBidiCommands(cmds: BidiModuleMap): void {
|
|
437
|
-
const overlappingKeys = _.intersection(Object.keys(cmds), Object.keys(this.bidiCommands));
|
|
438
|
-
if (overlappingKeys.length) {
|
|
439
|
-
this.log.warn(`Overwriting existing bidi modules: ${JSON.stringify(overlappingKeys)}. This may not be intended!`);
|
|
440
|
-
}
|
|
441
|
-
this.bidiCommands = {
|
|
442
|
-
...this.bidiCommands,
|
|
443
|
-
...cmds,
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
async executeBidiCommand(bidiCmd: string, bidiParams: StringRecord): Promise<BiDiResultData> {
|
|
448
|
-
const [moduleName, methodName] = bidiCmd.split('.');
|
|
449
|
-
|
|
450
|
-
// if we don't get a valid format for bidi command name, reject
|
|
451
|
-
if (!moduleName || !methodName) {
|
|
452
|
-
throw new errors.UnknownCommandError(
|
|
453
|
-
`Did not receive a valid BiDi module and method name ` +
|
|
454
|
-
`of the form moduleName.methodName. Instead received ` +
|
|
455
|
-
`'${moduleName}.${methodName}'`,
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
// if the command module or method isn't part of our spec, reject
|
|
461
|
-
if (!this.bidiCommands[moduleName] || !this.bidiCommands[moduleName][methodName]) {
|
|
462
|
-
throw new errors.UnknownCommandError();
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const {command, params} = this.bidiCommands[moduleName][methodName];
|
|
466
|
-
// if the command method isn't part of our spec, also reject
|
|
467
|
-
if (!command) {
|
|
468
|
-
throw new errors.UnknownCommandError();
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// If the driver doesn't have this command, it must not be implemented
|
|
472
|
-
if (!this[command]) {
|
|
473
|
-
throw new errors.NotYetImplementedError();
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// TODO improve param parsing and error messages along the lines of what we have in the http
|
|
477
|
-
// handlers
|
|
478
|
-
const args: any[] = [];
|
|
479
|
-
if (params?.required?.length) {
|
|
480
|
-
for (const requiredParam of params.required) {
|
|
481
|
-
if (_.isUndefined(bidiParams[requiredParam])) {
|
|
482
|
-
throw new errors.InvalidArgumentError(
|
|
483
|
-
`The ${requiredParam} parameter was required but you omitted it`,
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
args.push(bidiParams[requiredParam]);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (params?.optional?.length) {
|
|
490
|
-
for (const optionalParam of params.optional) {
|
|
491
|
-
args.push(bidiParams[optionalParam]);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
const logParams = _.truncate(JSON.stringify(bidiParams), {length: MAX_LOG_BODY_LENGTH});
|
|
495
|
-
this.log.debug(
|
|
496
|
-
`Executing bidi command '${bidiCmd}' with params ${logParams} by passing to driver ` +
|
|
497
|
-
`method '${command}'`,
|
|
498
|
-
);
|
|
499
|
-
const response = await this[command](...args);
|
|
500
|
-
const finalResponse = _.isUndefined(response) ? {} : response;
|
|
501
|
-
this.log.debug(
|
|
502
|
-
`Responding to bidi command '${bidiCmd}' with ` +
|
|
503
|
-
`${_.truncate(JSON.stringify(finalResponse), {length: MAX_LOG_BODY_LENGTH})}`
|
|
504
|
-
);
|
|
505
|
-
return finalResponse;
|
|
506
|
-
}
|
|
507
417
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {logger} from '@appium/support';
|
|
2
|
+
import {EventEmitter} from 'node:events';
|
|
3
|
+
import type {
|
|
4
|
+
AppiumLogger,
|
|
5
|
+
BidiModuleMap,
|
|
6
|
+
BiDiResultData,
|
|
7
|
+
StringRecord,
|
|
8
|
+
} from '@appium/types';
|
|
9
|
+
import {
|
|
10
|
+
MAX_LOG_BODY_LENGTH,
|
|
11
|
+
} from '../constants';
|
|
12
|
+
import {errors} from '../protocol';
|
|
13
|
+
import {BIDI_COMMANDS} from '../protocol/bidi-commands';
|
|
14
|
+
import _ from 'lodash';
|
|
15
|
+
import {generateDriverLogPrefix} from './helpers';
|
|
16
|
+
|
|
17
|
+
export class ExtensionCore {
|
|
18
|
+
bidiEventSubs: Record<string, string[]>;
|
|
19
|
+
bidiCommands: BidiModuleMap = BIDI_COMMANDS as BidiModuleMap;
|
|
20
|
+
_logPrefix?: string;
|
|
21
|
+
protected _log: AppiumLogger;
|
|
22
|
+
// used to handle driver events
|
|
23
|
+
readonly eventEmitter: NodeJS.EventEmitter;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
constructor(logPrefix?: string) {
|
|
27
|
+
this._logPrefix = logPrefix;
|
|
28
|
+
this.bidiEventSubs = {};
|
|
29
|
+
this.eventEmitter = new EventEmitter();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get log(): AppiumLogger {
|
|
33
|
+
if (!this._log) {
|
|
34
|
+
this.updateLogPrefix(this._logPrefix ?? generateDriverLogPrefix(this));
|
|
35
|
+
}
|
|
36
|
+
return this._log;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
updateLogPrefix(logPrefix: string) {
|
|
40
|
+
this._log = logger.getLogger(logPrefix);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
updateBidiCommands(cmds: BidiModuleMap): void {
|
|
44
|
+
const overlappingKeys = _.intersection(Object.keys(cmds), Object.keys(this.bidiCommands));
|
|
45
|
+
if (overlappingKeys.length) {
|
|
46
|
+
this.log.warn(`Overwriting existing bidi modules: ${JSON.stringify(overlappingKeys)}. This may not be intended!`);
|
|
47
|
+
}
|
|
48
|
+
this.bidiCommands = {
|
|
49
|
+
...this.bidiCommands,
|
|
50
|
+
...cmds,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
doesBidiCommandExist(moduleName: string, methodName: string): boolean {
|
|
55
|
+
try {
|
|
56
|
+
this.ensureBidiCommandExists(moduleName, methodName);
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ensureBidiCommandExists(moduleName: string, methodName: string): void {
|
|
64
|
+
// if we don't get a valid format for bidi command name, reject
|
|
65
|
+
if (!moduleName || !methodName) {
|
|
66
|
+
throw new errors.UnknownCommandError(
|
|
67
|
+
`Did not receive a valid BiDi module and method name ` +
|
|
68
|
+
`of the form moduleName.methodName. Instead received ` +
|
|
69
|
+
`'${moduleName}.${methodName}'`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// if the command module or method isn't part of our spec, reject
|
|
74
|
+
if (!this.bidiCommands[moduleName] || !this.bidiCommands[moduleName][methodName]) {
|
|
75
|
+
throw new errors.UnknownCommandError();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const {command} = this.bidiCommands[moduleName][methodName];
|
|
79
|
+
// if the command method isn't part of our spec, also reject
|
|
80
|
+
if (!command) {
|
|
81
|
+
throw new errors.UnknownCommandError();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// If the driver doesn't have this command, it must not be implemented
|
|
85
|
+
if (!this[command]) {
|
|
86
|
+
throw new errors.NotYetImplementedError();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async executeBidiCommand(bidiCmd: string, bidiParams: StringRecord, next?: () => Promise<any>, driver?: ExtensionCore): Promise<BiDiResultData> {
|
|
91
|
+
const handlerType = (next && driver) ? 'plugin' : 'driver';
|
|
92
|
+
const [moduleName, methodName] = bidiCmd.split('.');
|
|
93
|
+
this.ensureBidiCommandExists(moduleName, methodName);
|
|
94
|
+
const {command, params} = this.bidiCommands[moduleName][methodName];
|
|
95
|
+
|
|
96
|
+
// TODO improve param parsing and error messages along the lines of what we have in the http
|
|
97
|
+
// handlers
|
|
98
|
+
const args: any[] = [];
|
|
99
|
+
if (params?.required?.length) {
|
|
100
|
+
for (const requiredParam of params.required) {
|
|
101
|
+
if (_.isUndefined(bidiParams[requiredParam])) {
|
|
102
|
+
throw new errors.InvalidArgumentError(
|
|
103
|
+
`The ${requiredParam} parameter was required but you omitted it`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
args.push(bidiParams[requiredParam]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (params?.optional?.length) {
|
|
110
|
+
for (const optionalParam of params.optional) {
|
|
111
|
+
args.push(bidiParams[optionalParam]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const logParams = _.truncate(JSON.stringify(bidiParams), {length: MAX_LOG_BODY_LENGTH});
|
|
115
|
+
this.log.debug(
|
|
116
|
+
`Executing bidi command '${bidiCmd}' with params ${logParams} by passing to ${handlerType} ` +
|
|
117
|
+
`method '${command}'`,
|
|
118
|
+
);
|
|
119
|
+
// call the handler with the signature appropriate to extension type (plugin or driver)
|
|
120
|
+
const response = (next && driver) ? await this[command](next, driver, ...args) : await this[command](...args);
|
|
121
|
+
const finalResponse = _.isUndefined(response) ? {} : response;
|
|
122
|
+
this.log.debug(
|
|
123
|
+
`Responding to bidi command '${bidiCmd}' with ` +
|
|
124
|
+
`${_.truncate(JSON.stringify(finalResponse), {length: MAX_LOG_BODY_LENGTH})}`
|
|
125
|
+
);
|
|
126
|
+
return finalResponse;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -401,7 +401,7 @@ export function parseCapsArray(cap) {
|
|
|
401
401
|
/**
|
|
402
402
|
* Generate a string that uniquely describes driver instance
|
|
403
403
|
*
|
|
404
|
-
* @param {
|
|
404
|
+
* @param {object} obj driver instance
|
|
405
405
|
* @param {string?} [sessionId=null] session identifier (if exists).
|
|
406
406
|
* This parameter is deprecated and is not used.
|
|
407
407
|
* @returns {string}
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ try {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// BaseDriver exports
|
|
13
|
+
export {ExtensionCore} from './basedriver/extension-core';
|
|
13
14
|
import {BaseDriver} from './basedriver/driver';
|
|
14
15
|
export {DriverCore} from './basedriver/core';
|
|
15
16
|
export {DeviceSettings} from './basedriver/device-settings';
|
|
@@ -48,6 +49,8 @@ export {
|
|
|
48
49
|
// Web socket helpers
|
|
49
50
|
export {DEFAULT_WS_PATHNAME_PREFIX} from './express/websocket';
|
|
50
51
|
|
|
52
|
+
export {generateDriverLogPrefix} from './basedriver/helpers';
|
|
53
|
+
|
|
51
54
|
/**
|
|
52
55
|
* @typedef {import('./express/server').ServerOpts} ServerOpts
|
|
53
56
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-driver",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.15.0",
|
|
4
4
|
"description": "Base driver class for Appium drivers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"test:types": "tsd"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@appium/support": "^6.0.
|
|
48
|
-
"@appium/types": "^0.
|
|
47
|
+
"@appium/support": "^6.0.3",
|
|
48
|
+
"@appium/types": "^0.24.0",
|
|
49
49
|
"@colors/colors": "1.6.0",
|
|
50
50
|
"@types/async-lock": "1.4.2",
|
|
51
51
|
"@types/bluebird": "3.5.42",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"publishConfig": {
|
|
81
81
|
"access": "public"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "a7ce83e169e101ae497bab11204a73703fd54e99",
|
|
84
84
|
"tsd": {
|
|
85
85
|
"directory": "test/types"
|
|
86
86
|
}
|