From dcd49f3c171932fc75126e2b2d72292d621e5664 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 12 May 2024 21:18:33 +0200 Subject: [PATCH] feat: Align execute methods implementation with other android drivers (#1005) --- lib/commands/execute.js | 108 ++++------------------------------------ lib/driver.ts | 2 +- package.json | 2 +- 3 files changed, 13 insertions(+), 99 deletions(-) diff --git a/lib/commands/execute.js b/lib/commands/execute.js index c35c5f3d..ad703d08 100644 --- a/lib/commands/execute.js +++ b/lib/commands/execute.js @@ -1,26 +1,13 @@ -import _ from 'lodash'; -import { errors } from 'appium/driver'; +import {AndroidDriver} from 'appium-android-driver'; /** - * @this {import('../driver').EspressoDriver} - * @param {string} mobileCommand - * @param {Record} [opts={}] - * @returns {Promise} + * @this {EspressoDriver} + * @returns {import('@appium/types').StringRecord} */ -export async function executeMobile (mobileCommand, opts = {}) { - const mobileCommandsMapping = { - shell: 'mobileShell', - - execEmuConsoleCommand: 'mobileExecEmuConsoleCommand', - - performEditorAction: 'mobilePerformEditorAction', - - changePermissions: 'mobileChangePermissions', - getPermissions: 'mobileGetPermissions', - - startScreenStreaming: 'mobileStartScreenStreaming', - stopScreenStreaming: 'mobileStopScreenStreaming', - +export function mobileCommandsMapping() { + const commonMapping = new AndroidDriver().mobileCommandsMapping.call(this); + return { + ...commonMapping, swipe: 'mobileSwipe', scrollToPage: 'mobileScrollToPage', navigateTo: 'mobileNavigateTo', @@ -36,8 +23,6 @@ export async function executeMobile (mobileCommand, opts = {}) { setDate: 'mobileSetDate', setTime: 'mobileSetTime', - getDeviceTime: 'mobileGetDeviceTime', - backdoor: 'mobileBackdoor', flashElement: 'mobileFlashElement', @@ -46,89 +31,18 @@ export async function executeMobile (mobileCommand, opts = {}) { uiautomatorPageSource: 'mobileUiautomatorPageSource', webAtoms: 'mobileWebAtoms', - getContexts: 'mobileGetContexts', dismissAutofill: 'mobileDismissAutofill', - getNotifications: 'mobileGetNotifications', - - listSms: 'mobileListSms', - - pushFile: 'mobilePushFile', - pullFile: 'mobilePullFile', - pullFolder: 'mobilePullFolder', - deleteFile: 'mobileDeleteFile', - - isAppInstalled: 'mobileIsAppInstalled', - queryAppState: 'mobileQueryAppState', - activateApp: 'mobileActivateApp', - removeApp: 'mobileRemoveApp', - terminateApp: 'mobileTerminateApp', - installApp: 'mobileInstallApp', - clearApp: 'mobileClearApp', - backgroundApp: 'mobileBackgroundApp', - getCurrentActivity: 'getCurrentActivity', - getCurrentPackage: 'getCurrentPackage', - - startActivity: 'mobileStartActivity', - startService: 'mobileStartService', - stopService: 'mobileStopService', - broadcast: 'mobileBroadcast', - registerIdlingResources: 'mobileRegisterIdlingResources', unregisterIdlingResources: 'mobileUnregisterIdlingResources', listIdlingResources: 'mobileListIdlingResources', waitForUIThread: 'mobileWaitForUIThread', - lock: 'mobileLock', - unlock: 'mobileUnlock', - isLocked: 'isLocked', - - refreshGpsCache: 'mobileRefreshGpsCache', - - startMediaProjectionRecording: 'mobileStartMediaProjectionRecording', - isMediaProjectionRecordingRunning: 'mobileIsMediaProjectionRecordingRunning', - stopMediaProjectionRecording: 'mobileStopMediaProjectionRecording', - - getConnectivity: 'mobileGetConnectivity', - setConnectivity: 'mobileSetConnectivity', - toggleGps: 'toggleLocationServices', - isGpsEnables: 'isLocationServicesEnabled', - pressKey: 'mobilePressKey', - hideKeyboard: 'hideKeyboard', - isKeyboardShown: 'isKeyboardShown', - - getDisplayDensity: 'getDisplayDensity', - getSystemBars: 'getSystemBars', - fingerprint: 'mobileFingerprint', - - sendSms: 'mobileSendSms', - gsmCall: 'mobileGsmCall', - gsmSignal: 'mobileGsmSignal', - gsmVoice: 'mobileGsmVoice', - powerAc: 'mobilePowerAC', - powerCapacity: 'mobilePowerCapacity', - networkSpeed: 'mobileNetworkSpeed', - sensorSet: 'sensorSet', - - getPerformanceData: 'mobileGetPerformanceData', - getPerformanceDataTypes: 'getPerformanceDataTypes', - - statusBar: 'mobilePerformStatusBarCommand', - - screenshots: 'mobileScreenshots', - - setUiMode: 'mobileSetUiMode', - getUiMode: 'mobileGetUiMode', - - startLogsBroadcast: 'mobileStartLogsBroadcast', - stopLogsBroadcast: 'mobileStopLogsBroadcast', }; - - if (!_.has(mobileCommandsMapping, mobileCommand)) { - throw new errors.UnknownCommandError(`Unknown mobile command "${mobileCommand}". ` + - `Only ${_.keys(mobileCommandsMapping)} commands are supported.`); - } - return await this[/**@type {string}*/(mobileCommandsMapping[mobileCommand])](opts); } + +/** + * @typedef {import('../driver').EspressoDriver} EspressoDriver + */ diff --git a/lib/driver.ts b/lib/driver.ts index cae3fe1b..76b87aa0 100644 --- a/lib/driver.ts +++ b/lib/driver.ts @@ -700,7 +700,7 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver< performActions = actionsCmds.performActions; - executeMobile = executeCmds.executeMobile; + mobileCommandsMapping = executeCmds.mobileCommandsMapping; mobileBackgroundApp = appManagementCmds.mobileBackgroundApp; startActivity = appManagementCmds.startActivity; diff --git a/package.json b/package.json index d77f69ad..ac050256 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ ], "dependencies": { "appium-adb": "^12.2.0", - "appium-android-driver": "^9.3.0", + "appium-android-driver": "^9.6.0", "asyncbox": "^3.0.0", "bluebird": "^3.5.0", "io.appium.settings": "^5.7.2",