assistsx-js 0.0.2048 → 0.0.2050
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/AssistsX.d.ts +12 -0
- package/dist/AssistsX.js +22 -0
- package/dist/AssistsXAsync.d.ts +16 -0
- package/dist/AssistsXAsync.js +22 -0
- package/dist/CallMethod.d.ts +2 -0
- package/dist/CallMethod.js +2 -0
- package/dist/Step.d.ts +7 -1
- package/dist/Step.js +20 -7
- package/dist/StepError.d.ts +15 -7
- package/dist/StepError.js +13 -2
- package/package.json +1 -1
- package/src/AssistsX.ts +976 -954
- package/src/AssistsXAsync.ts +1044 -1012
- package/src/CallMethod.ts +62 -60
- package/src/Step.ts +20 -14
- package/src/StepError.ts +48 -36
package/src/CallMethod.ts
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
1
|
// CallMethod 常量对象
|
|
2
2
|
export const CallMethod = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
takeScreenshot: "takeScreenshot",
|
|
4
|
+
overlayToast: "overlayToast",
|
|
5
|
+
setNodeText: "setNodeText",
|
|
6
|
+
findByTags: "findByTags",
|
|
7
|
+
findById: "findById",
|
|
8
|
+
findByText: "findByText",
|
|
9
|
+
findByTextAllMatch: "findByTextAllMatch",
|
|
10
|
+
containsText: "containsText",
|
|
11
|
+
getAllText: "getAllText",
|
|
12
|
+
findFirstParentByTags: "findFirstParentByTags",
|
|
13
|
+
getAllNodes: "getAllNodes",
|
|
14
|
+
getNodes: "getNodes",
|
|
15
|
+
findFirstParentClickable: "findFirstParentClickable",
|
|
16
|
+
getChildren: "getChildren",
|
|
17
|
+
getBoundsInScreen: "getBoundsInScreen",
|
|
18
|
+
isVisible: "isVisible",
|
|
19
|
+
click: "click",
|
|
20
|
+
longClick: "longClick",
|
|
21
|
+
back: "back",
|
|
22
|
+
home: "home",
|
|
23
|
+
notifications: "notifications",
|
|
24
|
+
recentApps: "recentApps",
|
|
25
|
+
paste: "paste",
|
|
26
|
+
focus: "focus",
|
|
27
|
+
selectionText: "selectionText",
|
|
28
|
+
scrollForward: "scrollForward",
|
|
29
|
+
launchApp: "launchApp",
|
|
30
|
+
getPackageName: "getPackageName",
|
|
31
|
+
getScreenSize: "getScreenSize",
|
|
32
|
+
getAppScreenSize: "getAppScreenSize",
|
|
33
|
+
scrollBackward: "scrollBackward",
|
|
34
|
+
setOverlayFlags: "setOverlayFlags",
|
|
35
|
+
scanQR: "scanQR",
|
|
36
|
+
loadWebViewOverlay: "loadWebViewOverlay",
|
|
37
|
+
recognizeTextInScreenshot: "recognizeTextInScreenshot",
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
clickByGesture: "clickByGesture",
|
|
40
|
+
clickNodeByGesture: "clickNodeByGesture",
|
|
41
|
+
doubleClickNodeByGesture: "doubleClickNodeByGesture",
|
|
42
|
+
performLinearGesture: "performLinearGesture",
|
|
43
|
+
longPressGestureAutoPaste: "longPressGestureAutoPaste",
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
getAppInfo: "getAppInfo",
|
|
46
|
+
getMacAddress: "getMacAddress",
|
|
47
|
+
getAndroidID: "getAndroidID",
|
|
48
|
+
getUniqueDeviceId: "getUniqueDeviceId",
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
addAccessibilityEventFilter: "addAccessibilityEventFilter",
|
|
51
|
+
setAccessibilityEventFilters: "setAccessibilityEventFilters",
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
httpRequest: "httpRequest",
|
|
54
|
+
getDeviceInfo: "getDeviceInfo",
|
|
55
|
+
getNetworkType: "getNetworkType",
|
|
56
|
+
isAppInstalled: "isAppInstalled",
|
|
57
|
+
getClipboardLatestText: "getClipboardLatestText",
|
|
58
|
+
openUrlInBrowser: "openUrlInBrowser",
|
|
59
|
+
keepScreenOn: "keepScreenOn",
|
|
60
|
+
clearKeepScreenOn: "clearKeepScreenOn",
|
|
61
|
+
download: "download",
|
|
62
|
+
audioPlayFromFile: "audioPlayFromFile",
|
|
63
|
+
audioStop: "audioStop",
|
|
64
|
+
audioPlayRingtone: "audioPlayRingtone",
|
|
65
|
+
audioStopRingtone: "audioStopRingtone",
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
// 通讯录相关方法
|
|
68
|
+
addContact: "addContact",
|
|
69
|
+
getAllContacts: "getAllContacts",
|
|
68
70
|
} as const;
|
|
69
71
|
|
|
70
72
|
// 导出类型定义
|
package/src/Step.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Node } from "./Node";
|
|
|
7
7
|
import { CallMethod } from "./CallMethod";
|
|
8
8
|
import { useStepStore } from "./StepStateStore";
|
|
9
9
|
import { generateUUID } from "./Utils";
|
|
10
|
-
import { StepError } from "./StepError";
|
|
10
|
+
import { StepError, StepStopError } from "./StepError";
|
|
11
11
|
import { StepAsync } from "./StepAsync";
|
|
12
12
|
|
|
13
13
|
// 步骤结果类型,可以是Step实例或undefined
|
|
@@ -35,6 +35,11 @@ export class Step {
|
|
|
35
35
|
*/
|
|
36
36
|
private static _interceptors: StepInterceptor[] = [];
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* 步骤异常变量,默认为空
|
|
40
|
+
*/
|
|
41
|
+
public static exception: StepError | undefined = undefined;
|
|
42
|
+
|
|
38
43
|
/**
|
|
39
44
|
* 运行步骤实现
|
|
40
45
|
* @param impl 步骤实现函数
|
|
@@ -56,6 +61,7 @@ export class Step {
|
|
|
56
61
|
delayMs?: number;
|
|
57
62
|
} = {}
|
|
58
63
|
): Promise<Step | undefined> {
|
|
64
|
+
this.exception = undefined;
|
|
59
65
|
const stepStore = useStepStore();
|
|
60
66
|
let implnName = impl.name;
|
|
61
67
|
let currentStep: Step | undefined;
|
|
@@ -180,14 +186,7 @@ export class Step {
|
|
|
180
186
|
error: e?.message ?? String(e),
|
|
181
187
|
});
|
|
182
188
|
stepStore.setError(errorMsg);
|
|
183
|
-
throw
|
|
184
|
-
errorMsg,
|
|
185
|
-
implnName,
|
|
186
|
-
tag,
|
|
187
|
-
data,
|
|
188
|
-
e,
|
|
189
|
-
currentStep || undefined
|
|
190
|
-
);
|
|
189
|
+
throw e
|
|
191
190
|
}
|
|
192
191
|
//步骤执行结束
|
|
193
192
|
stepStore.completeStep();
|
|
@@ -206,11 +205,12 @@ export class Step {
|
|
|
206
205
|
* @param stepId 要验证的步骤ID
|
|
207
206
|
*/
|
|
208
207
|
static assert(stepId: string | undefined) {
|
|
208
|
+
// 检查异常变量,如果不为空则直接抛出
|
|
209
|
+
if (Step.exception) {
|
|
210
|
+
throw Step.exception;
|
|
211
|
+
}
|
|
209
212
|
if (stepId && Step.stepId != stepId) {
|
|
210
|
-
|
|
211
|
-
throw new Error("主动中断步骤");
|
|
212
|
-
}
|
|
213
|
-
throw new Error("StepId mismatch");
|
|
213
|
+
throw new StepError("StepId mismatch", { stepId, currentStepId: Step.stepId });
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -229,9 +229,15 @@ export class Step {
|
|
|
229
229
|
|
|
230
230
|
/**
|
|
231
231
|
* 停止当前步骤执行
|
|
232
|
+
* @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
|
|
232
233
|
*/
|
|
233
|
-
static stop(): void {
|
|
234
|
+
static stop(exception?: StepError): void {
|
|
234
235
|
this._stepId = "STEP_STOP";
|
|
236
|
+
if (exception) {
|
|
237
|
+
this.exception = exception;
|
|
238
|
+
} else {
|
|
239
|
+
this.exception = new StepStopError("主动中断步骤", { stepId: this._stepId });
|
|
240
|
+
}
|
|
235
241
|
}
|
|
236
242
|
|
|
237
243
|
/**
|
package/src/StepError.ts
CHANGED
|
@@ -1,47 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 步骤执行错误类
|
|
3
3
|
* 用于携带步骤执行过程中的错误信息和当前步骤对象
|
|
4
|
+
* 支持传入可选数据:message,data任何类型的数据
|
|
4
5
|
*/
|
|
5
6
|
export class StepError extends Error {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* 步骤实现函数名
|
|
9
|
+
*/
|
|
10
|
+
readonly impl?: string;
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 步骤标签
|
|
14
|
+
*/
|
|
15
|
+
readonly tag?: string | undefined;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 步骤数据,可以是任何类型
|
|
19
|
+
*/
|
|
20
|
+
readonly data?: any;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
/**
|
|
23
|
+
* 原始错误
|
|
24
|
+
*/
|
|
25
|
+
readonly originalError?: any;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 当前步骤对象
|
|
29
|
+
*/
|
|
30
|
+
readonly currentStep?: any;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
constructor(
|
|
33
|
+
message?: string,
|
|
34
|
+
data?: any,
|
|
35
|
+
impl?: string,
|
|
36
|
+
tag?: string | undefined,
|
|
37
|
+
originalError?: any,
|
|
38
|
+
currentStep?: any | undefined
|
|
39
|
+
) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = "StepError";
|
|
42
|
+
this.data = data;
|
|
43
|
+
this.impl = impl;
|
|
44
|
+
this.tag = tag;
|
|
45
|
+
this.originalError = originalError;
|
|
46
|
+
this.currentStep = currentStep;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 主动停止异常类
|
|
52
|
+
* 用于表示步骤被主动停止执行
|
|
53
|
+
*/
|
|
54
|
+
export class StepStopError extends StepError {
|
|
55
|
+
constructor(message?: string, data?: any) {
|
|
56
|
+
super(message || "主动中断步骤", data);
|
|
57
|
+
this.name = "StepStopError";
|
|
58
|
+
}
|
|
47
59
|
}
|