You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
feat(android, harmony): add terminate action to support force-stopping apps and update documentation (#2214)
* feat(android,harmony): Added a terminate action to support forced application termination and supplemented documentation.
Added a terminate interface for Android and Harmony Agent.
Registered the Terminate action in the device action space, supporting forced termination of applications by package name or bundle name.
Completed unit tests for agent/device, covering success, URI truncation, and failure branches.
* fix(core): map yaml terminate shortcut to uri param
* fix(harmony): improve terminate app resolution
* ci(workflow): add workflow dispatch to ci and lint
* fix(visualizer): capitalize action names in playground dropdown
The actionNameForType function did not handle lowercase interfaceAlias
values (e.g. "launch", "terminate", "runHdcShell"), causing inconsistent
capitalization in the Device-Specific APIs dropdown.
---------
Co-authored-by: jeffjiang <jeffjiang@didiglobal.com>
Co-authored-by: quanruzhuoxiu <quanruzhuoxiu@gmail.com>
Copy file name to clipboardExpand all lines: apps/site/docs/en/android-api-reference.mdx
+16-1Lines changed: 16 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ Use this doc when you need to customize Midscene's Android automation or review
17
17
-`Pinch`— Two-finger pinch gesture. Use `scale > 1` to zoom in, `scale < 1` to zoom out.
18
18
-`ClearInput`— Clear the contents of an input field.
19
19
-`Launch`— Open a web URL or `package/.Activity` string.
20
+
-`Terminate`— Force-stop an app by package name.
20
21
-`RunAdbShell`— Execute raw `adb shell` commands.
21
22
-`AndroidBackButton`— Trigger the system back action.
22
23
-`AndroidHomeButton`— Return to the home screen.
@@ -148,7 +149,7 @@ const agent = new AndroidAgent(device, {
148
149
:::info
149
150
150
151
- Use one agent per device connection.
151
-
- Android-only helpers such as `launch` and `runAdbShell` are also exposed in YAML scripts. See [Android platform-specific actions](./automate-with-scripts-in-yaml#the-android-part).
152
+
- Android-only helpers such as `launch`, `terminate`, and `runAdbShell` are also exposed in YAML scripts. See [Android platform-specific actions](./automate-with-scripts-in-yaml#the-android-part).
152
153
- For shared interaction methods, see [API reference (Common)](./api#interaction-methods).
153
154
154
155
:::
@@ -180,6 +181,20 @@ const result = await agent.runAdbShell('dumpsys battery');
180
181
console.log(result);
181
182
```
182
183
184
+
#### `agent.terminate()`
185
+
186
+
Terminate (force-stop) a running Android app.
187
+
188
+
```ts
189
+
function terminate(uri:string):Promise<void>;
190
+
```
191
+
192
+
-`uri: string`— Package name, app name in `appNameMapping`, or `package/.Activity` (only the package part is used).
193
+
194
+
```ts
195
+
awaitagent.terminate('com.android.settings');
196
+
```
197
+
183
198
#### Navigation helpers
184
199
185
200
-`agent.back(): Promise<void>`— Trigger the Android system Back action.
Copy file name to clipboardExpand all lines: apps/site/docs/en/harmony-api-reference.mdx
+16-1Lines changed: 16 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ When you need to customize device behavior, integrate Midscene into a framework,
16
16
-`ClearInput` — Clear input field contents.
17
17
-~~`Pinch`~~ — Not supported. The HarmonyOS `uitest` framework does not provide multi-touch input APIs.
18
18
-`Launch` — Open a HarmonyOS app (bundle name).
19
+
-`Terminate` — Force-stop a HarmonyOS app by bundle name.
19
20
-`RunHdcShell` — Execute a raw `hdc shell` command.
20
21
-`HarmonyBackButton` — Trigger system back.
21
22
-`HarmonyHomeButton` — Return to home screen.
@@ -113,7 +114,7 @@ const agent = new HarmonyAgent(device, {
113
114
:::info
114
115
115
116
- One device connection corresponds to one Agent.
116
-
- HarmonyOS-specific helpers like `launch` and `runHdcShell` can also be used in YAML scripts. See [HarmonyOS platform-specific actions](./automate-with-scripts-in-yaml#the-harmony-part).
117
+
- HarmonyOS-specific helpers like `launch`, `terminate`, and `runHdcShell` can also be used in YAML scripts. See [HarmonyOS platform-specific actions](./automate-with-scripts-in-yaml#the-harmony-part).
117
118
- For common interaction methods, see [API Reference (Common)](./api#interaction-methods).
118
119
119
120
:::
@@ -150,6 +151,20 @@ const result = await agent.runHdcShell('hidumper -s RenderService -a screen');
150
151
console.log(result);
151
152
```
152
153
154
+
#### `agent.terminate()`
155
+
156
+
Terminate (force-stop) a running HarmonyOS app.
157
+
158
+
```ts
159
+
function terminate(uri:string):Promise<void>;
160
+
```
161
+
162
+
-`uri: string` — Bundle name, app name in `appNameMapping`, or `bundle/Ability` (only the bundle part is used).
163
+
164
+
```ts
165
+
awaitagent.terminate('com.huawei.hmos.settings');
166
+
```
167
+
153
168
#### Navigation Helpers
154
169
155
170
-`agent.back(): Promise<void>` — Trigger HarmonyOS system back.
0 commit comments