assistsx-js 0.0.2049 → 0.0.2051
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/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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/Step.ts +20 -14
- package/src/StepAsync.ts +330 -330
- package/src/StepError.ts +48 -36
- package/src/index.ts +1 -0
package/dist/Step.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Node } from "./Node";
|
|
2
|
+
import { StepError } from "./StepError";
|
|
2
3
|
import { StepAsync } from "./StepAsync";
|
|
3
4
|
export type StepResult = Step | undefined;
|
|
4
5
|
export type StepImpl = (step: Step) => Promise<StepResult>;
|
|
@@ -16,6 +17,10 @@ export declare class Step {
|
|
|
16
17
|
* 步骤拦截器列表
|
|
17
18
|
*/
|
|
18
19
|
private static _interceptors;
|
|
20
|
+
/**
|
|
21
|
+
* 步骤异常变量,默认为空
|
|
22
|
+
*/
|
|
23
|
+
static exception: StepError | undefined;
|
|
19
24
|
/**
|
|
20
25
|
* 运行步骤实现
|
|
21
26
|
* @param impl 步骤实现函数
|
|
@@ -46,8 +51,9 @@ export declare class Step {
|
|
|
46
51
|
static assignIdsToNodes(nodes: Node[], stepId: string | undefined): void;
|
|
47
52
|
/**
|
|
48
53
|
* 停止当前步骤执行
|
|
54
|
+
* @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
|
|
49
55
|
*/
|
|
50
|
-
static stop(): void;
|
|
56
|
+
static stop(exception?: StepError): void;
|
|
51
57
|
/**
|
|
52
58
|
* 添加步骤拦截器
|
|
53
59
|
* @param interceptor 拦截器函数
|
package/dist/Step.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { AssistsX } from "./AssistsX";
|
|
6
6
|
import { useStepStore } from "./StepStateStore";
|
|
7
7
|
import { generateUUID } from "./Utils";
|
|
8
|
-
import { StepError } from "./StepError";
|
|
8
|
+
import { StepError, StepStopError } from "./StepError";
|
|
9
9
|
import { StepAsync } from "./StepAsync";
|
|
10
10
|
export class Step {
|
|
11
11
|
/**
|
|
@@ -17,6 +17,7 @@ export class Step {
|
|
|
17
17
|
*/
|
|
18
18
|
static async run(impl, { stepId, tag, data, delayMs = Step.delayMsDefault, } = {}) {
|
|
19
19
|
var _a, _b, _c, _d, _e, _f;
|
|
20
|
+
this.exception = undefined;
|
|
20
21
|
const stepStore = useStepStore();
|
|
21
22
|
let implnName = impl.name;
|
|
22
23
|
let currentStep;
|
|
@@ -131,7 +132,7 @@ export class Step {
|
|
|
131
132
|
error: (_f = e === null || e === void 0 ? void 0 : e.message) !== null && _f !== void 0 ? _f : String(e),
|
|
132
133
|
});
|
|
133
134
|
stepStore.setError(errorMsg);
|
|
134
|
-
throw
|
|
135
|
+
throw e;
|
|
135
136
|
}
|
|
136
137
|
//步骤执行结束
|
|
137
138
|
stepStore.completeStep();
|
|
@@ -148,11 +149,12 @@ export class Step {
|
|
|
148
149
|
* @param stepId 要验证的步骤ID
|
|
149
150
|
*/
|
|
150
151
|
static assert(stepId) {
|
|
152
|
+
// 检查异常变量,如果不为空则直接抛出
|
|
153
|
+
if (Step.exception) {
|
|
154
|
+
throw Step.exception;
|
|
155
|
+
}
|
|
151
156
|
if (stepId && Step.stepId != stepId) {
|
|
152
|
-
|
|
153
|
-
throw new Error("主动中断步骤");
|
|
154
|
-
}
|
|
155
|
-
throw new Error("StepId mismatch");
|
|
157
|
+
throw new StepError("StepId mismatch", { stepId, currentStepId: Step.stepId });
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
/**
|
|
@@ -169,9 +171,16 @@ export class Step {
|
|
|
169
171
|
}
|
|
170
172
|
/**
|
|
171
173
|
* 停止当前步骤执行
|
|
174
|
+
* @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
|
|
172
175
|
*/
|
|
173
|
-
static stop() {
|
|
176
|
+
static stop(exception) {
|
|
174
177
|
this._stepId = "STEP_STOP";
|
|
178
|
+
if (exception) {
|
|
179
|
+
this.exception = exception;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this.exception = new StepStopError("主动中断步骤", { stepId: this._stepId });
|
|
183
|
+
}
|
|
175
184
|
}
|
|
176
185
|
/**
|
|
177
186
|
* 添加步骤拦截器
|
|
@@ -622,3 +631,7 @@ Step._stepId = undefined;
|
|
|
622
631
|
* 步骤拦截器列表
|
|
623
632
|
*/
|
|
624
633
|
Step._interceptors = [];
|
|
634
|
+
/**
|
|
635
|
+
* 步骤异常变量,默认为空
|
|
636
|
+
*/
|
|
637
|
+
Step.exception = undefined;
|
package/dist/StepError.d.ts
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 步骤执行错误类
|
|
3
3
|
* 用于携带步骤执行过程中的错误信息和当前步骤对象
|
|
4
|
+
* 支持传入可选数据:message,data任何类型的数据
|
|
4
5
|
*/
|
|
5
6
|
export declare class StepError extends Error {
|
|
6
7
|
/**
|
|
7
8
|
* 步骤实现函数名
|
|
8
9
|
*/
|
|
9
|
-
readonly impl
|
|
10
|
+
readonly impl?: string;
|
|
10
11
|
/**
|
|
11
12
|
* 步骤标签
|
|
12
13
|
*/
|
|
13
|
-
readonly tag
|
|
14
|
+
readonly tag?: string | undefined;
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* 步骤数据,可以是任何类型
|
|
16
17
|
*/
|
|
17
|
-
readonly data
|
|
18
|
+
readonly data?: any;
|
|
18
19
|
/**
|
|
19
20
|
* 原始错误
|
|
20
21
|
*/
|
|
21
|
-
readonly originalError
|
|
22
|
+
readonly originalError?: any;
|
|
22
23
|
/**
|
|
23
24
|
* 当前步骤对象
|
|
24
25
|
*/
|
|
25
|
-
readonly currentStep
|
|
26
|
-
constructor(message
|
|
26
|
+
readonly currentStep?: any;
|
|
27
|
+
constructor(message?: string, data?: any, impl?: string, tag?: string | undefined, originalError?: any, currentStep?: any | undefined);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 主动停止异常类
|
|
31
|
+
* 用于表示步骤被主动停止执行
|
|
32
|
+
*/
|
|
33
|
+
export declare class StepStopError extends StepError {
|
|
34
|
+
constructor(message?: string, data?: any);
|
|
27
35
|
}
|
package/dist/StepError.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 步骤执行错误类
|
|
3
3
|
* 用于携带步骤执行过程中的错误信息和当前步骤对象
|
|
4
|
+
* 支持传入可选数据:message,data任何类型的数据
|
|
4
5
|
*/
|
|
5
6
|
export class StepError extends Error {
|
|
6
|
-
constructor(message, impl, tag,
|
|
7
|
+
constructor(message, data, impl, tag, originalError, currentStep) {
|
|
7
8
|
super(message);
|
|
8
9
|
this.name = "StepError";
|
|
10
|
+
this.data = data;
|
|
9
11
|
this.impl = impl;
|
|
10
12
|
this.tag = tag;
|
|
11
|
-
this.data = data;
|
|
12
13
|
this.originalError = originalError;
|
|
13
14
|
this.currentStep = currentStep;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* 主动停止异常类
|
|
19
|
+
* 用于表示步骤被主动停止执行
|
|
20
|
+
*/
|
|
21
|
+
export class StepStopError extends StepError {
|
|
22
|
+
constructor(message, data) {
|
|
23
|
+
super(message || "主动中断步骤", data);
|
|
24
|
+
this.name = "StepStopError";
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
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/StepAsync.ts
CHANGED
|
@@ -12,354 +12,354 @@ import { AssistsXAsync } from "./AssistsXAsync";
|
|
|
12
12
|
import { Step } from "./Step";
|
|
13
13
|
|
|
14
14
|
export class StepAsync {
|
|
15
|
-
|
|
15
|
+
private step: Step;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 构造函数
|
|
19
|
+
* @param step Step实例
|
|
20
|
+
*/
|
|
21
|
+
constructor(step: Step) {
|
|
22
|
+
this.step = step;
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 对单个节点进行截图
|
|
27
|
+
* @param node 目标节点
|
|
28
|
+
* @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
|
|
29
|
+
* @returns 截图路径
|
|
30
|
+
*/
|
|
31
|
+
public async takeScreenshotByNode(
|
|
32
|
+
node: Node,
|
|
33
|
+
overlayHiddenScreenshotDelayMillis: number = 250
|
|
34
|
+
): Promise<string> {
|
|
35
|
+
Step.assert(this.step.stepId);
|
|
36
|
+
const result = await AssistsXAsync.takeScreenshotNodes(
|
|
37
|
+
[node],
|
|
38
|
+
overlayHiddenScreenshotDelayMillis
|
|
39
|
+
);
|
|
40
|
+
Step.assert(this.step.stepId);
|
|
41
|
+
return result[0];
|
|
42
|
+
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
44
|
+
/**
|
|
45
|
+
* 对多个节点进行截图
|
|
46
|
+
* @param nodes 目标节点数组
|
|
47
|
+
* @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
|
|
48
|
+
* @returns 截图路径数组
|
|
49
|
+
*/
|
|
50
|
+
public async takeScreenshotNodes(
|
|
51
|
+
nodes: Node[],
|
|
52
|
+
overlayHiddenScreenshotDelayMillis: number = 250
|
|
53
|
+
): Promise<string[]> {
|
|
54
|
+
Step.assert(this.step.stepId);
|
|
55
|
+
const result = await AssistsXAsync.takeScreenshotNodes(
|
|
56
|
+
nodes,
|
|
57
|
+
overlayHiddenScreenshotDelayMillis
|
|
58
|
+
);
|
|
59
|
+
Step.assert(this.step.stepId);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
63
|
+
/**
|
|
64
|
+
* 获取所有符合条件的节点
|
|
65
|
+
* @param filterClass 类名过滤
|
|
66
|
+
* @param filterViewId 视图ID过滤
|
|
67
|
+
* @param filterDes 描述过滤
|
|
68
|
+
* @param filterText 文本过滤
|
|
69
|
+
* @returns 节点数组
|
|
70
|
+
*/
|
|
71
|
+
public async getAllNodes({
|
|
72
|
+
filterClass,
|
|
73
|
+
filterViewId,
|
|
74
|
+
filterDes,
|
|
75
|
+
filterText,
|
|
76
|
+
}: {
|
|
77
|
+
filterClass?: string;
|
|
78
|
+
filterViewId?: string;
|
|
79
|
+
filterDes?: string;
|
|
80
|
+
filterText?: string;
|
|
81
|
+
} = {}): Promise<Node[]> {
|
|
82
|
+
Step.assert(this.step.stepId);
|
|
83
|
+
const nodes = await AssistsXAsync.getAllNodes({
|
|
84
|
+
filterClass,
|
|
85
|
+
filterViewId,
|
|
86
|
+
filterDes,
|
|
87
|
+
filterText,
|
|
88
|
+
});
|
|
89
|
+
Step.assert(this.step.stepId);
|
|
90
|
+
Step.assignIdsToNodes(nodes, this.step.stepId);
|
|
91
|
+
return nodes;
|
|
92
|
+
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
94
|
+
/**
|
|
95
|
+
* 启动应用
|
|
96
|
+
* @param packageName 应用包名
|
|
97
|
+
* @returns 是否启动成功
|
|
98
|
+
*/
|
|
99
|
+
public async launchApp(packageName: string): Promise<boolean> {
|
|
100
|
+
Step.assert(this.step.stepId);
|
|
101
|
+
const result = await AssistsXAsync.launchApp(packageName);
|
|
102
|
+
Step.assert(this.step.stepId);
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
/**
|
|
107
|
+
* 获取当前应用包名
|
|
108
|
+
* @returns 包名
|
|
109
|
+
*/
|
|
110
|
+
public async getPackageName(): Promise<string> {
|
|
111
|
+
Step.assert(this.step.stepId);
|
|
112
|
+
const result = await AssistsXAsync.getPackageName();
|
|
113
|
+
Step.assert(this.step.stepId);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
117
|
+
/**
|
|
118
|
+
* 通过ID查找节点
|
|
119
|
+
* @param id 节点ID
|
|
120
|
+
* @param filterClass 类名过滤
|
|
121
|
+
* @param filterText 文本过滤
|
|
122
|
+
* @param filterDes 描述过滤
|
|
123
|
+
* @returns 节点数组
|
|
124
|
+
*/
|
|
125
|
+
public async findById(
|
|
126
|
+
id: string,
|
|
127
|
+
{
|
|
128
|
+
filterClass,
|
|
129
|
+
filterText,
|
|
130
|
+
filterDes,
|
|
131
|
+
}: { filterClass?: string; filterText?: string; filterDes?: string } = {}
|
|
132
|
+
): Promise<Node[]> {
|
|
133
|
+
Step.assert(this.step.stepId);
|
|
134
|
+
const nodes = await AssistsXAsync.findById(id, {
|
|
135
|
+
filterClass,
|
|
136
|
+
filterText,
|
|
137
|
+
filterDes,
|
|
138
|
+
});
|
|
139
|
+
Step.assert(this.step.stepId);
|
|
140
|
+
Step.assignIdsToNodes(nodes, this.step.stepId);
|
|
141
|
+
return nodes;
|
|
142
|
+
}
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
144
|
+
/**
|
|
145
|
+
* 通过文本查找节点
|
|
146
|
+
* @param text 要查找的文本
|
|
147
|
+
* @param filterClass 类名过滤
|
|
148
|
+
* @param filterViewId 视图ID过滤
|
|
149
|
+
* @param filterDes 描述过滤
|
|
150
|
+
* @returns 节点数组
|
|
151
|
+
*/
|
|
152
|
+
public async findByText(
|
|
153
|
+
text: string,
|
|
154
|
+
{
|
|
155
|
+
filterClass,
|
|
156
|
+
filterViewId,
|
|
157
|
+
filterDes,
|
|
158
|
+
}: { filterClass?: string; filterViewId?: string; filterDes?: string } = {}
|
|
159
|
+
): Promise<Node[]> {
|
|
160
|
+
Step.assert(this.step.stepId);
|
|
161
|
+
const nodes = await AssistsXAsync.findByText(text, {
|
|
162
|
+
filterClass,
|
|
163
|
+
filterViewId,
|
|
164
|
+
filterDes,
|
|
165
|
+
});
|
|
166
|
+
Step.assert(this.step.stepId);
|
|
167
|
+
Step.assignIdsToNodes(nodes, this.step.stepId);
|
|
168
|
+
return nodes;
|
|
169
|
+
}
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
171
|
+
/**
|
|
172
|
+
* 通过标签查找节点
|
|
173
|
+
* @param className 类名
|
|
174
|
+
* @param filterText 文本过滤
|
|
175
|
+
* @param filterViewId 视图ID过滤
|
|
176
|
+
* @param filterDes 描述过滤
|
|
177
|
+
* @returns 节点数组
|
|
178
|
+
*/
|
|
179
|
+
public async findByTags(
|
|
180
|
+
className: string,
|
|
181
|
+
{
|
|
182
|
+
filterText,
|
|
183
|
+
filterViewId,
|
|
184
|
+
filterDes,
|
|
185
|
+
}: { filterText?: string; filterViewId?: string; filterDes?: string } = {}
|
|
186
|
+
): Promise<Node[]> {
|
|
187
|
+
Step.assert(this.step.stepId);
|
|
188
|
+
const nodes = await AssistsXAsync.findByTags(className, {
|
|
189
|
+
filterText,
|
|
190
|
+
filterViewId,
|
|
191
|
+
filterDes,
|
|
192
|
+
});
|
|
193
|
+
Step.assert(this.step.stepId);
|
|
194
|
+
Step.assignIdsToNodes(nodes, this.step.stepId);
|
|
195
|
+
return nodes;
|
|
196
|
+
}
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
/**
|
|
199
|
+
* 查找所有匹配文本的节点
|
|
200
|
+
* @param text 要查找的文本
|
|
201
|
+
* @returns 节点数组
|
|
202
|
+
*/
|
|
203
|
+
public async findByTextAllMatch(text: string): Promise<Node[]> {
|
|
204
|
+
Step.assert(this.step.stepId);
|
|
205
|
+
const nodes = await AssistsXAsync.findByTextAllMatch(text);
|
|
206
|
+
Step.assert(this.step.stepId);
|
|
207
|
+
Step.assignIdsToNodes(nodes, this.step.stepId);
|
|
208
|
+
return nodes;
|
|
209
|
+
}
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
211
|
+
/**
|
|
212
|
+
* 检查是否包含指定文本
|
|
213
|
+
* @param text 要检查的文本
|
|
214
|
+
* @returns 是否包含
|
|
215
|
+
*/
|
|
216
|
+
public async containsText(text: string): Promise<boolean> {
|
|
217
|
+
Step.assert(this.step.stepId);
|
|
218
|
+
const result = await AssistsXAsync.containsText(text);
|
|
219
|
+
Step.assert(this.step.stepId);
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
222
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
/**
|
|
224
|
+
* 获取所有文本
|
|
225
|
+
* @returns 文本数组
|
|
226
|
+
*/
|
|
227
|
+
public async getAllText(): Promise<string[]> {
|
|
228
|
+
Step.assert(this.step.stepId);
|
|
229
|
+
const texts = await AssistsXAsync.getAllText();
|
|
230
|
+
Step.assert(this.step.stepId);
|
|
231
|
+
return texts;
|
|
232
|
+
}
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
234
|
+
/**
|
|
235
|
+
* 执行点击手势
|
|
236
|
+
* @param x 横坐标
|
|
237
|
+
* @param y 纵坐标
|
|
238
|
+
* @param duration 持续时间(毫秒)
|
|
239
|
+
* @returns 是否成功
|
|
240
|
+
*/
|
|
241
|
+
public async clickByGesture(
|
|
242
|
+
x: number,
|
|
243
|
+
y: number,
|
|
244
|
+
duration: number
|
|
245
|
+
): Promise<boolean> {
|
|
246
|
+
Step.assert(this.step.stepId);
|
|
247
|
+
const result = await AssistsXAsync.clickByGesture(x, y, duration);
|
|
248
|
+
Step.assert(this.step.stepId);
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
252
|
+
public async longPressGestureAutoPaste(
|
|
253
|
+
point: { x: number; y: number },
|
|
254
|
+
text: string,
|
|
255
|
+
{
|
|
256
|
+
matchedPackageName,
|
|
257
|
+
matchedText,
|
|
258
|
+
timeoutMillis,
|
|
259
|
+
longPressDuration,
|
|
260
|
+
}: {
|
|
261
|
+
matchedPackageName?: string;
|
|
262
|
+
matchedText?: string;
|
|
263
|
+
timeoutMillis?: number;
|
|
264
|
+
longPressDuration?: number;
|
|
265
|
+
} = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
|
|
266
|
+
): Promise<boolean> {
|
|
267
|
+
Step.assert(this.step.stepId);
|
|
268
|
+
const result = await AssistsXAsync.longPressGestureAutoPaste(point, text, {
|
|
269
|
+
matchedPackageName,
|
|
270
|
+
matchedText,
|
|
271
|
+
timeoutMillis,
|
|
272
|
+
longPressDuration,
|
|
273
|
+
});
|
|
274
|
+
Step.assert(this.step.stepId);
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
public async getAppInfo(packageName: string): Promise<any> {
|
|
278
|
+
Step.assert(this.step.stepId);
|
|
279
|
+
const result = await AssistsXAsync.getAppInfo(packageName);
|
|
280
|
+
Step.assert(this.step.stepId);
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
public async performLinearGesture(
|
|
284
|
+
startPoint: { x: number; y: number },
|
|
285
|
+
endPoint: { x: number; y: number },
|
|
286
|
+
{ duration }: { duration?: number } = {}
|
|
287
|
+
): Promise<boolean> {
|
|
288
|
+
Step.assert(this.step.stepId);
|
|
289
|
+
const result = await AssistsXAsync.performLinearGesture(
|
|
290
|
+
startPoint,
|
|
291
|
+
endPoint,
|
|
292
|
+
{
|
|
293
|
+
duration,
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
Step.assert(this.step.stepId);
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
300
|
+
/**
|
|
301
|
+
* 返回操作
|
|
302
|
+
* @returns 是否成功
|
|
303
|
+
*/
|
|
304
|
+
public async back(): Promise<boolean> {
|
|
305
|
+
Step.assert(this.step.stepId);
|
|
306
|
+
const result = await AssistsXAsync.back();
|
|
307
|
+
Step.assert(this.step.stepId);
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
310
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
311
|
+
/**
|
|
312
|
+
* 回到主页
|
|
313
|
+
* @returns 是否成功
|
|
314
|
+
*/
|
|
315
|
+
public async home(): Promise<boolean> {
|
|
316
|
+
Step.assert(this.step.stepId);
|
|
317
|
+
const result = await AssistsXAsync.home();
|
|
318
|
+
Step.assert(this.step.stepId);
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
321
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
322
|
+
/**
|
|
323
|
+
* 打开通知栏
|
|
324
|
+
* @returns 是否成功
|
|
325
|
+
*/
|
|
326
|
+
public async notifications(): Promise<boolean> {
|
|
327
|
+
Step.assert(this.step.stepId);
|
|
328
|
+
const result = await AssistsXAsync.notifications();
|
|
329
|
+
Step.assert(this.step.stepId);
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
332
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
333
|
+
/**
|
|
334
|
+
* 显示最近应用
|
|
335
|
+
* @returns 是否成功
|
|
336
|
+
*/
|
|
337
|
+
public async recentApps(): Promise<boolean> {
|
|
338
|
+
Step.assert(this.step.stepId);
|
|
339
|
+
const result = await AssistsXAsync.recentApps();
|
|
340
|
+
Step.assert(this.step.stepId);
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
343
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
344
|
+
/**
|
|
345
|
+
* 获取屏幕尺寸
|
|
346
|
+
* @returns 屏幕尺寸对象
|
|
347
|
+
*/
|
|
348
|
+
public async getScreenSize(): Promise<any> {
|
|
349
|
+
Step.assert(this.step.stepId);
|
|
350
|
+
const data = await AssistsXAsync.getScreenSize();
|
|
351
|
+
Step.assert(this.step.stepId);
|
|
352
|
+
return data;
|
|
353
|
+
}
|
|
354
354
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
355
|
+
/**
|
|
356
|
+
* 获取应用窗口尺寸
|
|
357
|
+
* @returns 应用窗口尺寸对象
|
|
358
|
+
*/
|
|
359
|
+
public async getAppScreenSize(): Promise<any> {
|
|
360
|
+
Step.assert(this.step.stepId);
|
|
361
|
+
const data = await AssistsXAsync.getAppScreenSize();
|
|
362
|
+
Step.assert(this.step.stepId);
|
|
363
|
+
return data;
|
|
364
|
+
}
|
|
365
365
|
}
|
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
|
}
|
package/src/index.ts
CHANGED