Skip to content

Commit

Permalink
feat: Align execute methods implementation with other android drivers (
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored May 12, 2024
1 parent 36e14c9 commit dcd49f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 99 deletions.
108 changes: 11 additions & 97 deletions lib/commands/execute.js
Original file line number Diff line number Diff line change
@@ -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<string, any>} [opts={}]
* @returns {Promise<any>}
* @this {EspressoDriver}
* @returns {import('@appium/types').StringRecord<string>}
*/
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',
Expand All @@ -36,8 +23,6 @@ export async function executeMobile (mobileCommand, opts = {}) {
setDate: 'mobileSetDate',
setTime: 'mobileSetTime',

getDeviceTime: 'mobileGetDeviceTime',

backdoor: 'mobileBackdoor',

flashElement: 'mobileFlashElement',
Expand All @@ -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
*/
2 changes: 1 addition & 1 deletion lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dcd49f3

Please sign in to comment.