assistsx-js 0.0.1353 → 0.0.2001

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