UNPKG

appium-mac2-driver

Version:

XCTest-based Appium driver for macOS apps automation

34 lines (30 loc) 1 kB
import _ from 'lodash'; import type {Mac2Driver} from '../driver'; import type {StringRecord} from '@appium/types'; const EXECUTE_SCRIPT_PREFIX = 'macos:'; /** * * @param script - The script to execute * @param args - Arguments to pass to the script */ export async function execute( this: Mac2Driver, script: string, args?: readonly any[] | StringRecord, ): Promise<any> { this.log.info(`Executing extension command '${script}'`); const formattedScript = String(script) .trim() .replace(/^macos:\s*/, `${EXECUTE_SCRIPT_PREFIX} `); const preprocessedArgs = preprocessExecuteMethodArgs(args); return await this.executeMethod(formattedScript, [preprocessedArgs]); } /** * Massages the arguments going into an execute method. * * @param args - Arguments to preprocess * @returns Preprocessed arguments as StringRecord */ function preprocessExecuteMethodArgs(args?: readonly any[] | StringRecord): StringRecord { return (_.isArray(args) ? _.first(args) : args) ?? {}; }