assistsx-js 0.0.1353 → 0.0.2002

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.
@@ -0,0 +1,411 @@
1
+ /**
2
+ * 节点类
3
+ * 表示界面上的一个可交互元素,包含元素的属性和可执行的操作
4
+ */
5
+ import { Bounds } from "./Bounds";
6
+ import { AssistsX } from "./AssistsX";
7
+ import { Step } from "./Step";
8
+ import { AssistsXAsync } from "./AssistsXAsync";
9
+ import { Node } from "./Node";
10
+
11
+ export class NodeAsync {
12
+ private node: Node;
13
+
14
+ /**
15
+ * 构造函数
16
+ * @param node Node实例
17
+ */
18
+ constructor(node: Node) {
19
+ this.node = node;
20
+ }
21
+ /**
22
+ * 查找第一个匹配标签的父节点
23
+ * @param className 类名
24
+ * @returns 父节点
25
+ */
26
+ public async findFirstParentByTags(className: string): Promise<Node> {
27
+ Step.assert(this.node.stepId);
28
+ const node = await AssistsXAsync.findFirstParentByTags(
29
+ this.node,
30
+ className
31
+ );
32
+ Step.assert(this.node.stepId);
33
+ return node;
34
+ }
35
+ /**
36
+ * 对节点执行点击手势
37
+ * @param offsetX X轴偏移
38
+ * @param offsetY Y轴偏移
39
+ * @param switchWindowIntervalDelay 窗口切换延迟
40
+ * @param clickDuration 点击持续时间
41
+ * @returns 是否点击成功
42
+ */
43
+ public async clickNodeByGesture({
44
+ offsetX,
45
+ offsetY,
46
+ switchWindowIntervalDelay,
47
+ clickDuration,
48
+ }: {
49
+ offsetX?: number;
50
+ offsetY?: number;
51
+ switchWindowIntervalDelay?: number;
52
+ clickDuration?: number;
53
+ } = {}): Promise<boolean> {
54
+ Step.assert(this.node.stepId);
55
+ const result = await AssistsXAsync.clickNodeByGesture(this.node, {
56
+ offsetX,
57
+ offsetY,
58
+ switchWindowIntervalDelay,
59
+ clickDuration,
60
+ });
61
+ Step.assert(this.node.stepId);
62
+ return result;
63
+ }
64
+ /**
65
+ * 对节点执行双击手势
66
+ * @param offsetX X轴偏移
67
+ * @param offsetY Y轴偏移
68
+ * @param switchWindowIntervalDelay 窗口切换延迟
69
+ * @param clickDuration 点击持续时间
70
+ * @param clickInterval 点击间隔
71
+ * @returns 是否双击成功
72
+ */
73
+ public async doubleClickNodeByGesture({
74
+ offsetX,
75
+ offsetY,
76
+ switchWindowIntervalDelay,
77
+ clickDuration,
78
+ clickInterval,
79
+ }: {
80
+ offsetX?: number;
81
+ offsetY?: number;
82
+ switchWindowIntervalDelay?: number;
83
+ clickDuration?: number;
84
+ clickInterval?: number;
85
+ } = {}): Promise<boolean> {
86
+ Step.assert(this.node.stepId);
87
+ const result = await AssistsXAsync.doubleClickNodeByGesture(this.node, {
88
+ offsetX,
89
+ offsetY,
90
+ switchWindowIntervalDelay,
91
+ clickDuration,
92
+ clickInterval,
93
+ });
94
+ Step.assert(this.node.stepId);
95
+ return result;
96
+ }
97
+
98
+ public async longPressNodeByGestureAutoPaste(
99
+ text: string,
100
+ {
101
+ matchedPackageName,
102
+ matchedText,
103
+ timeoutMillis,
104
+ longPressDuration,
105
+ }: {
106
+ matchedPackageName?: string;
107
+ matchedText?: string;
108
+ timeoutMillis?: number;
109
+ longPressDuration?: number;
110
+ } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
111
+ ): Promise<boolean> {
112
+ Step.assert(this.node.stepId);
113
+ const result = await AssistsXAsync.longPressNodeByGestureAutoPaste(
114
+ this.node,
115
+ text,
116
+ {
117
+ matchedPackageName,
118
+ matchedText,
119
+ timeoutMillis,
120
+ longPressDuration,
121
+ }
122
+ );
123
+ Step.assert(this.node.stepId);
124
+ return result;
125
+ }
126
+
127
+ /**
128
+ * 在当前节点范围内通过标签查找节点
129
+ * @param className 类名
130
+ * @param filterText 文本过滤
131
+ * @param filterViewId 视图ID过滤
132
+ * @param filterDes 描述过滤
133
+ * @returns 节点数组
134
+ */
135
+ public async findByTags(
136
+ className: string,
137
+ {
138
+ filterText,
139
+ filterViewId,
140
+ filterDes,
141
+ }: { filterText?: string; filterViewId?: string; filterDes?: string } = {}
142
+ ): Promise<Node[]> {
143
+ Step.assert(this.node.stepId);
144
+ const result = await AssistsXAsync.findByTags(className, {
145
+ filterText,
146
+ filterViewId,
147
+ filterDes,
148
+ node: this.node,
149
+ });
150
+ Step.assignIdsToNodes(result, this.node.stepId);
151
+ Step.assert(this.node.stepId);
152
+ return result;
153
+ }
154
+ /**
155
+ * 在当前节点范围内通过ID查找节点
156
+ * @param id 节点ID
157
+ * @param filterClass 类名过滤
158
+ * @param filterText 文本过滤
159
+ * @param filterDes 描述过滤
160
+ * @returns 节点数组
161
+ */
162
+ public async findById(
163
+ id: string,
164
+ {
165
+ filterClass,
166
+ filterText,
167
+ filterDes,
168
+ }: { filterClass?: string; filterText?: string; filterDes?: string } = {}
169
+ ): Promise<Node[]> {
170
+ Step.assert(this.node.stepId);
171
+ const result = await AssistsXAsync.findById(id, {
172
+ filterClass,
173
+ filterText,
174
+ filterDes,
175
+ node: this.node,
176
+ });
177
+ Step.assignIdsToNodes(result, this.node.stepId);
178
+ Step.assert(this.node.stepId);
179
+ return result;
180
+ }
181
+ /**
182
+ * 在当前节点范围内通过文本查找节点
183
+ * @param text 要查找的文本
184
+ * @param filterClass 类名过滤
185
+ * @param filterViewId 视图ID过滤
186
+ * @param filterDes 描述过滤
187
+ * @returns 节点数组
188
+ */
189
+ public async findByText(
190
+ text: string,
191
+ {
192
+ filterClass,
193
+ filterViewId,
194
+ filterDes,
195
+ }: { filterClass?: string; filterViewId?: string; filterDes?: string } = {}
196
+ ): Promise<Node[]> {
197
+ Step.assert(this.node.stepId);
198
+ const result = await AssistsXAsync.findByText(text, {
199
+ filterClass,
200
+ filterViewId,
201
+ filterDes,
202
+ node: this.node,
203
+ });
204
+ Step.assignIdsToNodes(result, this.node.stepId);
205
+ Step.assert(this.node.stepId);
206
+ return result;
207
+ }
208
+
209
+ /**
210
+ * 向前滚动节点
211
+ * @returns 是否滚动成功
212
+ */
213
+ public async scrollForward(): Promise<boolean> {
214
+ Step.assert(this.node.stepId);
215
+ const response = await AssistsXAsync.scrollForward(this.node);
216
+ Step.assert(this.node.stepId);
217
+ return response;
218
+ }
219
+
220
+ /**
221
+ * 向后滚动节点
222
+ * @returns 是否滚动成功
223
+ */
224
+ public async scrollBackward(): Promise<boolean> {
225
+ Step.assert(this.node.stepId);
226
+ const response = await AssistsXAsync.scrollBackward(this.node);
227
+ Step.assert(this.node.stepId);
228
+ return response;
229
+ }
230
+ /**
231
+ * 检查节点是否可见
232
+ * @param compareNode 比较节点
233
+ * @param isFullyByCompareNode 是否完全可见
234
+ * @returns 是否可见
235
+ */
236
+ public async isVisible({
237
+ compareNode,
238
+ isFullyByCompareNode,
239
+ }: {
240
+ compareNode?: Node;
241
+ isFullyByCompareNode?: boolean;
242
+ } = {}): Promise<boolean> {
243
+ Step.assert(this.node.stepId);
244
+ const response = await AssistsXAsync.isVisible(this.node, {
245
+ compareNode,
246
+ isFullyByCompareNode,
247
+ });
248
+ Step.assert(this.node.stepId);
249
+ return response;
250
+ }
251
+ /**
252
+ * 对节点进行截图
253
+ * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
254
+ * @returns 截图路径
255
+ */
256
+ public async takeScreenshot(
257
+ overlayHiddenScreenshotDelayMillis: number = 250
258
+ ): Promise<string> {
259
+ Step.assert(this.node.stepId);
260
+ const result = await AssistsXAsync.takeScreenshotNodes(
261
+ [this.node],
262
+ overlayHiddenScreenshotDelayMillis
263
+ );
264
+ Step.assert(this.node.stepId);
265
+ return result[0];
266
+ }
267
+ /**
268
+ * 设置节点文本
269
+ * @param text 要设置的文本
270
+ * @returns 是否设置成功
271
+ */
272
+ public async setNodeText(text: string): Promise<boolean> {
273
+ Step.assert(this.node.stepId);
274
+ const result = await AssistsXAsync.setNodeText(this.node, text);
275
+ Step.assert(this.node.stepId);
276
+ return result;
277
+ }
278
+ public async paste(text: string): Promise<boolean> {
279
+ Step.assert(this.node.stepId);
280
+ const result = await AssistsXAsync.paste(this.node, text);
281
+ Step.assert(this.node.stepId);
282
+ return result;
283
+ }
284
+ public async focus(): Promise<boolean> {
285
+ Step.assert(this.node.stepId);
286
+ const result = await AssistsXAsync.focus(this.node);
287
+ Step.assert(this.node.stepId);
288
+ return result;
289
+ }
290
+
291
+ /**
292
+ * 点击节点
293
+ * @returns 是否点击成功
294
+ */
295
+ public async click(): Promise<boolean> {
296
+ Step.assert(this.node.stepId);
297
+ const result = await AssistsXAsync.click(this.node);
298
+ Step.assert(this.node.stepId);
299
+ return result;
300
+ }
301
+ /**
302
+ * 长按节点
303
+ * @returns 是否长按成功
304
+ */
305
+ public async longClick(): Promise<boolean> {
306
+ Step.assert(this.node.stepId);
307
+ const result = await AssistsXAsync.longClick(this.node);
308
+ Step.assert(this.node.stepId);
309
+ return result;
310
+ }
311
+ /**
312
+ * 查找第一个可点击的父节点
313
+ * @returns 可点击的父节点
314
+ */
315
+ public async findFirstParentClickable(): Promise<Node> {
316
+ Step.assert(this.node.stepId);
317
+ const result = await AssistsXAsync.findFirstParentClickable(this.node);
318
+ Step.assert(this.node.stepId);
319
+ Step.assignIdsToNodes([result], this.node.stepId);
320
+ return result;
321
+ }
322
+ /**
323
+ * 获取节点在屏幕中的边界
324
+ * @returns 边界对象
325
+ */
326
+ public async getBoundsInScreen(): Promise<Bounds> {
327
+ Step.assert(this.node.stepId);
328
+ const result = await AssistsXAsync.getBoundsInScreen(this.node);
329
+ Step.assert(this.node.stepId);
330
+ return result;
331
+ }
332
+ /**
333
+ * 获取节点的所有子节点
334
+ * @returns 子节点数组
335
+ */
336
+ public async getNodes(): Promise<Node[]> {
337
+ Step.assert(this.node.stepId);
338
+ const result = await AssistsXAsync.getNodes(this.node);
339
+ Step.assert(this.node.stepId);
340
+ Step.assignIdsToNodes(result, this.node.stepId);
341
+ return result;
342
+ }
343
+ /**
344
+ * 获取节点的直接子节点
345
+ * @returns 子节点数组
346
+ */
347
+ public async getChildren(): Promise<Node[]> {
348
+ Step.assert(this.node.stepId);
349
+ const result = await AssistsXAsync.getChildren(this.node);
350
+ Step.assert(this.node.stepId);
351
+ Step.assignIdsToNodes(result, this.node.stepId);
352
+ return result;
353
+ }
354
+
355
+ /**
356
+ * 从JSON字符串创建节点实例
357
+ * @param json JSON字符串
358
+ * @returns 节点实例
359
+ */
360
+ static fromJSON(json: string): Node {
361
+ const data = JSON.parse(json);
362
+ return new Node(data);
363
+ }
364
+
365
+ /**
366
+ * 从普通对象创建节点实例
367
+ * @param data 对象数据
368
+ * @returns 节点实例
369
+ */
370
+ static from(data: any): Node {
371
+ return new Node(data);
372
+ }
373
+
374
+ /**
375
+ * JSON.parse的reviver函数,用于将解析的JSON对象转换为Node实例
376
+ * @param key 属性键
377
+ * @param value 属性值
378
+ * @returns 转换后的值
379
+ */
380
+ static reviver(key: string, value: any): any {
381
+ return key === "" ? new Node(value) : value;
382
+ }
383
+
384
+ /**
385
+ * 创建新的节点实例
386
+ * @param params 节点参数对象
387
+ * @returns 节点实例
388
+ */
389
+ static create(params: {
390
+ nodeId: string;
391
+ text: string;
392
+ des: string;
393
+ viewId: string;
394
+ className: string;
395
+ isScrollable: boolean;
396
+ isClickable: boolean;
397
+ isEnabled: boolean;
398
+ stepId: string | undefined;
399
+ }): Node {
400
+ return new Node(params);
401
+ }
402
+
403
+ /**
404
+ * 从JSON数组创建节点数组
405
+ * @param array JSON数组
406
+ * @returns 节点数组
407
+ */
408
+ static fromJSONArray(array: Array<any>): Node[] {
409
+ return array.map((data) => new Node(data));
410
+ }
411
+ }