@appium/base-driver
Version:
Base driver class for Appium drivers
36 lines • 2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = __importDefault(require("lodash"));
const protocol_1 = require("../../protocol");
const levenshtein_match_1 = require("../../helpers/levenshtein-match");
const mixin_1 = require("./mixin");
const ExecuteCommands = {
async executeMethod(script, protoArgs) {
const Driver = this.constructor;
const commandMetadata = { ...Driver.executeMethodMap?.[script] };
if (!commandMetadata.command) {
const availableScripts = lodash_1.default.keys(Driver.executeMethodMap);
if (lodash_1.default.isEmpty(availableScripts)) {
throw new protocol_1.errors.UnsupportedOperationError(`Unsupported execute method '${script}'. ` +
`Make sure the installed ${Driver.name} is up-to-date. ` +
`The current driver version does not define any execute methods.`);
}
const { sorted: sortedMatches, suggestion } = (0, levenshtein_match_1.rankLevenshteinCandidates)(script, availableScripts);
throw new protocol_1.errors.UnsupportedOperationError((suggestion
? `Unsupported execute method '${script}', did you mean '${suggestion}'? `
: `Unsupported execute method '${script}'. `) +
`Make sure the installed ${Driver.name} is up-to-date. ` +
`Execute methods available in the current driver version are: ` +
sortedMatches.join(', '));
}
const args = (0, protocol_1.validateExecuteMethodParams)(protoArgs, commandMetadata.params);
const commandName = commandMetadata.command;
const command = this[commandName];
return await command.call(this, ...args);
},
};
(0, mixin_1.mixin)(ExecuteCommands);
//# sourceMappingURL=execute.js.map