Files
appium/packages/base-driver/lib/helpers/extension-command-name.ts
T
Puja Jagani c410201baa fix(base-driver,types): For extension commands that use prefix "mobile", ensure logEvents() has the name of executed script (#21416)
* fix(appium): For extension commands that use prefix "mobile", ensure logEvents() has the name of executed script

Related to https://github.com/appium/java-client/issues/2219

* Fix linting

* Address comments

* Update method name

* Address comments

* Address comments

* Address comments

* Add check for accessing method

* Addressing comments
2025-08-06 18:46:26 +09:00

28 lines
908 B
TypeScript

import _ from 'lodash';
import type {Constraints, Driver, DriverClass} from '@appium/types';
import type {BaseDriver} from '../basedriver/driver';
/**
* Resolves the name of extension method corresponding to an `execute` command string
* based on the driver's `executeMethodMap`.
*
* @param commandName - The command name to resolve.
* @returns The resolved extension command name if a mapping exists. Otherwise, the original command name.
*/
export function resolveExecuteExtensionName<C extends Constraints>(
this: BaseDriver<C>,
commandName: string
): string {
const Driver = this.constructor as DriverClass<Driver<C>>;
const methodMap = Driver.executeMethodMap;
if (methodMap && _.isPlainObject(methodMap) && commandName in methodMap) {
const command = methodMap[commandName]?.command;
if (typeof command === 'string') {
return command;
}
}
return commandName;
}