@midscene/android 1.0.1-beta-20251104075048.0 → 1.0.1-beta-20251106111345.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.mjs +43 -32
- package/dist/lib/index.js +43 -32
- package/dist/types/index.d.ts +23 -1
- package/package.json +4 -4
package/dist/es/index.mjs
CHANGED
|
@@ -105,30 +105,6 @@ class AndroidDevice {
|
|
|
105
105
|
defineActionKeyboardPress(async (param)=>{
|
|
106
106
|
await this.keyboardPress(param.keyName);
|
|
107
107
|
}),
|
|
108
|
-
defineAction({
|
|
109
|
-
name: 'AndroidBackButton',
|
|
110
|
-
description: 'Trigger the system "back" operation on Android devices',
|
|
111
|
-
paramSchema: z.object({}),
|
|
112
|
-
call: async ()=>{
|
|
113
|
-
await this.back();
|
|
114
|
-
}
|
|
115
|
-
}),
|
|
116
|
-
defineAction({
|
|
117
|
-
name: 'AndroidHomeButton',
|
|
118
|
-
description: 'Trigger the system "home" operation on Android devices',
|
|
119
|
-
paramSchema: z.object({}),
|
|
120
|
-
call: async ()=>{
|
|
121
|
-
await this.home();
|
|
122
|
-
}
|
|
123
|
-
}),
|
|
124
|
-
defineAction({
|
|
125
|
-
name: 'AndroidRecentAppsButton',
|
|
126
|
-
description: 'Trigger the system "recent apps" operation on Android devices',
|
|
127
|
-
paramSchema: z.object({}),
|
|
128
|
-
call: async ()=>{
|
|
129
|
-
await this.recentApps();
|
|
130
|
-
}
|
|
131
|
-
}),
|
|
132
108
|
defineAction({
|
|
133
109
|
name: 'AndroidLongPress',
|
|
134
110
|
description: 'Trigger a long press on the screen at specified coordinates on Android devices',
|
|
@@ -314,7 +290,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
314
290
|
const result = {
|
|
315
291
|
override: sizeStr,
|
|
316
292
|
physical: sizeStr,
|
|
317
|
-
orientation: rotation
|
|
293
|
+
orientation: rotation,
|
|
294
|
+
isCurrentOrientation: true
|
|
318
295
|
};
|
|
319
296
|
if (shouldCache) this.cachedScreenSize = result;
|
|
320
297
|
return result;
|
|
@@ -337,7 +314,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
337
314
|
const result = {
|
|
338
315
|
override: sizeStr,
|
|
339
316
|
physical: sizeStr,
|
|
340
|
-
orientation: rotation
|
|
317
|
+
orientation: rotation,
|
|
318
|
+
isCurrentOrientation: true
|
|
341
319
|
};
|
|
342
320
|
if (shouldCache) this.cachedScreenSize = result;
|
|
343
321
|
return result;
|
|
@@ -370,7 +348,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
370
348
|
if (size.override || size.physical) {
|
|
371
349
|
const result = {
|
|
372
350
|
...size,
|
|
373
|
-
orientation
|
|
351
|
+
orientation,
|
|
352
|
+
isCurrentOrientation: false
|
|
374
353
|
};
|
|
375
354
|
if (shouldCache) this.cachedScreenSize = result;
|
|
376
355
|
return result;
|
|
@@ -456,8 +435,9 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
456
435
|
const match = (screenSize.override || screenSize.physical).match(/(\d+)x(\d+)/);
|
|
457
436
|
if (!match || match.length < 3) throw new Error(`Unable to parse screen size: ${screenSize}`);
|
|
458
437
|
const isLandscape = 1 === screenSize.orientation || 3 === screenSize.orientation;
|
|
459
|
-
const
|
|
460
|
-
const
|
|
438
|
+
const shouldSwap = true !== screenSize.isCurrentOrientation && isLandscape;
|
|
439
|
+
const width = Number.parseInt(match[shouldSwap ? 2 : 1], 10);
|
|
440
|
+
const height = Number.parseInt(match[shouldSwap ? 1 : 2], 10);
|
|
461
441
|
const scale = (null == (_this_options = this.options) ? void 0 : _this_options.screenshotResizeScale) ?? 1 / this.devicePixelRatio;
|
|
462
442
|
this.scalingRatio = scale;
|
|
463
443
|
const logicalWidth = Math.round(width * scale);
|
|
@@ -968,6 +948,30 @@ const createPlatformActions = (device)=>({
|
|
|
968
948
|
call: async (param)=>{
|
|
969
949
|
await device.launch(param);
|
|
970
950
|
}
|
|
951
|
+
}),
|
|
952
|
+
AndroidBackButton: defineAction({
|
|
953
|
+
name: 'AndroidBackButton',
|
|
954
|
+
description: 'Trigger the system "back" operation on Android devices',
|
|
955
|
+
paramSchema: z["void"]().describe('No parameters required'),
|
|
956
|
+
call: async ()=>{
|
|
957
|
+
await device.back();
|
|
958
|
+
}
|
|
959
|
+
}),
|
|
960
|
+
AndroidHomeButton: defineAction({
|
|
961
|
+
name: 'AndroidHomeButton',
|
|
962
|
+
description: 'Trigger the system "home" operation on Android devices',
|
|
963
|
+
paramSchema: z["void"]().describe('No parameters required'),
|
|
964
|
+
call: async ()=>{
|
|
965
|
+
await device.home();
|
|
966
|
+
}
|
|
967
|
+
}),
|
|
968
|
+
AndroidRecentAppsButton: defineAction({
|
|
969
|
+
name: 'AndroidRecentAppsButton',
|
|
970
|
+
description: 'Trigger the system "recent apps" operation on Android devices',
|
|
971
|
+
paramSchema: z["void"]().describe('No parameters required'),
|
|
972
|
+
call: async ()=>{
|
|
973
|
+
await device.recentApps();
|
|
974
|
+
}
|
|
971
975
|
})
|
|
972
976
|
});
|
|
973
977
|
const debugUtils = getDebug('android:utils');
|
|
@@ -998,10 +1002,17 @@ function agent_define_property(obj, key, value) {
|
|
|
998
1002
|
}
|
|
999
1003
|
const debugAgent = getDebug('android:agent');
|
|
1000
1004
|
class AndroidAgent extends Agent {
|
|
1005
|
+
createActionWrapper(name) {
|
|
1006
|
+
const action = this.wrapActionInActionSpace(name);
|
|
1007
|
+
return (...args)=>action(args[0]);
|
|
1008
|
+
}
|
|
1001
1009
|
constructor(device, opts){
|
|
1002
|
-
super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runAdbShell", void 0);
|
|
1003
|
-
this.launch = this.
|
|
1004
|
-
this.runAdbShell = this.
|
|
1010
|
+
super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runAdbShell", void 0), agent_define_property(this, "back", void 0), agent_define_property(this, "home", void 0), agent_define_property(this, "recentApps", void 0);
|
|
1011
|
+
this.launch = this.createActionWrapper('Launch');
|
|
1012
|
+
this.runAdbShell = this.createActionWrapper('RunAdbShell');
|
|
1013
|
+
this.back = this.createActionWrapper('AndroidBackButton');
|
|
1014
|
+
this.home = this.createActionWrapper('AndroidHomeButton');
|
|
1015
|
+
this.recentApps = this.createActionWrapper('AndroidRecentAppsButton');
|
|
1005
1016
|
}
|
|
1006
1017
|
}
|
|
1007
1018
|
async function agentFromAdbDevice(deviceId, opts) {
|
package/dist/lib/index.js
CHANGED
|
@@ -151,30 +151,6 @@ class AndroidDevice {
|
|
|
151
151
|
(0, device_namespaceObject.defineActionKeyboardPress)(async (param)=>{
|
|
152
152
|
await this.keyboardPress(param.keyName);
|
|
153
153
|
}),
|
|
154
|
-
(0, device_namespaceObject.defineAction)({
|
|
155
|
-
name: 'AndroidBackButton',
|
|
156
|
-
description: 'Trigger the system "back" operation on Android devices',
|
|
157
|
-
paramSchema: core_namespaceObject.z.object({}),
|
|
158
|
-
call: async ()=>{
|
|
159
|
-
await this.back();
|
|
160
|
-
}
|
|
161
|
-
}),
|
|
162
|
-
(0, device_namespaceObject.defineAction)({
|
|
163
|
-
name: 'AndroidHomeButton',
|
|
164
|
-
description: 'Trigger the system "home" operation on Android devices',
|
|
165
|
-
paramSchema: core_namespaceObject.z.object({}),
|
|
166
|
-
call: async ()=>{
|
|
167
|
-
await this.home();
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
(0, device_namespaceObject.defineAction)({
|
|
171
|
-
name: 'AndroidRecentAppsButton',
|
|
172
|
-
description: 'Trigger the system "recent apps" operation on Android devices',
|
|
173
|
-
paramSchema: core_namespaceObject.z.object({}),
|
|
174
|
-
call: async ()=>{
|
|
175
|
-
await this.recentApps();
|
|
176
|
-
}
|
|
177
|
-
}),
|
|
178
154
|
(0, device_namespaceObject.defineAction)({
|
|
179
155
|
name: 'AndroidLongPress',
|
|
180
156
|
description: 'Trigger a long press on the screen at specified coordinates on Android devices',
|
|
@@ -360,7 +336,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
360
336
|
const result = {
|
|
361
337
|
override: sizeStr,
|
|
362
338
|
physical: sizeStr,
|
|
363
|
-
orientation: rotation
|
|
339
|
+
orientation: rotation,
|
|
340
|
+
isCurrentOrientation: true
|
|
364
341
|
};
|
|
365
342
|
if (shouldCache) this.cachedScreenSize = result;
|
|
366
343
|
return result;
|
|
@@ -383,7 +360,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
383
360
|
const result = {
|
|
384
361
|
override: sizeStr,
|
|
385
362
|
physical: sizeStr,
|
|
386
|
-
orientation: rotation
|
|
363
|
+
orientation: rotation,
|
|
364
|
+
isCurrentOrientation: true
|
|
387
365
|
};
|
|
388
366
|
if (shouldCache) this.cachedScreenSize = result;
|
|
389
367
|
return result;
|
|
@@ -416,7 +394,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
416
394
|
if (size.override || size.physical) {
|
|
417
395
|
const result = {
|
|
418
396
|
...size,
|
|
419
|
-
orientation
|
|
397
|
+
orientation,
|
|
398
|
+
isCurrentOrientation: false
|
|
420
399
|
};
|
|
421
400
|
if (shouldCache) this.cachedScreenSize = result;
|
|
422
401
|
return result;
|
|
@@ -502,8 +481,9 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
502
481
|
const match = (screenSize.override || screenSize.physical).match(/(\d+)x(\d+)/);
|
|
503
482
|
if (!match || match.length < 3) throw new Error(`Unable to parse screen size: ${screenSize}`);
|
|
504
483
|
const isLandscape = 1 === screenSize.orientation || 3 === screenSize.orientation;
|
|
505
|
-
const
|
|
506
|
-
const
|
|
484
|
+
const shouldSwap = true !== screenSize.isCurrentOrientation && isLandscape;
|
|
485
|
+
const width = Number.parseInt(match[shouldSwap ? 2 : 1], 10);
|
|
486
|
+
const height = Number.parseInt(match[shouldSwap ? 1 : 2], 10);
|
|
507
487
|
const scale = (null == (_this_options = this.options) ? void 0 : _this_options.screenshotResizeScale) ?? 1 / this.devicePixelRatio;
|
|
508
488
|
this.scalingRatio = scale;
|
|
509
489
|
const logicalWidth = Math.round(width * scale);
|
|
@@ -1014,6 +994,30 @@ const createPlatformActions = (device)=>({
|
|
|
1014
994
|
call: async (param)=>{
|
|
1015
995
|
await device.launch(param);
|
|
1016
996
|
}
|
|
997
|
+
}),
|
|
998
|
+
AndroidBackButton: (0, device_namespaceObject.defineAction)({
|
|
999
|
+
name: 'AndroidBackButton',
|
|
1000
|
+
description: 'Trigger the system "back" operation on Android devices',
|
|
1001
|
+
paramSchema: core_namespaceObject.z["void"]().describe('No parameters required'),
|
|
1002
|
+
call: async ()=>{
|
|
1003
|
+
await device.back();
|
|
1004
|
+
}
|
|
1005
|
+
}),
|
|
1006
|
+
AndroidHomeButton: (0, device_namespaceObject.defineAction)({
|
|
1007
|
+
name: 'AndroidHomeButton',
|
|
1008
|
+
description: 'Trigger the system "home" operation on Android devices',
|
|
1009
|
+
paramSchema: core_namespaceObject.z["void"]().describe('No parameters required'),
|
|
1010
|
+
call: async ()=>{
|
|
1011
|
+
await device.home();
|
|
1012
|
+
}
|
|
1013
|
+
}),
|
|
1014
|
+
AndroidRecentAppsButton: (0, device_namespaceObject.defineAction)({
|
|
1015
|
+
name: 'AndroidRecentAppsButton',
|
|
1016
|
+
description: 'Trigger the system "recent apps" operation on Android devices',
|
|
1017
|
+
paramSchema: core_namespaceObject.z["void"]().describe('No parameters required'),
|
|
1018
|
+
call: async ()=>{
|
|
1019
|
+
await device.recentApps();
|
|
1020
|
+
}
|
|
1017
1021
|
})
|
|
1018
1022
|
});
|
|
1019
1023
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
@@ -1045,10 +1049,17 @@ function agent_define_property(obj, key, value) {
|
|
|
1045
1049
|
}
|
|
1046
1050
|
const debugAgent = (0, logger_namespaceObject.getDebug)('android:agent');
|
|
1047
1051
|
class AndroidAgent extends agent_namespaceObject.Agent {
|
|
1052
|
+
createActionWrapper(name) {
|
|
1053
|
+
const action = this.wrapActionInActionSpace(name);
|
|
1054
|
+
return (...args)=>action(args[0]);
|
|
1055
|
+
}
|
|
1048
1056
|
constructor(device, opts){
|
|
1049
|
-
super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runAdbShell", void 0);
|
|
1050
|
-
this.launch = this.
|
|
1051
|
-
this.runAdbShell = this.
|
|
1057
|
+
super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runAdbShell", void 0), agent_define_property(this, "back", void 0), agent_define_property(this, "home", void 0), agent_define_property(this, "recentApps", void 0);
|
|
1058
|
+
this.launch = this.createActionWrapper('Launch');
|
|
1059
|
+
this.runAdbShell = this.createActionWrapper('RunAdbShell');
|
|
1060
|
+
this.back = this.createActionWrapper('AndroidBackButton');
|
|
1061
|
+
this.home = this.createActionWrapper('AndroidHomeButton');
|
|
1062
|
+
this.recentApps = this.createActionWrapper('AndroidRecentAppsButton');
|
|
1052
1063
|
}
|
|
1053
1064
|
}
|
|
1054
1065
|
async function agentFromAdbDevice(deviceId, opts) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ import { Point } from '@midscene/core';
|
|
|
15
15
|
import { Size } from '@midscene/core';
|
|
16
16
|
import { z } from '@midscene/core';
|
|
17
17
|
|
|
18
|
+
declare type ActionArgs<T extends DeviceAction> = [ActionParam<T>] extends [undefined] ? [] : [ActionParam<T>];
|
|
19
|
+
|
|
18
20
|
export declare function agentFromAdbDevice(deviceId?: string, opts?: AndroidAgentOpt & AndroidDeviceOpt): Promise<AndroidAgent>;
|
|
19
21
|
|
|
20
22
|
export declare class AndroidAgent extends Agent<AndroidDevice> {
|
|
@@ -26,7 +28,20 @@ export declare class AndroidAgent extends Agent<AndroidDevice> {
|
|
|
26
28
|
* Execute ADB shell command on Android device
|
|
27
29
|
*/
|
|
28
30
|
runAdbShell: WrappedAction<DeviceActionRunAdbShell>;
|
|
31
|
+
/**
|
|
32
|
+
* Trigger the system back operation on Android devices
|
|
33
|
+
*/
|
|
34
|
+
back: WrappedAction<DeviceActionAndroidBackButton>;
|
|
35
|
+
/**
|
|
36
|
+
* Trigger the system home operation on Android devices
|
|
37
|
+
*/
|
|
38
|
+
home: WrappedAction<DeviceActionAndroidHomeButton>;
|
|
39
|
+
/**
|
|
40
|
+
* Trigger the system recent apps operation on Android devices
|
|
41
|
+
*/
|
|
42
|
+
recentApps: WrappedAction<DeviceActionAndroidRecentAppsButton>;
|
|
29
43
|
constructor(device: AndroidDevice, opts?: AndroidAgentOpt);
|
|
44
|
+
private createActionWrapper;
|
|
30
45
|
}
|
|
31
46
|
|
|
32
47
|
declare type AndroidAgentOpt = AgentOpt;
|
|
@@ -61,6 +76,7 @@ export declare class AndroidDevice implements AbstractInterface {
|
|
|
61
76
|
override: string;
|
|
62
77
|
physical: string;
|
|
63
78
|
orientation: number;
|
|
79
|
+
isCurrentOrientation?: boolean;
|
|
64
80
|
}>;
|
|
65
81
|
private initializeDevicePixelRatio;
|
|
66
82
|
getDisplayDensity(): Promise<number>;
|
|
@@ -126,6 +142,12 @@ export declare class AndroidDevice implements AbstractInterface {
|
|
|
126
142
|
hideKeyboard(options?: AndroidDeviceInputOpt, timeoutMs?: number): Promise<boolean>;
|
|
127
143
|
}
|
|
128
144
|
|
|
145
|
+
declare type DeviceActionAndroidBackButton = DeviceAction<void, void>;
|
|
146
|
+
|
|
147
|
+
declare type DeviceActionAndroidHomeButton = DeviceAction<void, void>;
|
|
148
|
+
|
|
149
|
+
declare type DeviceActionAndroidRecentAppsButton = DeviceAction<void, void>;
|
|
150
|
+
|
|
129
151
|
declare type DeviceActionLaunch = DeviceAction<LaunchParam, void>;
|
|
130
152
|
|
|
131
153
|
declare type DeviceActionRunAdbShell = DeviceAction<RunAdbShellParam, string>;
|
|
@@ -149,6 +171,6 @@ declare const runAdbShellParamSchema: z.ZodString;
|
|
|
149
171
|
/**
|
|
150
172
|
* Helper type to convert DeviceAction to wrapped method signature
|
|
151
173
|
*/
|
|
152
|
-
declare type WrappedAction<T extends DeviceAction> = (
|
|
174
|
+
declare type WrappedAction<T extends DeviceAction> = (...args: ActionArgs<T>) => Promise<ActionReturn<T>>;
|
|
153
175
|
|
|
154
176
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "1.0.1-beta-
|
|
3
|
+
"version": "1.0.1-beta-20251106111345.0",
|
|
4
4
|
"description": "Android automation library for Midscene",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Android UI automation",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"appium-adb": "12.12.1",
|
|
30
|
-
"@midscene/shared": "1.0.1-beta-
|
|
31
|
-
"@midscene/core": "1.0.1-beta-
|
|
30
|
+
"@midscene/shared": "1.0.1-beta-20251106111345.0",
|
|
31
|
+
"@midscene/core": "1.0.1-beta-20251106111345.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rslib/core": "^0.11.2",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"tsx": "^4.19.2",
|
|
39
39
|
"vitest": "3.0.5",
|
|
40
40
|
"zod": "3.24.3",
|
|
41
|
-
"@midscene/playground": "1.0.1-beta-
|
|
41
|
+
"@midscene/playground": "1.0.1-beta-20251106111345.0"
|
|
42
42
|
},
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"scripts": {
|