Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Align execute methods implementation with other android drivers #1005

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading