assistsx-js 0.0.2047 → 0.0.2048

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/Node.d.ts CHANGED
@@ -109,7 +109,7 @@ export declare class Node {
109
109
  isSelected: boolean;
110
110
  isVisibleToUser: boolean;
111
111
  drawingOrder: number;
112
- boundsInScreen: Bounds;
112
+ boundsInScreen: Bounds | any;
113
113
  });
114
114
  get async(): NodeAsync;
115
115
  /**
package/dist/Node.js CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * 节点类
3
+ * 表示界面上的一个可交互元素,包含元素的属性和可执行的操作
4
+ */
5
+ import { Bounds } from "./Bounds";
1
6
  import { AssistsX } from "./AssistsX";
2
7
  import { Step } from "./Step";
3
8
  import { NodeAsync } from "./NodeAsync";
@@ -27,7 +32,10 @@ export class Node {
27
32
  this.isSelected = params.isSelected;
28
33
  this.isVisibleToUser = params.isVisibleToUser;
29
34
  this.drawingOrder = params.drawingOrder;
30
- this.boundsInScreen = params.boundsInScreen;
35
+ // 确保 boundsInScreen Bounds 实例,如果不是则转换
36
+ this.boundsInScreen = params.boundsInScreen instanceof Bounds
37
+ ? params.boundsInScreen
38
+ : Bounds.fromData(params.boundsInScreen);
31
39
  }
32
40
  get async() {
33
41
  return new NodeAsync(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.0.2047",
3
+ "version": "0.0.2048",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/Node.ts CHANGED
@@ -9,548 +9,551 @@ import { NodeAsync } from "./NodeAsync";
9
9
 
10
10
  // 将接口改造为类
11
11
  export class Node {
12
- /**
13
- * 节点唯一标识
14
- */
15
- nodeId: string;
16
-
17
- /**
18
- * 节点文本内容
19
- */
20
- text: string;
21
-
22
- /**
23
- * 节点描述信息
24
- */
25
- des: string;
26
-
27
- /**
28
- * 节点视图ID
29
- */
30
- viewId: string;
31
-
32
- /**
33
- * 节点类名
34
- */
35
- className: string;
36
-
37
- /**
38
- * 是否可滚动
39
- */
40
- isScrollable: boolean;
41
-
42
- /**
43
- * 是否可点击
44
- */
45
- isClickable: boolean;
46
-
47
- /**
48
- * 是否启用
49
- */
50
- isEnabled: boolean;
51
-
52
- /**
53
- * 所属步骤ID
54
- */
55
- stepId: string | undefined;
56
-
57
- /**
58
- * 提示文本
59
- */
60
- hintText: string;
61
-
62
- /**
63
- * 是否可选择
64
- */
65
- isCheckable: boolean;
66
-
67
- /**
68
- * 是否已选中
69
- */
70
- isChecked: boolean;
71
-
72
- /**
73
- * 是否可聚焦
74
- */
75
- isFocusable: boolean;
76
-
77
- /**
78
- * 是否已聚焦
79
- */
80
- isFocused: boolean;
81
-
82
- /**
83
- * 是否可长按
84
- */
85
- isLongClickable: boolean;
86
-
87
- /**
88
- * 是否为密码字段
89
- */
90
- isPassword: boolean;
91
-
92
- /**
93
- * 是否已选中
94
- */
95
- isSelected: boolean;
96
-
97
- /**
98
- * 是否对用户可见
99
- */
100
- isVisibleToUser: boolean;
101
-
102
- /**
103
- * 绘制顺序
104
- */
105
- drawingOrder: number;
106
-
107
- /**
108
- * 节点在屏幕中的边界
109
- */
110
- boundsInScreen: Bounds;
111
-
112
- /**
113
- * 构造函数
114
- * @param params 节点参数对象
115
- */
116
- constructor(params: {
12
+ /**
13
+ * 节点唯一标识
14
+ */
117
15
  nodeId: string;
16
+
17
+ /**
18
+ * 节点文本内容
19
+ */
118
20
  text: string;
21
+
22
+ /**
23
+ * 节点描述信息
24
+ */
119
25
  des: string;
26
+
27
+ /**
28
+ * 节点视图ID
29
+ */
120
30
  viewId: string;
31
+
32
+ /**
33
+ * 节点类名
34
+ */
121
35
  className: string;
36
+
37
+ /**
38
+ * 是否可滚动
39
+ */
122
40
  isScrollable: boolean;
41
+
42
+ /**
43
+ * 是否可点击
44
+ */
123
45
  isClickable: boolean;
46
+
47
+ /**
48
+ * 是否启用
49
+ */
124
50
  isEnabled: boolean;
51
+
52
+ /**
53
+ * 所属步骤ID
54
+ */
125
55
  stepId: string | undefined;
56
+
57
+ /**
58
+ * 提示文本
59
+ */
126
60
  hintText: string;
61
+
62
+ /**
63
+ * 是否可选择
64
+ */
127
65
  isCheckable: boolean;
66
+
67
+ /**
68
+ * 是否已选中
69
+ */
128
70
  isChecked: boolean;
71
+
72
+ /**
73
+ * 是否可聚焦
74
+ */
129
75
  isFocusable: boolean;
76
+
77
+ /**
78
+ * 是否已聚焦
79
+ */
130
80
  isFocused: boolean;
81
+
82
+ /**
83
+ * 是否可长按
84
+ */
131
85
  isLongClickable: boolean;
86
+
87
+ /**
88
+ * 是否为密码字段
89
+ */
132
90
  isPassword: boolean;
91
+
92
+ /**
93
+ * 是否已选中
94
+ */
133
95
  isSelected: boolean;
96
+
97
+ /**
98
+ * 是否对用户可见
99
+ */
134
100
  isVisibleToUser: boolean;
101
+
102
+ /**
103
+ * 绘制顺序
104
+ */
135
105
  drawingOrder: number;
106
+
107
+ /**
108
+ * 节点在屏幕中的边界
109
+ */
136
110
  boundsInScreen: Bounds;
137
- }) {
138
- this.nodeId = params.nodeId;
139
- this.text = params.text;
140
- this.des = params.des;
141
- this.viewId = params.viewId;
142
- this.className = params.className;
143
- this.isScrollable = params.isScrollable;
144
- this.isClickable = params.isClickable;
145
- this.isEnabled = params.isEnabled;
146
- this.stepId = params.stepId;
147
- this.hintText = params.hintText;
148
- this.isCheckable = params.isCheckable;
149
- this.isChecked = params.isChecked;
150
- this.isFocusable = params.isFocusable;
151
- this.isFocused = params.isFocused;
152
- this.isLongClickable = params.isLongClickable;
153
- this.isPassword = params.isPassword;
154
- this.isSelected = params.isSelected;
155
- this.isVisibleToUser = params.isVisibleToUser;
156
- this.drawingOrder = params.drawingOrder;
157
- this.boundsInScreen = params.boundsInScreen;
158
- }
159
-
160
- public get async(): NodeAsync {
161
- return new NodeAsync(this);
162
- }
163
-
164
- /**
165
- * 查找第一个匹配标签的父节点
166
- * @param className 类名
167
- * @returns 父节点
168
- */
169
- public findFirstParentByTags(className: string): Node {
170
- Step.assert(this.stepId);
171
- const node = AssistsX.findFirstParentByTags(this, className);
172
- Step.assert(this.stepId);
173
- return node;
174
- }
175
-
176
- /**
177
- * 对节点执行点击手势
178
- * @param offsetX X轴偏移
179
- * @param offsetY Y轴偏移
180
- * @param switchWindowIntervalDelay 窗口切换延迟
181
- * @param clickDuration 点击持续时间
182
- * @returns 是否点击成功
183
- */
184
- public async clickNodeByGesture({
185
- offsetX,
186
- offsetY,
187
- switchWindowIntervalDelay,
188
- clickDuration,
189
- }: {
190
- offsetX?: number;
191
- offsetY?: number;
192
- switchWindowIntervalDelay?: number;
193
- clickDuration?: number;
194
- } = {}): Promise<boolean> {
195
- Step.assert(this.stepId);
196
- const result = await AssistsX.clickNodeByGesture(this, {
197
- offsetX,
198
- offsetY,
199
- switchWindowIntervalDelay,
200
- clickDuration,
201
- });
202
- Step.assert(this.stepId);
203
- return result;
204
- }
205
- /**
206
- * 对节点执行双击手势
207
- * @param offsetX X轴偏移
208
- * @param offsetY Y轴偏移
209
- * @param switchWindowIntervalDelay 窗口切换延迟
210
- * @param clickDuration 点击持续时间
211
- * @param clickInterval 点击间隔
212
- * @returns 是否双击成功
213
- */
214
- public async doubleClickNodeByGesture({
215
- offsetX,
216
- offsetY,
217
- switchWindowIntervalDelay,
218
- clickDuration,
219
- clickInterval,
220
- }: {
221
- offsetX?: number;
222
- offsetY?: number;
223
- switchWindowIntervalDelay?: number;
224
- clickDuration?: number;
225
- clickInterval?: number;
226
- } = {}): Promise<boolean> {
227
- Step.assert(this.stepId);
228
- const result = await AssistsX.doubleClickNodeByGesture(this, {
229
- offsetX,
230
- offsetY,
231
- switchWindowIntervalDelay,
232
- clickDuration,
233
- clickInterval,
234
- });
235
- Step.assert(this.stepId);
236
- return result;
237
- }
238
-
239
- public async longPressNodeByGestureAutoPaste(
240
- text: string,
241
- {
242
- matchedPackageName,
243
- matchedText,
244
- timeoutMillis,
245
- longPressDuration,
111
+
112
+ /**
113
+ * 构造函数
114
+ * @param params 节点参数对象
115
+ */
116
+ constructor(params: {
117
+ nodeId: string;
118
+ text: string;
119
+ des: string;
120
+ viewId: string;
121
+ className: string;
122
+ isScrollable: boolean;
123
+ isClickable: boolean;
124
+ isEnabled: boolean;
125
+ stepId: string | undefined;
126
+ hintText: string;
127
+ isCheckable: boolean;
128
+ isChecked: boolean;
129
+ isFocusable: boolean;
130
+ isFocused: boolean;
131
+ isLongClickable: boolean;
132
+ isPassword: boolean;
133
+ isSelected: boolean;
134
+ isVisibleToUser: boolean;
135
+ drawingOrder: number;
136
+ boundsInScreen: Bounds | any;
137
+ }) {
138
+ this.nodeId = params.nodeId;
139
+ this.text = params.text;
140
+ this.des = params.des;
141
+ this.viewId = params.viewId;
142
+ this.className = params.className;
143
+ this.isScrollable = params.isScrollable;
144
+ this.isClickable = params.isClickable;
145
+ this.isEnabled = params.isEnabled;
146
+ this.stepId = params.stepId;
147
+ this.hintText = params.hintText;
148
+ this.isCheckable = params.isCheckable;
149
+ this.isChecked = params.isChecked;
150
+ this.isFocusable = params.isFocusable;
151
+ this.isFocused = params.isFocused;
152
+ this.isLongClickable = params.isLongClickable;
153
+ this.isPassword = params.isPassword;
154
+ this.isSelected = params.isSelected;
155
+ this.isVisibleToUser = params.isVisibleToUser;
156
+ this.drawingOrder = params.drawingOrder;
157
+ // 确保 boundsInScreen 是 Bounds 实例,如果不是则转换
158
+ this.boundsInScreen = params.boundsInScreen instanceof Bounds
159
+ ? params.boundsInScreen
160
+ : Bounds.fromData(params.boundsInScreen);
161
+ }
162
+
163
+ public get async(): NodeAsync {
164
+ return new NodeAsync(this);
165
+ }
166
+
167
+ /**
168
+ * 查找第一个匹配标签的父节点
169
+ * @param className 类名
170
+ * @returns 父节点
171
+ */
172
+ public findFirstParentByTags(className: string): Node {
173
+ Step.assert(this.stepId);
174
+ const node = AssistsX.findFirstParentByTags(this, className);
175
+ Step.assert(this.stepId);
176
+ return node;
177
+ }
178
+
179
+ /**
180
+ * 对节点执行点击手势
181
+ * @param offsetX X轴偏移
182
+ * @param offsetY Y轴偏移
183
+ * @param switchWindowIntervalDelay 窗口切换延迟
184
+ * @param clickDuration 点击持续时间
185
+ * @returns 是否点击成功
186
+ */
187
+ public async clickNodeByGesture({
188
+ offsetX,
189
+ offsetY,
190
+ switchWindowIntervalDelay,
191
+ clickDuration,
246
192
  }: {
247
- matchedPackageName?: string;
248
- matchedText?: string;
249
- timeoutMillis?: number;
250
- longPressDuration?: number;
251
- } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
252
- ): Promise<boolean> {
253
- Step.assert(this.stepId);
254
- const result = await AssistsX.longPressNodeByGestureAutoPaste(this, text, {
255
- matchedPackageName,
256
- matchedText,
257
- timeoutMillis,
258
- longPressDuration,
259
- });
260
- Step.assert(this.stepId);
261
- return result;
262
- }
263
-
264
- /**
265
- * 在当前节点范围内通过标签查找节点
266
- * @param className 类名
267
- * @param filterText 文本过滤
268
- * @param filterViewId 视图ID过滤
269
- * @param filterDes 描述过滤
270
- * @returns 节点数组
271
- */
272
- public findByTags(
273
- className: string,
274
- {
275
- filterText,
276
- filterViewId,
277
- filterDes,
278
- }: { filterText?: string; filterViewId?: string; filterDes?: string } = {}
279
- ): Node[] {
280
- Step.assert(this.stepId);
281
- const result = AssistsX.findByTags(className, {
282
- filterText,
283
- filterViewId,
284
- filterDes,
285
- node: this,
286
- });
287
- Step.assignIdsToNodes(result, this.stepId);
288
- Step.assert(this.stepId);
289
- return result;
290
- }
291
- /**
292
- * 在当前节点范围内通过ID查找节点
293
- * @param id 节点ID
294
- * @param filterClass 类名过滤
295
- * @param filterText 文本过滤
296
- * @param filterDes 描述过滤
297
- * @returns 节点数组
298
- */
299
- public findById(
300
- id: string,
301
- {
302
- filterClass,
303
- filterText,
304
- filterDes,
305
- }: { filterClass?: string; filterText?: string; filterDes?: string } = {}
306
- ): Node[] {
307
- Step.assert(this.stepId);
308
- const result = AssistsX.findById(id, {
309
- filterClass,
310
- filterText,
311
- filterDes,
312
- node: this,
313
- });
314
- Step.assignIdsToNodes(result, this.stepId);
315
- Step.assert(this.stepId);
316
- return result;
317
- }
318
- /**
319
- * 在当前节点范围内通过文本查找节点
320
- * @param text 要查找的文本
321
- * @param filterClass 类名过滤
322
- * @param filterViewId 视图ID过滤
323
- * @param filterDes 描述过滤
324
- * @returns 节点数组
325
- */
326
- public findByText(
327
- text: string,
328
- {
329
- filterClass,
330
- filterViewId,
331
- filterDes,
332
- }: { filterClass?: string; filterViewId?: string; filterDes?: string } = {}
333
- ): Node[] {
334
- Step.assert(this.stepId);
335
- const result = AssistsX.findByText(text, {
336
- filterClass,
337
- filterViewId,
338
- filterDes,
339
- node: this,
340
- });
341
- Step.assignIdsToNodes(result, this.stepId);
342
- Step.assert(this.stepId);
343
- return result;
344
- }
345
-
346
- /**
347
- * 向前滚动节点
348
- * @returns 是否滚动成功
349
- */
350
- public scrollForward(): boolean {
351
- Step.assert(this.stepId);
352
- const response = AssistsX.scrollForward(this);
353
- Step.assert(this.stepId);
354
- return response;
355
- }
356
-
357
- /**
358
- * 向后滚动节点
359
- * @returns 是否滚动成功
360
- */
361
- public scrollBackward(): boolean {
362
- Step.assert(this.stepId);
363
- const response = AssistsX.scrollBackward(this);
364
- Step.assert(this.stepId);
365
- return response;
366
- }
367
- /**
368
- * 检查节点是否可见
369
- * @param compareNode 比较节点
370
- * @param isFullyByCompareNode 是否完全可见
371
- * @returns 是否可见
372
- */
373
- public isVisible({
374
- compareNode,
375
- isFullyByCompareNode,
376
- }: { compareNode?: Node; isFullyByCompareNode?: boolean } = {}): boolean {
377
- Step.assert(this.stepId);
378
- const response = AssistsX.isVisible(this, {
379
- compareNode,
380
- isFullyByCompareNode,
381
- });
382
- Step.assert(this.stepId);
383
- return response;
384
- }
385
- /**
386
- * 对节点进行截图
387
- * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
388
- * @returns 截图路径
389
- */
390
- public async takeScreenshot(
391
- overlayHiddenScreenshotDelayMillis: number = 250
392
- ): Promise<string> {
393
- Step.assert(this.stepId);
394
- const result = await AssistsX.takeScreenshotNodes(
395
- [this],
396
- overlayHiddenScreenshotDelayMillis
397
- );
398
- Step.assert(this.stepId);
399
- return result[0];
400
- }
401
- /**
402
- * 设置节点文本
403
- * @param text 要设置的文本
404
- * @returns 是否设置成功
405
- */
406
- public setNodeText(text: string): boolean {
407
- Step.assert(this.stepId);
408
- const result = AssistsX.setNodeText(this, text);
409
- Step.assert(this.stepId);
410
- return result;
411
- }
412
- public paste(text: string): boolean {
413
- Step.assert(this.stepId);
414
- const result = AssistsX.paste(this, text);
415
- Step.assert(this.stepId);
416
- return result;
417
- }
418
- public focus(): boolean {
419
- Step.assert(this.stepId);
420
- const result = AssistsX.focus(this);
421
- Step.assert(this.stepId);
422
- return result;
423
- }
424
-
425
- /**
426
- * 点击节点
427
- * @returns 是否点击成功
428
- */
429
- public click(): boolean {
430
- Step.assert(this.stepId);
431
- const result = AssistsX.click(this);
432
- Step.assert(this.stepId);
433
- return result;
434
- }
435
- /**
436
- * 长按节点
437
- * @returns 是否长按成功
438
- */
439
- public longClick(): boolean {
440
- Step.assert(this.stepId);
441
- const result = AssistsX.longClick(this);
442
- Step.assert(this.stepId);
443
- return result;
444
- }
445
- /**
446
- * 查找第一个可点击的父节点
447
- * @returns 可点击的父节点
448
- */
449
- public findFirstParentClickable(): Node {
450
- Step.assert(this.stepId);
451
- const result = AssistsX.findFirstParentClickable(this);
452
- Step.assert(this.stepId);
453
- Step.assignIdsToNodes([result], this.stepId);
454
- return result;
455
- }
456
- /**
457
- * 获取节点在屏幕中的边界
458
- * @returns 边界对象
459
- */
460
- public getBoundsInScreen(): Bounds {
461
- Step.assert(this.stepId);
462
- const result = AssistsX.getBoundsInScreen(this);
463
- Step.assert(this.stepId);
464
- return result;
465
- }
466
- /**
467
- * 获取节点的所有子节点
468
- * @returns 子节点数组
469
- */
470
- public getNodes(): Node[] {
471
- Step.assert(this.stepId);
472
- const result = AssistsX.getNodes(this);
473
- Step.assert(this.stepId);
474
- Step.assignIdsToNodes(result, this.stepId);
475
- return result;
476
- }
477
- /**
478
- * 获取节点的直接子节点
479
- * @returns 子节点数组
480
- */
481
- public getChildren(): Node[] {
482
- Step.assert(this.stepId);
483
- const result = AssistsX.getChildren(this);
484
- Step.assert(this.stepId);
485
- Step.assignIdsToNodes(result, this.stepId);
486
- return result;
487
- }
488
-
489
- /**
490
- * 从JSON字符串创建节点实例
491
- * @param json JSON字符串
492
- * @returns 节点实例
493
- */
494
- static fromJSON(json: string): Node {
495
- const data = JSON.parse(json);
496
- return new Node(data);
497
- }
498
-
499
- /**
500
- * 从普通对象创建节点实例
501
- * @param data 对象数据
502
- * @returns 节点实例
503
- */
504
- static from(data: any): Node {
505
- return new Node(data);
506
- }
507
-
508
- /**
509
- * JSON.parse的reviver函数,用于将解析的JSON对象转换为Node实例
510
- * @param key 属性键
511
- * @param value 属性值
512
- * @returns 转换后的值
513
- */
514
- static reviver(key: string, value: any): any {
515
- return key === "" ? new Node(value) : value;
516
- }
517
-
518
- /**
519
- * 创建新的节点实例
520
- * @param params 节点参数对象
521
- * @returns 节点实例
522
- */
523
- static create(params: {
524
- nodeId: string;
525
- text: string;
526
- des: string;
527
- viewId: string;
528
- className: string;
529
- isScrollable: boolean;
530
- isClickable: boolean;
531
- isEnabled: boolean;
532
- stepId: string | undefined;
533
- hintText: string;
534
- isCheckable: boolean;
535
- isChecked: boolean;
536
- isFocusable: boolean;
537
- isFocused: boolean;
538
- isLongClickable: boolean;
539
- isPassword: boolean;
540
- isSelected: boolean;
541
- isVisibleToUser: boolean;
542
- drawingOrder: number;
543
- boundsInScreen: Bounds;
544
- }): Node {
545
- return new Node(params);
546
- }
547
-
548
- /**
549
- * 从JSON数组创建节点数组
550
- * @param array JSON数组
551
- * @returns 节点数组
552
- */
553
- static fromJSONArray(array: Array<any>): Node[] {
554
- return array.map((data) => new Node(data));
555
- }
193
+ offsetX?: number;
194
+ offsetY?: number;
195
+ switchWindowIntervalDelay?: number;
196
+ clickDuration?: number;
197
+ } = {}): Promise<boolean> {
198
+ Step.assert(this.stepId);
199
+ const result = await AssistsX.clickNodeByGesture(this, {
200
+ offsetX,
201
+ offsetY,
202
+ switchWindowIntervalDelay,
203
+ clickDuration,
204
+ });
205
+ Step.assert(this.stepId);
206
+ return result;
207
+ }
208
+ /**
209
+ * 对节点执行双击手势
210
+ * @param offsetX X轴偏移
211
+ * @param offsetY Y轴偏移
212
+ * @param switchWindowIntervalDelay 窗口切换延迟
213
+ * @param clickDuration 点击持续时间
214
+ * @param clickInterval 点击间隔
215
+ * @returns 是否双击成功
216
+ */
217
+ public async doubleClickNodeByGesture({
218
+ offsetX,
219
+ offsetY,
220
+ switchWindowIntervalDelay,
221
+ clickDuration,
222
+ clickInterval,
223
+ }: {
224
+ offsetX?: number;
225
+ offsetY?: number;
226
+ switchWindowIntervalDelay?: number;
227
+ clickDuration?: number;
228
+ clickInterval?: number;
229
+ } = {}): Promise<boolean> {
230
+ Step.assert(this.stepId);
231
+ const result = await AssistsX.doubleClickNodeByGesture(this, {
232
+ offsetX,
233
+ offsetY,
234
+ switchWindowIntervalDelay,
235
+ clickDuration,
236
+ clickInterval,
237
+ });
238
+ Step.assert(this.stepId);
239
+ return result;
240
+ }
241
+
242
+ public async longPressNodeByGestureAutoPaste(
243
+ text: string,
244
+ {
245
+ matchedPackageName,
246
+ matchedText,
247
+ timeoutMillis,
248
+ longPressDuration,
249
+ }: {
250
+ matchedPackageName?: string;
251
+ matchedText?: string;
252
+ timeoutMillis?: number;
253
+ longPressDuration?: number;
254
+ } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
255
+ ): Promise<boolean> {
256
+ Step.assert(this.stepId);
257
+ const result = await AssistsX.longPressNodeByGestureAutoPaste(this, text, {
258
+ matchedPackageName,
259
+ matchedText,
260
+ timeoutMillis,
261
+ longPressDuration,
262
+ });
263
+ Step.assert(this.stepId);
264
+ return result;
265
+ }
266
+
267
+ /**
268
+ * 在当前节点范围内通过标签查找节点
269
+ * @param className 类名
270
+ * @param filterText 文本过滤
271
+ * @param filterViewId 视图ID过滤
272
+ * @param filterDes 描述过滤
273
+ * @returns 节点数组
274
+ */
275
+ public findByTags(
276
+ className: string,
277
+ {
278
+ filterText,
279
+ filterViewId,
280
+ filterDes,
281
+ }: { filterText?: string; filterViewId?: string; filterDes?: string } = {}
282
+ ): Node[] {
283
+ Step.assert(this.stepId);
284
+ const result = AssistsX.findByTags(className, {
285
+ filterText,
286
+ filterViewId,
287
+ filterDes,
288
+ node: this,
289
+ });
290
+ Step.assignIdsToNodes(result, this.stepId);
291
+ Step.assert(this.stepId);
292
+ return result;
293
+ }
294
+ /**
295
+ * 在当前节点范围内通过ID查找节点
296
+ * @param id 节点ID
297
+ * @param filterClass 类名过滤
298
+ * @param filterText 文本过滤
299
+ * @param filterDes 描述过滤
300
+ * @returns 节点数组
301
+ */
302
+ public findById(
303
+ id: string,
304
+ {
305
+ filterClass,
306
+ filterText,
307
+ filterDes,
308
+ }: { filterClass?: string; filterText?: string; filterDes?: string } = {}
309
+ ): Node[] {
310
+ Step.assert(this.stepId);
311
+ const result = AssistsX.findById(id, {
312
+ filterClass,
313
+ filterText,
314
+ filterDes,
315
+ node: this,
316
+ });
317
+ Step.assignIdsToNodes(result, this.stepId);
318
+ Step.assert(this.stepId);
319
+ return result;
320
+ }
321
+ /**
322
+ * 在当前节点范围内通过文本查找节点
323
+ * @param text 要查找的文本
324
+ * @param filterClass 类名过滤
325
+ * @param filterViewId 视图ID过滤
326
+ * @param filterDes 描述过滤
327
+ * @returns 节点数组
328
+ */
329
+ public findByText(
330
+ text: string,
331
+ {
332
+ filterClass,
333
+ filterViewId,
334
+ filterDes,
335
+ }: { filterClass?: string; filterViewId?: string; filterDes?: string } = {}
336
+ ): Node[] {
337
+ Step.assert(this.stepId);
338
+ const result = AssistsX.findByText(text, {
339
+ filterClass,
340
+ filterViewId,
341
+ filterDes,
342
+ node: this,
343
+ });
344
+ Step.assignIdsToNodes(result, this.stepId);
345
+ Step.assert(this.stepId);
346
+ return result;
347
+ }
348
+
349
+ /**
350
+ * 向前滚动节点
351
+ * @returns 是否滚动成功
352
+ */
353
+ public scrollForward(): boolean {
354
+ Step.assert(this.stepId);
355
+ const response = AssistsX.scrollForward(this);
356
+ Step.assert(this.stepId);
357
+ return response;
358
+ }
359
+
360
+ /**
361
+ * 向后滚动节点
362
+ * @returns 是否滚动成功
363
+ */
364
+ public scrollBackward(): boolean {
365
+ Step.assert(this.stepId);
366
+ const response = AssistsX.scrollBackward(this);
367
+ Step.assert(this.stepId);
368
+ return response;
369
+ }
370
+ /**
371
+ * 检查节点是否可见
372
+ * @param compareNode 比较节点
373
+ * @param isFullyByCompareNode 是否完全可见
374
+ * @returns 是否可见
375
+ */
376
+ public isVisible({
377
+ compareNode,
378
+ isFullyByCompareNode,
379
+ }: { compareNode?: Node; isFullyByCompareNode?: boolean } = {}): boolean {
380
+ Step.assert(this.stepId);
381
+ const response = AssistsX.isVisible(this, {
382
+ compareNode,
383
+ isFullyByCompareNode,
384
+ });
385
+ Step.assert(this.stepId);
386
+ return response;
387
+ }
388
+ /**
389
+ * 对节点进行截图
390
+ * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
391
+ * @returns 截图路径
392
+ */
393
+ public async takeScreenshot(
394
+ overlayHiddenScreenshotDelayMillis: number = 250
395
+ ): Promise<string> {
396
+ Step.assert(this.stepId);
397
+ const result = await AssistsX.takeScreenshotNodes(
398
+ [this],
399
+ overlayHiddenScreenshotDelayMillis
400
+ );
401
+ Step.assert(this.stepId);
402
+ return result[0];
403
+ }
404
+ /**
405
+ * 设置节点文本
406
+ * @param text 要设置的文本
407
+ * @returns 是否设置成功
408
+ */
409
+ public setNodeText(text: string): boolean {
410
+ Step.assert(this.stepId);
411
+ const result = AssistsX.setNodeText(this, text);
412
+ Step.assert(this.stepId);
413
+ return result;
414
+ }
415
+ public paste(text: string): boolean {
416
+ Step.assert(this.stepId);
417
+ const result = AssistsX.paste(this, text);
418
+ Step.assert(this.stepId);
419
+ return result;
420
+ }
421
+ public focus(): boolean {
422
+ Step.assert(this.stepId);
423
+ const result = AssistsX.focus(this);
424
+ Step.assert(this.stepId);
425
+ return result;
426
+ }
427
+
428
+ /**
429
+ * 点击节点
430
+ * @returns 是否点击成功
431
+ */
432
+ public click(): boolean {
433
+ Step.assert(this.stepId);
434
+ const result = AssistsX.click(this);
435
+ Step.assert(this.stepId);
436
+ return result;
437
+ }
438
+ /**
439
+ * 长按节点
440
+ * @returns 是否长按成功
441
+ */
442
+ public longClick(): boolean {
443
+ Step.assert(this.stepId);
444
+ const result = AssistsX.longClick(this);
445
+ Step.assert(this.stepId);
446
+ return result;
447
+ }
448
+ /**
449
+ * 查找第一个可点击的父节点
450
+ * @returns 可点击的父节点
451
+ */
452
+ public findFirstParentClickable(): Node {
453
+ Step.assert(this.stepId);
454
+ const result = AssistsX.findFirstParentClickable(this);
455
+ Step.assert(this.stepId);
456
+ Step.assignIdsToNodes([result], this.stepId);
457
+ return result;
458
+ }
459
+ /**
460
+ * 获取节点在屏幕中的边界
461
+ * @returns 边界对象
462
+ */
463
+ public getBoundsInScreen(): Bounds {
464
+ Step.assert(this.stepId);
465
+ const result = AssistsX.getBoundsInScreen(this);
466
+ Step.assert(this.stepId);
467
+ return result;
468
+ }
469
+ /**
470
+ * 获取节点的所有子节点
471
+ * @returns 子节点数组
472
+ */
473
+ public getNodes(): Node[] {
474
+ Step.assert(this.stepId);
475
+ const result = AssistsX.getNodes(this);
476
+ Step.assert(this.stepId);
477
+ Step.assignIdsToNodes(result, this.stepId);
478
+ return result;
479
+ }
480
+ /**
481
+ * 获取节点的直接子节点
482
+ * @returns 子节点数组
483
+ */
484
+ public getChildren(): Node[] {
485
+ Step.assert(this.stepId);
486
+ const result = AssistsX.getChildren(this);
487
+ Step.assert(this.stepId);
488
+ Step.assignIdsToNodes(result, this.stepId);
489
+ return result;
490
+ }
491
+
492
+ /**
493
+ * 从JSON字符串创建节点实例
494
+ * @param json JSON字符串
495
+ * @returns 节点实例
496
+ */
497
+ static fromJSON(json: string): Node {
498
+ const data = JSON.parse(json);
499
+ return new Node(data);
500
+ }
501
+
502
+ /**
503
+ * 从普通对象创建节点实例
504
+ * @param data 对象数据
505
+ * @returns 节点实例
506
+ */
507
+ static from(data: any): Node {
508
+ return new Node(data);
509
+ }
510
+
511
+ /**
512
+ * JSON.parse的reviver函数,用于将解析的JSON对象转换为Node实例
513
+ * @param key 属性键
514
+ * @param value 属性值
515
+ * @returns 转换后的值
516
+ */
517
+ static reviver(key: string, value: any): any {
518
+ return key === "" ? new Node(value) : value;
519
+ }
520
+
521
+ /**
522
+ * 创建新的节点实例
523
+ * @param params 节点参数对象
524
+ * @returns 节点实例
525
+ */
526
+ static create(params: {
527
+ nodeId: string;
528
+ text: string;
529
+ des: string;
530
+ viewId: string;
531
+ className: string;
532
+ isScrollable: boolean;
533
+ isClickable: boolean;
534
+ isEnabled: boolean;
535
+ stepId: string | undefined;
536
+ hintText: string;
537
+ isCheckable: boolean;
538
+ isChecked: boolean;
539
+ isFocusable: boolean;
540
+ isFocused: boolean;
541
+ isLongClickable: boolean;
542
+ isPassword: boolean;
543
+ isSelected: boolean;
544
+ isVisibleToUser: boolean;
545
+ drawingOrder: number;
546
+ boundsInScreen: Bounds;
547
+ }): Node {
548
+ return new Node(params);
549
+ }
550
+
551
+ /**
552
+ * 从JSON数组创建节点数组
553
+ * @param array JSON数组
554
+ * @returns 节点数组
555
+ */
556
+ static fromJSONArray(array: Array<any>): Node[] {
557
+ return array.map((data) => new Node(data));
558
+ }
556
559
  }