@appium/base-plugin
Version:
The base plugin used to create Appium plugins
42 lines • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasePlugin = void 0;
const base_driver_1 = require("@appium/base-driver");
/**
* Base plugin class for Appium plugins.
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
*/
class BasePlugin extends base_driver_1.ExtensionCore {
static newMethodMap = {};
static executeMethodMap = {};
name;
cliArgs;
constructor(name, cliArgs = {}, driverId = null) {
super();
if (driverId) {
this.updateLogPrefix(`${(0, base_driver_1.generateDriverLogPrefix)(this)} <${driverId}>`);
}
this.name = name;
this.cliArgs = cliArgs;
this.logger = this.log;
}
/**
* A convenience method for plugins that implement their own `executeMethodMap`.
* Pass through to the driver's execute method if the plugin does not handle the script.
*/
async executeMethod(next, driver, script, protoArgs) {
const PluginClass = this.constructor;
const commandMetadata = { ...PluginClass.executeMethodMap?.[script] };
if (!commandMetadata.command || !(commandMetadata.command in this)) {
this.log.info(`Plugin did not know how to handle method '${script}'. Passing control to next`);
return await next();
}
const command = this[commandMetadata.command];
const args = (0, base_driver_1.validateExecuteMethodParams)(protoArgs, commandMetadata.params);
return await command.call(this, next, driver, ...args);
}
}
exports.BasePlugin = BasePlugin;
exports.default = BasePlugin;
//# sourceMappingURL=plugin.js.map