Skip to content

Commit 1e7606c

Browse files
chore: Migrate the rest of command modules to typescript (#971)
1 parent 7ac292f commit 1e7606c

21 files changed

Lines changed: 570 additions & 550 deletions

lib/commands/actions.js

Lines changed: 0 additions & 107 deletions
This file was deleted.

lib/commands/actions.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import type {StringRecord} from '@appium/types';
2+
import type {AndroidUiautomator2Driver} from '../driver';
3+
import type {ActionResult} from './types';
4+
5+
/**
6+
* Schedules a recurring action to be performed at specified intervals.
7+
* @param name - Unique name for the scheduled action.
8+
* @param steps - Array of action steps to be executed.
9+
* @param maxPass - Maximum number of successful executions before stopping.
10+
* @param maxFail - Maximum number of failed executions before stopping.
11+
* @param times - Total number of times to execute the action.
12+
* @param intervalMs - Interval in milliseconds between action executions.
13+
* @param maxHistoryItems - Maximum number of history items to keep.
14+
* @returns The result of scheduling the action.
15+
*/
16+
export async function mobileScheduleAction(
17+
this: AndroidUiautomator2Driver,
18+
name: string,
19+
steps: StringRecord[],
20+
maxPass?: number,
21+
maxFail?: number,
22+
times?: number,
23+
intervalMs?: number,
24+
maxHistoryItems?: number,
25+
): Promise<any> {
26+
return await this.uiautomator2.jwproxy.command('/appium/schedule_action', 'POST', {
27+
name,
28+
steps,
29+
maxFail,
30+
maxPass,
31+
times,
32+
intervalMs,
33+
maxHistoryItems,
34+
});
35+
}
36+
37+
/**
38+
* Gets the execution history for a scheduled action.
39+
* @param name - Name of the scheduled action.
40+
* @returns The action execution history containing repeats and step results.
41+
*/
42+
export async function mobileGetActionHistory(
43+
this: AndroidUiautomator2Driver,
44+
name: string,
45+
): Promise<ActionResult> {
46+
return (await this.uiautomator2.jwproxy.command('/appium/action_history', 'POST', {name})) as ActionResult;
47+
}
48+
49+
/**
50+
* Unschedules a previously scheduled action.
51+
* @param name - Name of the scheduled action to unschedule.
52+
* @returns The result of unscheduling the action.
53+
*/
54+
export async function mobileUnscheduleAction(
55+
this: AndroidUiautomator2Driver,
56+
name: string,
57+
): Promise<any> {
58+
return await this.uiautomator2.jwproxy.command('/appium/unschedule_action', 'POST', {name});
59+
}
60+
61+
/**
62+
* Performs a sequence of actions.
63+
* @param actions - Array of action objects to perform. Pointer actions are automatically converted to touch type.
64+
*/
65+
export async function performActions(
66+
this: AndroidUiautomator2Driver,
67+
actions: StringRecord[],
68+
): Promise<void> {
69+
// This is mandatory, since Selenium API uses MOUSE as the default pointer type
70+
const preprocessedActions = actions.map((action) =>
71+
Object.assign(
72+
{},
73+
action,
74+
action.type === 'pointer'
75+
? {
76+
parameters: {
77+
pointerType: 'touch',
78+
},
79+
}
80+
: {}
81+
)
82+
);
83+
this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
84+
await this.uiautomator2.jwproxy.command('/actions', 'POST', {
85+
actions: preprocessedActions,
86+
});
87+
}
88+
89+
/**
90+
* Releases all currently pressed keys and buttons.
91+
*/
92+
export async function releaseActions(this: AndroidUiautomator2Driver): Promise<void> {
93+
this.log.info('On this platform, releaseActions is a no-op');
94+
}
95+

lib/commands/alert.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

lib/commands/alert.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type {AndroidUiautomator2Driver} from '../driver';
2+
3+
/**
4+
* Gets the text of the currently displayed alert.
5+
* @returns The alert text as a string.
6+
*/
7+
export async function getAlertText(this: AndroidUiautomator2Driver): Promise<string> {
8+
return String(await this.uiautomator2.jwproxy.command('/alert/text', 'GET', {}));
9+
}
10+
11+
/**
12+
* Accepts the currently displayed alert.
13+
* @param buttonLabel - Optional label of the button to click. If not provided, the button will be detected automatically.
14+
*/
15+
export async function mobileAcceptAlert(
16+
this: AndroidUiautomator2Driver,
17+
buttonLabel?: string,
18+
): Promise<void> {
19+
await this.uiautomator2.jwproxy.command('/alert/accept', 'POST', {buttonLabel});
20+
}
21+
22+
/**
23+
* Accepts the currently displayed alert (W3C endpoint).
24+
*/
25+
export async function postAcceptAlert(this: AndroidUiautomator2Driver): Promise<void> {
26+
await this.mobileAcceptAlert();
27+
}
28+
29+
/**
30+
* Dismisses the currently displayed alert.
31+
* @param buttonLabel - Optional label of the button to click. If not provided, the button will be detected automatically.
32+
*/
33+
export async function mobileDismissAlert(
34+
this: AndroidUiautomator2Driver,
35+
buttonLabel?: string,
36+
): Promise<void> {
37+
await this.uiautomator2.jwproxy.command('/alert/dismiss', 'POST', {buttonLabel});
38+
}
39+
40+
/**
41+
* Dismisses the currently displayed alert (W3C endpoint).
42+
*/
43+
export async function postDismissAlert(this: AndroidUiautomator2Driver): Promise<void> {
44+
await this.mobileDismissAlert();
45+
}
46+

lib/commands/app-management.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/commands/app-management.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import _ from 'lodash';
2+
import B from 'bluebird';
3+
import {errors} from 'appium/driver';
4+
import {APK_EXTENSION} from '../extensions';
5+
import type {AndroidUiautomator2Driver} from '../driver';
6+
import type {InstallOptions} from './types';
7+
8+
/**
9+
* Installs multiple APKs with `install-multiple` option.
10+
* @param apks - Array of APK file paths or URLs to install.
11+
* @param options - Optional installation options (allowTestPackages, useSdcard, grantPermissions, etc.).
12+
* @throws {errors.InvalidArgumentError} If the apks array is empty or invalid.
13+
*/
14+
export async function mobileInstallMultipleApks(
15+
this: AndroidUiautomator2Driver,
16+
apks: string[],
17+
options?: InstallOptions,
18+
): Promise<void> {
19+
if (!_.isArray(apks) || _.isEmpty(apks)) {
20+
throw new errors.InvalidArgumentError('No apks are given to install');
21+
}
22+
const configuredApks = await B.all(apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION])));
23+
await this.adb.installMultipleApks(configuredApks, options);
24+
}
25+

lib/commands/battery.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)