Skip to content

Commit

Permalink
feat: Add support of executeMethodMap (#863)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The following methods and properties were **removed**:
- mobileSetClipboard -> replaced by setClipboard
- mobileGetClipboard -> replaced by getClipboard
- executeMobile -> replaced by execute (the` script` argument must also be changed to start with `mobile: `)
- mobileCommandsMapping -> replaced by executeMethodsMap
- mobileGetAppStrings -> replaced by getStrings

BREAKING CHANGE: The following methods were **changed**:
- mobileDragGesture
- mobileFlingGesture
- mobileDoubleClickGesture
- mobileClickGesture
- mobilePinchOpenGesture
- mobilePinchCloseGesture
- mobileSwipeGesture
- mobileScrollGesture
- mobileScrollBackTo
- mobileScroll
- mobileDeepLink
- mobileAcceptAlert
- mobileDismissAlert
- mobileType
- mobileReplaceElementValue
- mobileInstallMultipleApks
- mobileBackgroundApp
- mobilePressKey
- mobileScreenshots
- mobileScheduleAction
- mobileUnscheduleAction
- mobileGetActionHistory

BREAKING CHANGE: The following obsolete type definitions were **removed**:
- DragOptions
- FlingOptions
- ClickOptions
- LongClickOptions
- PinchOptions
- SwipeOptions
- ScrollGestureOptions
- ScrollElementToElementOpts
- ScrollOptions
- DeepLinkOpts
- AcceptAlertOptions
- DismissAlertOptions
- TypingOptions
- ReplaceValueOptions
- InstallMultipleApksOptions
- BackgroundAppOptions
- PressKeyOptions
- ScreenshotsOpts
- ActionArgs
- SetClipboardOpts
- GetAppStringsOptions


Based on appium/appium-android-driver#982
  • Loading branch information
mykola-mokhnach authored Feb 1, 2025
1 parent b349a50 commit 4c45c3a
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 641 deletions.
42 changes: 32 additions & 10 deletions lib/commands/actions.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
/**
* See https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
* @this {AndroidUiautomator2Driver}
* @param {Record<string, any>} [opts={}]
* @param {string} name
* @param {import('@appium/types').StringRecord[]} steps
* @param {number} [maxPass]
* @param {number} [maxFail]
* @param {number} [times]
* @param {number} [intervalMs]
* @param {number} [maxHistoryItems]
* @returns {Promise<any>}
*/
export async function mobileScheduleAction(opts = {}) {
export async function mobileScheduleAction(
name,
steps,
maxPass,
maxFail,
times,
intervalMs,
maxHistoryItems,
) {
return await this.uiautomator2.jwproxy.command(
'/appium/schedule_action',
'POST',
opts
{
name,
steps,
maxFail,
maxPass,
times,
intervalMs,
maxHistoryItems,
}
);
}

/**
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
* @this {AndroidUiautomator2Driver}
* @param {import('./types').ActionArgs} [opts={}]
* @param {string} name
* @returns {Promise<import('./types').ActionResult>}
*/
export async function mobileGetActionHistory(opts) {
export async function mobileGetActionHistory(name) {
return /** @type {import('./types').ActionResult} */ (
await this.uiautomator2.jwproxy.command(
'/appium/action_history',
'POST',
opts ?? {}
{name}
)
);
}

/**
* @this {AndroidUiautomator2Driver}
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
* @param {import('./types').ActionArgs} [opts={}]
* @param {string} name
* @returns {Promise<any>}
*/
export async function mobileUnscheduleAction(opts) {
export async function mobileUnscheduleAction(name) {
return await this.uiautomator2.jwproxy.command(
'/appium/unschedule_action',
'POST',
opts ?? {}
{name}
);
}

Expand Down
16 changes: 10 additions & 6 deletions lib/commands/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export async function getAlertText() {

/**
* @this {AndroidUiautomator2Driver}
* @param {import('./types').AcceptAlertOptions} [opts={}]
* @param {string} [buttonLabel] The name of the button to click in order to accept the alert.
* If the name is not provided
* then the script will try to detect the button automatically.
* @returns {Promise<void>}
*/
export async function mobileAcceptAlert(opts = {}) {
export async function mobileAcceptAlert(buttonLabel) {
await this.uiautomator2.jwproxy.command(
'/alert/accept',
'POST',
opts
{buttonLabel}
);
}

Expand All @@ -35,14 +37,16 @@ export async function postAcceptAlert() {

/**
* @this {AndroidUiautomator2Driver}
* @param {import('./types').DismissAlertOptions} [opts={}]
* @param {string} [buttonLabel] The name of the button to click in order to dismiss the alert.
* If the name is not provided
* then the script will try to detect the button automatically.
* @returns {Promise<void>}
*/
export async function mobileDismissAlert(opts = {}) {
export async function mobileDismissAlert(buttonLabel) {
await this.uiautomator2.jwproxy.command(
'/alert/dismiss',
'POST',
opts
{buttonLabel}
);
}

Expand Down
25 changes: 14 additions & 11 deletions lib/commands/app-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@ import {APK_EXTENSION} from '../extensions';

/**
* Install multiple APKs with `install-multiple` option.
* @this {AndroidUiautomator2Driver}=
* @param {import('./types').InstallMultipleApksOptions} opts
* @this {AndroidUiautomator2Driver}
* @param {string[]} apks The list of APKs to install. Each APK should be a path to a apk
* or downloadable URL as HTTP/HTTPS.
* @param {import('./types').InstallOptions} [options] Installation options.
* @throws {Error} if an error occured while installing the given APKs.
* @returns {Promise<void>}
*/
export async function mobileInstallMultipleApks(opts) {
if (!_.isArray(opts.apks) || _.isEmpty(opts.apks)) {
export async function mobileInstallMultipleApks(apks, options) {
if (!_.isArray(apks) || _.isEmpty(apks)) {
throw new errors.InvalidArgumentError('No apks are given to install');
}
const apks = await B.all(
opts.apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
const configuredApks = await B.all(
apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
);
await this.adb.installMultipleApks(apks, opts.options);
await this.adb.installMultipleApks(configuredApks, options);
}

/**
* Puts the app to background and waits the given number of seconds Then restores the app
* Puts the app to background and waits the given number of seconds then restores the app
* if necessary. The call is blocking.
*
* @this {AndroidUiautomator2Driver}
* @param {import('./types').BackgroundAppOptions} [opts={}]
* @param {number} [seconds=-1] The amount of seconds to wait between putting the app to background and restoring it.
* Any negative value means to not restore the app after putting it to background.
* @returns {Promise<void>}
*/
export async function mobileBackgroundApp(opts = {}) {
const {seconds = -1} = opts;
export async function mobileBackgroundApp(seconds = -1) {
await this.background(seconds);
}

Expand Down
16 changes: 0 additions & 16 deletions lib/commands/app-strings.js

This file was deleted.

18 changes: 0 additions & 18 deletions lib/commands/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ export async function getClipboard() {
);
}

/**
* @this {AndroidUiautomator2Driver}
* @returns {Promise<string>} Base64-encoded content of the clipboard
* or an empty string if the clipboard is empty.
*/
export async function mobileGetClipboard() {
return await this.getClipboard();
}

/**
* @this {AndroidUiautomator2Driver}
* @param {string} content Base64-encoded clipboard payload
Expand All @@ -41,15 +32,6 @@ export async function setClipboard(content, contentType, label) {
);
}

/**
* @this {AndroidUiautomator2Driver}
* @param {import('./types').SetClipboardOpts} opts
* @returns {Promise<void>}
*/
export async function mobileSetClipboard(opts) {
await this.setClipboard(opts.content, opts.contentType, opts.label);
}

/**
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
*/
7 changes: 3 additions & 4 deletions lib/commands/element.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import B from 'bluebird';
import _ from 'lodash';
import {PROTOCOLS} from 'appium/driver';
import {utils} from 'appium-android-driver';

/**
* @this {AndroidUiautomator2Driver}
Expand Down Expand Up @@ -229,12 +228,12 @@ export async function getElementRect(elementId) {
/**
* Sends text to the given element by replacing its previous content
* @this {AndroidUiautomator2Driver}
* @param {import('./types').ReplaceValueOptions} opts
* @param {string} elementId The id of the element whose content will be replaced.
* @param {string} text The actual text to set.
* @throws {Error} If there was a faulre while setting the text
* @returns {Promise<void>}
*/
export async function mobileReplaceElementValue(opts) {
const {elementId, text} = utils.requireArgs(['elementId', 'text'], opts);
export async function mobileReplaceElementValue(elementId, text) {
await this.uiautomator2.jwproxy.command(
`/element/${elementId}/value`,
'POST',
Expand Down
93 changes: 0 additions & 93 deletions lib/commands/execute.js

This file was deleted.

Loading

0 comments on commit 4c45c3a

Please sign in to comment.