Skip to content

Commit 4c45c3a

Browse files
feat: Add support of executeMethodMap (#863)
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
1 parent b349a50 commit 4c45c3a

16 files changed

+543
-641
lines changed

lib/commands/actions.js

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,66 @@
11
/**
2-
* See https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
2+
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
33
* @this {AndroidUiautomator2Driver}
4-
* @param {Record<string, any>} [opts={}]
4+
* @param {string} name
5+
* @param {import('@appium/types').StringRecord[]} steps
6+
* @param {number} [maxPass]
7+
* @param {number} [maxFail]
8+
* @param {number} [times]
9+
* @param {number} [intervalMs]
10+
* @param {number} [maxHistoryItems]
511
* @returns {Promise<any>}
612
*/
7-
export async function mobileScheduleAction(opts = {}) {
13+
export async function mobileScheduleAction(
14+
name,
15+
steps,
16+
maxPass,
17+
maxFail,
18+
times,
19+
intervalMs,
20+
maxHistoryItems,
21+
) {
822
return await this.uiautomator2.jwproxy.command(
923
'/appium/schedule_action',
1024
'POST',
11-
opts
25+
{
26+
name,
27+
steps,
28+
maxFail,
29+
maxPass,
30+
times,
31+
intervalMs,
32+
maxHistoryItems,
33+
}
1234
);
1335
}
1436

1537
/**
1638
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
1739
* @this {AndroidUiautomator2Driver}
18-
* @param {import('./types').ActionArgs} [opts={}]
40+
* @param {string} name
1941
* @returns {Promise<import('./types').ActionResult>}
2042
*/
21-
export async function mobileGetActionHistory(opts) {
43+
export async function mobileGetActionHistory(name) {
2244
return /** @type {import('./types').ActionResult} */ (
2345
await this.uiautomator2.jwproxy.command(
2446
'/appium/action_history',
2547
'POST',
26-
opts ?? {}
48+
{name}
2749
)
2850
);
2951
}
3052

3153
/**
3254
* @this {AndroidUiautomator2Driver}
3355
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
34-
* @param {import('./types').ActionArgs} [opts={}]
56+
* @param {string} name
3557
* @returns {Promise<any>}
3658
*/
37-
export async function mobileUnscheduleAction(opts) {
59+
export async function mobileUnscheduleAction(name) {
3860
return await this.uiautomator2.jwproxy.command(
3961
'/appium/unschedule_action',
4062
'POST',
41-
opts ?? {}
63+
{name}
4264
);
4365
}
4466

lib/commands/alert.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ export async function getAlertText() {
1414

1515
/**
1616
* @this {AndroidUiautomator2Driver}
17-
* @param {import('./types').AcceptAlertOptions} [opts={}]
17+
* @param {string} [buttonLabel] The name of the button to click in order to accept the alert.
18+
* If the name is not provided
19+
* then the script will try to detect the button automatically.
1820
* @returns {Promise<void>}
1921
*/
20-
export async function mobileAcceptAlert(opts = {}) {
22+
export async function mobileAcceptAlert(buttonLabel) {
2123
await this.uiautomator2.jwproxy.command(
2224
'/alert/accept',
2325
'POST',
24-
opts
26+
{buttonLabel}
2527
);
2628
}
2729

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

3638
/**
3739
* @this {AndroidUiautomator2Driver}
38-
* @param {import('./types').DismissAlertOptions} [opts={}]
40+
* @param {string} [buttonLabel] The name of the button to click in order to dismiss the alert.
41+
* If the name is not provided
42+
* then the script will try to detect the button automatically.
3943
* @returns {Promise<void>}
4044
*/
41-
export async function mobileDismissAlert(opts = {}) {
45+
export async function mobileDismissAlert(buttonLabel) {
4246
await this.uiautomator2.jwproxy.command(
4347
'/alert/dismiss',
4448
'POST',
45-
opts
49+
{buttonLabel}
4650
);
4751
}
4852

lib/commands/app-management.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@ import {APK_EXTENSION} from '../extensions';
55

66
/**
77
* Install multiple APKs with `install-multiple` option.
8-
* @this {AndroidUiautomator2Driver}=
9-
* @param {import('./types').InstallMultipleApksOptions} opts
8+
* @this {AndroidUiautomator2Driver}
9+
* @param {string[]} apks The list of APKs to install. Each APK should be a path to a apk
10+
* or downloadable URL as HTTP/HTTPS.
11+
* @param {import('./types').InstallOptions} [options] Installation options.
1012
* @throws {Error} if an error occured while installing the given APKs.
1113
* @returns {Promise<void>}
1214
*/
13-
export async function mobileInstallMultipleApks(opts) {
14-
if (!_.isArray(opts.apks) || _.isEmpty(opts.apks)) {
15+
export async function mobileInstallMultipleApks(apks, options) {
16+
if (!_.isArray(apks) || _.isEmpty(apks)) {
1517
throw new errors.InvalidArgumentError('No apks are given to install');
1618
}
17-
const apks = await B.all(
18-
opts.apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
19+
const configuredApks = await B.all(
20+
apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
1921
);
20-
await this.adb.installMultipleApks(apks, opts.options);
22+
await this.adb.installMultipleApks(configuredApks, options);
2123
}
2224

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

lib/commands/app-strings.js

-16
This file was deleted.

lib/commands/clipboard.js

-18
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ export async function getClipboard() {
1515
);
1616
}
1717

18-
/**
19-
* @this {AndroidUiautomator2Driver}
20-
* @returns {Promise<string>} Base64-encoded content of the clipboard
21-
* or an empty string if the clipboard is empty.
22-
*/
23-
export async function mobileGetClipboard() {
24-
return await this.getClipboard();
25-
}
26-
2718
/**
2819
* @this {AndroidUiautomator2Driver}
2920
* @param {string} content Base64-encoded clipboard payload
@@ -41,15 +32,6 @@ export async function setClipboard(content, contentType, label) {
4132
);
4233
}
4334

44-
/**
45-
* @this {AndroidUiautomator2Driver}
46-
* @param {import('./types').SetClipboardOpts} opts
47-
* @returns {Promise<void>}
48-
*/
49-
export async function mobileSetClipboard(opts) {
50-
await this.setClipboard(opts.content, opts.contentType, opts.label);
51-
}
52-
5335
/**
5436
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
5537
*/

lib/commands/element.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import B from 'bluebird';
22
import _ from 'lodash';
33
import {PROTOCOLS} from 'appium/driver';
4-
import {utils} from 'appium-android-driver';
54

65
/**
76
* @this {AndroidUiautomator2Driver}
@@ -229,12 +228,12 @@ export async function getElementRect(elementId) {
229228
/**
230229
* Sends text to the given element by replacing its previous content
231230
* @this {AndroidUiautomator2Driver}
232-
* @param {import('./types').ReplaceValueOptions} opts
231+
* @param {string} elementId The id of the element whose content will be replaced.
232+
* @param {string} text The actual text to set.
233233
* @throws {Error} If there was a faulre while setting the text
234234
* @returns {Promise<void>}
235235
*/
236-
export async function mobileReplaceElementValue(opts) {
237-
const {elementId, text} = utils.requireArgs(['elementId', 'text'], opts);
236+
export async function mobileReplaceElementValue(elementId, text) {
238237
await this.uiautomator2.jwproxy.command(
239238
`/element/${elementId}/value`,
240239
'POST',

lib/commands/execute.js

-93
This file was deleted.

0 commit comments

Comments
 (0)