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.
- package/dist/AssistsX.d.ts +28 -16
- package/dist/AssistsX.js +144 -52
- package/dist/AssistsXAsync.d.ts +324 -0
- package/dist/AssistsXAsync.js +532 -0
- package/dist/CallMethod.d.ts +1 -0
- package/dist/CallMethod.js +1 -0
- package/dist/Node.d.ts +17 -8
- package/dist/Node.js +75 -20
- package/dist/NodeAsync.d.ts +200 -0
- package/dist/NodeAsync.js +308 -0
- package/dist/Step.d.ts +18 -20
- package/dist/Step.js +75 -44
- package/dist/StepAsync.d.ts +162 -0
- package/dist/StepAsync.js +264 -0
- package/dist/StepError.d.ts +27 -0
- package/dist/StepError.js +15 -0
- package/dist/Utils.d.ts +1 -0
- package/dist/Utils.js +12 -4
- package/dist/index.d.ts +13 -10
- package/dist/index.js +13 -10
- package/package.json +2 -2
- package/src/AssistsX.ts +815 -589
- package/src/AssistsXAsync.ts +723 -0
- package/src/CallMethod.ts +2 -1
- package/src/Node.ts +440 -323
- package/src/NodeAsync.ts +411 -0
- package/src/Step.ts +646 -490
- package/src/StepAsync.ts +365 -0
- package/src/StepError.ts +47 -0
- package/src/Utils.ts +16 -7
- package/src/global.d.ts +12 -9
- package/src/index.ts +13 -10
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AssistsX 类
|
|
3
|
+
* 提供与移动应用程序界面交互的工具类,包括节点查找、手势操作、屏幕操作等功能
|
|
4
|
+
*/
|
|
5
|
+
import { Node } from "./Node";
|
|
6
|
+
import { CallMethod } from "./CallMethod";
|
|
7
|
+
import { CallResponse } from "./CallResponse";
|
|
8
|
+
import { Bounds } from "./Bounds";
|
|
9
|
+
import { generateUUID } from "./Utils";
|
|
10
|
+
import { AssistsX, callbacks, WebFloatingWindowOptions } from "./AssistsX";
|
|
11
|
+
|
|
12
|
+
export class AssistsXAsync {
|
|
13
|
+
/**
|
|
14
|
+
* 执行异步调用
|
|
15
|
+
* @param method 方法名
|
|
16
|
+
* @param args 参数对象
|
|
17
|
+
* @returns Promise<调用响应>
|
|
18
|
+
*/
|
|
19
|
+
private static async asyncCall(
|
|
20
|
+
method: string,
|
|
21
|
+
{ args, node, nodes }: { args?: any; node?: Node; nodes?: Node[] } = {}
|
|
22
|
+
): Promise<CallResponse> {
|
|
23
|
+
const uuid = generateUUID();
|
|
24
|
+
const params = {
|
|
25
|
+
method,
|
|
26
|
+
arguments: args ? args : undefined,
|
|
27
|
+
node: node ? node : undefined,
|
|
28
|
+
nodes: nodes ? nodes : undefined,
|
|
29
|
+
callbackId: uuid,
|
|
30
|
+
};
|
|
31
|
+
const promise = new Promise((resolve) => {
|
|
32
|
+
callbacks[uuid] = (data: any) => {
|
|
33
|
+
resolve(data);
|
|
34
|
+
};
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
resolve(new CallResponse(0, null, uuid));
|
|
37
|
+
}, 10000);
|
|
38
|
+
});
|
|
39
|
+
const result = window.assistsxAsync.call(JSON.stringify(params));
|
|
40
|
+
const promiseResult = await promise;
|
|
41
|
+
if (typeof promiseResult === "string") {
|
|
42
|
+
const responseData = JSON.parse(promiseResult);
|
|
43
|
+
const response = new CallResponse(
|
|
44
|
+
responseData.code,
|
|
45
|
+
responseData.data,
|
|
46
|
+
responseData.callbackId
|
|
47
|
+
);
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
throw new Error("Call failed");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 设置悬浮窗标志
|
|
55
|
+
* @param flags 标志
|
|
56
|
+
* @returns 是否设置成功
|
|
57
|
+
*/
|
|
58
|
+
public static async setOverlayFlags(flags: number): Promise<boolean> {
|
|
59
|
+
const response = await this.asyncCall(CallMethod.setOverlayFlags, {
|
|
60
|
+
args: { flags: flags },
|
|
61
|
+
});
|
|
62
|
+
return response.getDataOrDefault(false);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 设置悬浮窗标志
|
|
66
|
+
* @param flags 标志
|
|
67
|
+
* @returns 是否设置成功
|
|
68
|
+
*/
|
|
69
|
+
public static async setOverlayFlagList(flags: number[]): Promise<boolean> {
|
|
70
|
+
const response = await this.asyncCall(CallMethod.setOverlayFlags, {
|
|
71
|
+
args: { flags: flags },
|
|
72
|
+
});
|
|
73
|
+
return response.getDataOrDefault(false);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 获取所有符合条件的节点
|
|
77
|
+
* @param filterClass 类名过滤
|
|
78
|
+
* @param filterViewId 视图ID过滤
|
|
79
|
+
* @param filterDes 描述过滤
|
|
80
|
+
* @param filterText 文本过滤
|
|
81
|
+
* @returns 节点数组
|
|
82
|
+
*/
|
|
83
|
+
public static async getAllNodes({
|
|
84
|
+
filterClass,
|
|
85
|
+
filterViewId,
|
|
86
|
+
filterDes,
|
|
87
|
+
filterText,
|
|
88
|
+
}: {
|
|
89
|
+
filterClass?: string;
|
|
90
|
+
filterViewId?: string;
|
|
91
|
+
filterDes?: string;
|
|
92
|
+
filterText?: string;
|
|
93
|
+
} = {}): Promise<Node[]> {
|
|
94
|
+
const response = await this.asyncCall(CallMethod.getAllNodes, {
|
|
95
|
+
args: { filterClass, filterViewId, filterDes, filterText },
|
|
96
|
+
});
|
|
97
|
+
return Node.fromJSONArray(response.getDataOrDefault("[]"));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 设置节点文本
|
|
102
|
+
* @param node 目标节点
|
|
103
|
+
* @param text 要设置的文本
|
|
104
|
+
* @returns 是否设置成功
|
|
105
|
+
*/
|
|
106
|
+
public static async setNodeText(node: Node, text: string): Promise<boolean> {
|
|
107
|
+
const response = await this.asyncCall(CallMethod.setNodeText, {
|
|
108
|
+
args: { text },
|
|
109
|
+
node,
|
|
110
|
+
});
|
|
111
|
+
return response.getDataOrDefault(false);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 对指定节点进行截图
|
|
116
|
+
* @param nodes 要截图的节点数组
|
|
117
|
+
* @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
|
|
118
|
+
* @returns 截图路径数组
|
|
119
|
+
*/
|
|
120
|
+
public static async takeScreenshotNodes(
|
|
121
|
+
nodes: Node[],
|
|
122
|
+
overlayHiddenScreenshotDelayMillis: number = 250
|
|
123
|
+
): Promise<string[]> {
|
|
124
|
+
const response = await this.asyncCall(CallMethod.takeScreenshot, {
|
|
125
|
+
nodes,
|
|
126
|
+
args: { overlayHiddenScreenshotDelayMillis },
|
|
127
|
+
});
|
|
128
|
+
const data = response.getDataOrDefault("");
|
|
129
|
+
return data.images;
|
|
130
|
+
}
|
|
131
|
+
public static async scanQR(): Promise<string> {
|
|
132
|
+
const response = await this.asyncCall(CallMethod.scanQR);
|
|
133
|
+
const data = response.getDataOrDefault({ value: "" });
|
|
134
|
+
return data.value;
|
|
135
|
+
}
|
|
136
|
+
public static async loadWebViewOverlay(
|
|
137
|
+
url: string,
|
|
138
|
+
options: WebFloatingWindowOptions = {}
|
|
139
|
+
): Promise<any> {
|
|
140
|
+
const {
|
|
141
|
+
initialWidth,
|
|
142
|
+
initialHeight,
|
|
143
|
+
minWidth,
|
|
144
|
+
minHeight,
|
|
145
|
+
maxWidth,
|
|
146
|
+
maxHeight,
|
|
147
|
+
initialCenter,
|
|
148
|
+
} = options;
|
|
149
|
+
const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
|
|
150
|
+
args: {
|
|
151
|
+
url,
|
|
152
|
+
initialWidth,
|
|
153
|
+
initialHeight,
|
|
154
|
+
minWidth,
|
|
155
|
+
minHeight,
|
|
156
|
+
maxWidth,
|
|
157
|
+
maxHeight,
|
|
158
|
+
initialCenter,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
const data = response.getDataOrDefault({});
|
|
162
|
+
return data;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 点击节点
|
|
167
|
+
* @param node 要点击的节点
|
|
168
|
+
* @returns 是否点击成功
|
|
169
|
+
*/
|
|
170
|
+
public static async click(node: Node): Promise<boolean> {
|
|
171
|
+
const response = await this.asyncCall(CallMethod.click, { node });
|
|
172
|
+
return response.getDataOrDefault(false);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 长按节点
|
|
177
|
+
* @param node 要长按的节点
|
|
178
|
+
* @returns 是否长按成功
|
|
179
|
+
*/
|
|
180
|
+
public static async longClick(node: Node): Promise<boolean> {
|
|
181
|
+
const response = await this.asyncCall(CallMethod.longClick, { node });
|
|
182
|
+
return response.getDataOrDefault(false);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 启动应用
|
|
187
|
+
* @param packageName 应用包名
|
|
188
|
+
* @returns 是否启动成功
|
|
189
|
+
*/
|
|
190
|
+
public static async launchApp(packageName: string): Promise<boolean> {
|
|
191
|
+
const response = await this.asyncCall(CallMethod.launchApp, {
|
|
192
|
+
args: { packageName },
|
|
193
|
+
});
|
|
194
|
+
return response.getDataOrDefault(false);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 获取当前应用包名
|
|
199
|
+
* @returns 包名
|
|
200
|
+
*/
|
|
201
|
+
public static async getPackageName(): Promise<string> {
|
|
202
|
+
const response = await this.asyncCall(CallMethod.getPackageName);
|
|
203
|
+
return response.getDataOrDefault("");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 显示悬浮提示
|
|
208
|
+
* @param text 提示文本
|
|
209
|
+
* @param delay 显示时长(毫秒)
|
|
210
|
+
* @returns 是否显示成功
|
|
211
|
+
*/
|
|
212
|
+
public static async overlayToast(
|
|
213
|
+
text: string,
|
|
214
|
+
delay: number = 2000
|
|
215
|
+
): Promise<boolean> {
|
|
216
|
+
const response = await this.asyncCall(CallMethod.overlayToast, {
|
|
217
|
+
args: { text, delay },
|
|
218
|
+
});
|
|
219
|
+
return response.getDataOrDefault(false);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 通过ID查找节点
|
|
224
|
+
* @param id 节点ID
|
|
225
|
+
* @param filterClass 类名过滤
|
|
226
|
+
* @param filterText 文本过滤
|
|
227
|
+
* @param filterDes 描述过滤
|
|
228
|
+
* @param node 父节点范围
|
|
229
|
+
* @returns 节点数组
|
|
230
|
+
*/
|
|
231
|
+
public static async findById(
|
|
232
|
+
id: string,
|
|
233
|
+
{
|
|
234
|
+
filterClass,
|
|
235
|
+
filterText,
|
|
236
|
+
filterDes,
|
|
237
|
+
node,
|
|
238
|
+
}: {
|
|
239
|
+
filterClass?: string;
|
|
240
|
+
filterText?: string;
|
|
241
|
+
filterDes?: string;
|
|
242
|
+
node?: Node;
|
|
243
|
+
} = {}
|
|
244
|
+
): Promise<Node[]> {
|
|
245
|
+
const response = await this.asyncCall(CallMethod.findById, {
|
|
246
|
+
args: { id, filterClass, filterText, filterDes },
|
|
247
|
+
node,
|
|
248
|
+
});
|
|
249
|
+
return Node.fromJSONArray(response.getDataOrDefault("[]"));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 通过文本查找节点
|
|
254
|
+
* @param text 要查找的文本
|
|
255
|
+
* @param filterClass 类名过滤
|
|
256
|
+
* @param filterViewId 视图ID过滤
|
|
257
|
+
* @param filterDes 描述过滤
|
|
258
|
+
* @param node 父节点范围
|
|
259
|
+
* @returns 节点数组
|
|
260
|
+
*/
|
|
261
|
+
public static async findByText(
|
|
262
|
+
text: string,
|
|
263
|
+
{
|
|
264
|
+
filterClass,
|
|
265
|
+
filterViewId,
|
|
266
|
+
filterDes,
|
|
267
|
+
node,
|
|
268
|
+
}: {
|
|
269
|
+
filterClass?: string;
|
|
270
|
+
filterViewId?: string;
|
|
271
|
+
filterDes?: string;
|
|
272
|
+
node?: Node;
|
|
273
|
+
} = {}
|
|
274
|
+
): Promise<Node[]> {
|
|
275
|
+
const response = await this.asyncCall(CallMethod.findByText, {
|
|
276
|
+
args: { text, filterClass, filterViewId, filterDes },
|
|
277
|
+
node,
|
|
278
|
+
});
|
|
279
|
+
return Node.fromJSONArray(response.getDataOrDefault("[]"));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 通过标签查找节点
|
|
284
|
+
* @param className 类名
|
|
285
|
+
* @param filterText 文本过滤
|
|
286
|
+
* @param filterViewId 视图ID过滤
|
|
287
|
+
* @param filterDes 描述过滤
|
|
288
|
+
* @param node 父节点范围
|
|
289
|
+
* @returns 节点数组
|
|
290
|
+
*/
|
|
291
|
+
public static async findByTags(
|
|
292
|
+
className: string,
|
|
293
|
+
{
|
|
294
|
+
filterText,
|
|
295
|
+
filterViewId,
|
|
296
|
+
filterDes,
|
|
297
|
+
node,
|
|
298
|
+
}: {
|
|
299
|
+
filterText?: string;
|
|
300
|
+
filterViewId?: string;
|
|
301
|
+
filterDes?: string;
|
|
302
|
+
node?: Node;
|
|
303
|
+
} = {}
|
|
304
|
+
): Promise<Node[]> {
|
|
305
|
+
const response = await this.asyncCall(CallMethod.findByTags, {
|
|
306
|
+
args: { className, filterText, filterViewId, filterDes },
|
|
307
|
+
node,
|
|
308
|
+
});
|
|
309
|
+
return Node.fromJSONArray(response.getDataOrDefault("[]"));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 查找所有匹配文本的节点
|
|
314
|
+
* @param text 要查找的文本
|
|
315
|
+
* @returns 节点数组
|
|
316
|
+
*/
|
|
317
|
+
public static async findByTextAllMatch(text: string): Promise<Node[]> {
|
|
318
|
+
const response = await this.asyncCall(CallMethod.findByTextAllMatch, {
|
|
319
|
+
args: { text },
|
|
320
|
+
});
|
|
321
|
+
return Node.fromJSONArray(response.getDataOrDefault("[]"));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 检查是否包含指定文本
|
|
326
|
+
* @param text 要检查的文本
|
|
327
|
+
* @returns 是否包含
|
|
328
|
+
*/
|
|
329
|
+
public static async containsText(text: string): Promise<boolean> {
|
|
330
|
+
const response = await this.asyncCall(CallMethod.containsText, {
|
|
331
|
+
args: { text },
|
|
332
|
+
});
|
|
333
|
+
return response.getDataOrDefault(false);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 获取所有文本
|
|
338
|
+
* @returns 文本数组
|
|
339
|
+
*/
|
|
340
|
+
public static async getAllText(): Promise<string[]> {
|
|
341
|
+
const response = await this.asyncCall(CallMethod.getAllText);
|
|
342
|
+
return response.getDataOrDefault("[]");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 查找第一个匹配标签的父节点
|
|
347
|
+
* @param className 类名
|
|
348
|
+
* @returns 父节点
|
|
349
|
+
*/
|
|
350
|
+
public static async findFirstParentByTags(
|
|
351
|
+
node: Node,
|
|
352
|
+
className: string
|
|
353
|
+
): Promise<Node> {
|
|
354
|
+
const response = await this.asyncCall(CallMethod.findFirstParentByTags, {
|
|
355
|
+
args: { className },
|
|
356
|
+
node,
|
|
357
|
+
});
|
|
358
|
+
return Node.create(response.getDataOrDefault("{}"));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 获取节点的所有子节点
|
|
363
|
+
* @param node 父节点
|
|
364
|
+
* @returns 子节点数组
|
|
365
|
+
*/
|
|
366
|
+
public static async getNodes(node: Node): Promise<Node[]> {
|
|
367
|
+
const response = await this.asyncCall(CallMethod.getNodes, { node });
|
|
368
|
+
return Node.fromJSONArray(response.getDataOrDefault("[]"));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 获取节点的直接子节点
|
|
373
|
+
* @param node 父节点
|
|
374
|
+
* @returns 子节点数组
|
|
375
|
+
*/
|
|
376
|
+
public static async getChildren(node: Node): Promise<Node[]> {
|
|
377
|
+
const response = await this.asyncCall(CallMethod.getChildren, { node });
|
|
378
|
+
return Node.fromJSONArray(response.getDataOrDefault([]));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* 查找第一个可点击的父节点
|
|
383
|
+
* @param node 起始节点
|
|
384
|
+
* @returns 可点击的父节点
|
|
385
|
+
*/
|
|
386
|
+
public static async findFirstParentClickable(node: Node): Promise<Node> {
|
|
387
|
+
const response = await this.asyncCall(CallMethod.findFirstParentClickable, {
|
|
388
|
+
node,
|
|
389
|
+
});
|
|
390
|
+
return Node.create(response.getDataOrDefault("{}"));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* 获取节点在屏幕中的边界
|
|
395
|
+
* @param node 目标节点
|
|
396
|
+
* @returns 边界对象
|
|
397
|
+
*/
|
|
398
|
+
public static async getBoundsInScreen(node: Node): Promise<Bounds> {
|
|
399
|
+
const response = await this.asyncCall(CallMethod.getBoundsInScreen, {
|
|
400
|
+
node,
|
|
401
|
+
});
|
|
402
|
+
return Bounds.fromData(response.getDataOrDefault({}));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* 检查节点是否可见
|
|
407
|
+
* @param node 目标节点
|
|
408
|
+
* @param compareNode 比较节点
|
|
409
|
+
* @param isFullyByCompareNode 是否完全可见
|
|
410
|
+
* @returns 是否可见
|
|
411
|
+
*/
|
|
412
|
+
public static async isVisible(
|
|
413
|
+
node: Node,
|
|
414
|
+
{
|
|
415
|
+
compareNode,
|
|
416
|
+
isFullyByCompareNode,
|
|
417
|
+
}: { compareNode?: Node; isFullyByCompareNode?: boolean } = {}
|
|
418
|
+
): Promise<boolean> {
|
|
419
|
+
const response = await this.asyncCall(CallMethod.isVisible, {
|
|
420
|
+
node,
|
|
421
|
+
args: { compareNode, isFullyByCompareNode },
|
|
422
|
+
});
|
|
423
|
+
return response.getDataOrDefault(false);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* 执行点击手势
|
|
428
|
+
* @param x 横坐标
|
|
429
|
+
* @param y 纵坐标
|
|
430
|
+
* @param duration 持续时间
|
|
431
|
+
* @returns 是否成功
|
|
432
|
+
*/
|
|
433
|
+
public static async clickByGesture(
|
|
434
|
+
x: number,
|
|
435
|
+
y: number,
|
|
436
|
+
duration: number
|
|
437
|
+
): Promise<boolean> {
|
|
438
|
+
const response = await this.asyncCall(CallMethod.clickByGesture, {
|
|
439
|
+
args: { x, y, duration },
|
|
440
|
+
});
|
|
441
|
+
return response.getDataOrDefault(false);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* 返回操作
|
|
446
|
+
* @returns 是否成功
|
|
447
|
+
*/
|
|
448
|
+
public static async back(): Promise<boolean> {
|
|
449
|
+
const response = await this.asyncCall(CallMethod.back);
|
|
450
|
+
return response.getDataOrDefault(false);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* 回到主页
|
|
455
|
+
* @returns 是否成功
|
|
456
|
+
*/
|
|
457
|
+
public static async home(): Promise<boolean> {
|
|
458
|
+
const response = await this.asyncCall(CallMethod.home);
|
|
459
|
+
return response.getDataOrDefault(false);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 打开通知栏
|
|
464
|
+
* @returns 是否成功
|
|
465
|
+
*/
|
|
466
|
+
public static async notifications(): Promise<boolean> {
|
|
467
|
+
const response = await this.asyncCall(CallMethod.notifications);
|
|
468
|
+
return response.getDataOrDefault(false);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* 显示最近应用
|
|
473
|
+
* @returns 是否成功
|
|
474
|
+
*/
|
|
475
|
+
public static async recentApps(): Promise<boolean> {
|
|
476
|
+
const response = await this.asyncCall(CallMethod.recentApps);
|
|
477
|
+
return response.getDataOrDefault(false);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* 在节点中粘贴文本
|
|
482
|
+
* @param node 目标节点
|
|
483
|
+
* @param text 要粘贴的文本
|
|
484
|
+
* @returns 是否成功
|
|
485
|
+
*/
|
|
486
|
+
public static async paste(node: Node, text: string): Promise<boolean> {
|
|
487
|
+
const response = await this.asyncCall(CallMethod.paste, {
|
|
488
|
+
args: { text },
|
|
489
|
+
node,
|
|
490
|
+
});
|
|
491
|
+
return response.getDataOrDefault(false);
|
|
492
|
+
}
|
|
493
|
+
public static async focus(node: Node): Promise<boolean> {
|
|
494
|
+
const response = await this.asyncCall(CallMethod.focus, { node });
|
|
495
|
+
return response.getDataOrDefault(false);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* 选择文本
|
|
500
|
+
* @param node 目标节点
|
|
501
|
+
* @param selectionStart 选择起始位置
|
|
502
|
+
* @param selectionEnd 选择结束位置
|
|
503
|
+
* @returns 是否成功
|
|
504
|
+
*/
|
|
505
|
+
public static async selectionText(
|
|
506
|
+
node: Node,
|
|
507
|
+
selectionStart: number,
|
|
508
|
+
selectionEnd: number
|
|
509
|
+
): Promise<boolean> {
|
|
510
|
+
const response = await this.asyncCall(CallMethod.selectionText, {
|
|
511
|
+
args: { selectionStart, selectionEnd },
|
|
512
|
+
node,
|
|
513
|
+
});
|
|
514
|
+
return response.getDataOrDefault(false);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* 向前滚动
|
|
519
|
+
* @param node 可滚动节点
|
|
520
|
+
* @returns 是否成功
|
|
521
|
+
*/
|
|
522
|
+
public static async scrollForward(node: Node): Promise<boolean> {
|
|
523
|
+
const response = await this.asyncCall(CallMethod.scrollForward, {
|
|
524
|
+
node,
|
|
525
|
+
});
|
|
526
|
+
return response.getDataOrDefault(false);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* 向后滚动
|
|
531
|
+
* @param node 可滚动节点
|
|
532
|
+
* @returns 是否成功
|
|
533
|
+
*/
|
|
534
|
+
public static async scrollBackward(node: Node): Promise<boolean> {
|
|
535
|
+
const response = await this.asyncCall(CallMethod.scrollBackward, {
|
|
536
|
+
node,
|
|
537
|
+
});
|
|
538
|
+
return response.getDataOrDefault(false);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* 对节点执行点击手势
|
|
543
|
+
* @param node 目标节点
|
|
544
|
+
* @param offsetX X轴偏移
|
|
545
|
+
* @param offsetY Y轴偏移
|
|
546
|
+
* @param switchWindowIntervalDelay 窗口切换延迟
|
|
547
|
+
* @param clickDuration 点击持续时间
|
|
548
|
+
* @returns 是否成功
|
|
549
|
+
*/
|
|
550
|
+
public static async clickNodeByGesture(
|
|
551
|
+
node: Node,
|
|
552
|
+
{
|
|
553
|
+
offsetX,
|
|
554
|
+
offsetY,
|
|
555
|
+
switchWindowIntervalDelay,
|
|
556
|
+
clickDuration,
|
|
557
|
+
}: {
|
|
558
|
+
offsetX?: number;
|
|
559
|
+
offsetY?: number;
|
|
560
|
+
switchWindowIntervalDelay?: number;
|
|
561
|
+
clickDuration?: number;
|
|
562
|
+
} = {}
|
|
563
|
+
): Promise<boolean> {
|
|
564
|
+
const response = await this.asyncCall(CallMethod.clickNodeByGesture, {
|
|
565
|
+
node,
|
|
566
|
+
args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration },
|
|
567
|
+
});
|
|
568
|
+
return response.getDataOrDefault(false);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* 对节点执行双击手势
|
|
573
|
+
* @param node 目标节点
|
|
574
|
+
* @param offsetX X轴偏移
|
|
575
|
+
* @param offsetY Y轴偏移
|
|
576
|
+
* @param switchWindowIntervalDelay 窗口切换延迟
|
|
577
|
+
* @param clickDuration 点击持续时间
|
|
578
|
+
* @param clickInterval 点击间隔
|
|
579
|
+
* @returns 是否成功
|
|
580
|
+
*/
|
|
581
|
+
public static async doubleClickNodeByGesture(
|
|
582
|
+
node: Node,
|
|
583
|
+
{
|
|
584
|
+
offsetX,
|
|
585
|
+
offsetY,
|
|
586
|
+
switchWindowIntervalDelay,
|
|
587
|
+
clickDuration,
|
|
588
|
+
clickInterval,
|
|
589
|
+
}: {
|
|
590
|
+
offsetX?: number;
|
|
591
|
+
offsetY?: number;
|
|
592
|
+
switchWindowIntervalDelay?: number;
|
|
593
|
+
clickDuration?: number;
|
|
594
|
+
clickInterval?: number;
|
|
595
|
+
} = {}
|
|
596
|
+
): Promise<boolean> {
|
|
597
|
+
const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, {
|
|
598
|
+
node,
|
|
599
|
+
args: {
|
|
600
|
+
offsetX,
|
|
601
|
+
offsetY,
|
|
602
|
+
switchWindowIntervalDelay,
|
|
603
|
+
clickDuration,
|
|
604
|
+
clickInterval,
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
return response.getDataOrDefault(false);
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* 执行线型手势
|
|
611
|
+
* @param startPoint
|
|
612
|
+
* @param endPoint
|
|
613
|
+
* @param param2
|
|
614
|
+
* @returns
|
|
615
|
+
*/
|
|
616
|
+
public static async performLinearGesture(
|
|
617
|
+
startPoint: { x: number; y: number },
|
|
618
|
+
endPoint: { x: number; y: number },
|
|
619
|
+
{ duration }: { duration?: number } = {}
|
|
620
|
+
): Promise<boolean> {
|
|
621
|
+
const response = await this.asyncCall(CallMethod.performLinearGesture, {
|
|
622
|
+
args: { startPoint, endPoint, duration },
|
|
623
|
+
});
|
|
624
|
+
return response.getDataOrDefault(false);
|
|
625
|
+
}
|
|
626
|
+
public static async longPressNodeByGestureAutoPaste(
|
|
627
|
+
node: Node,
|
|
628
|
+
text: string,
|
|
629
|
+
{
|
|
630
|
+
matchedPackageName,
|
|
631
|
+
matchedText,
|
|
632
|
+
timeoutMillis,
|
|
633
|
+
longPressDuration,
|
|
634
|
+
}: {
|
|
635
|
+
matchedPackageName?: string;
|
|
636
|
+
matchedText?: string;
|
|
637
|
+
timeoutMillis?: number;
|
|
638
|
+
longPressDuration?: number;
|
|
639
|
+
} = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
|
|
640
|
+
): Promise<boolean> {
|
|
641
|
+
const response = await this.asyncCall(
|
|
642
|
+
CallMethod.longPressGestureAutoPaste,
|
|
643
|
+
{
|
|
644
|
+
node,
|
|
645
|
+
args: {
|
|
646
|
+
text,
|
|
647
|
+
matchedPackageName,
|
|
648
|
+
matchedText,
|
|
649
|
+
timeoutMillis,
|
|
650
|
+
longPressDuration,
|
|
651
|
+
},
|
|
652
|
+
}
|
|
653
|
+
);
|
|
654
|
+
return response.getDataOrDefault(false);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
public static async longPressGestureAutoPaste(
|
|
658
|
+
point: { x: number; y: number },
|
|
659
|
+
text: string,
|
|
660
|
+
{
|
|
661
|
+
matchedPackageName,
|
|
662
|
+
matchedText,
|
|
663
|
+
timeoutMillis,
|
|
664
|
+
longPressDuration,
|
|
665
|
+
}: {
|
|
666
|
+
matchedPackageName?: string;
|
|
667
|
+
matchedText?: string;
|
|
668
|
+
timeoutMillis?: number;
|
|
669
|
+
longPressDuration?: number;
|
|
670
|
+
} = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
|
|
671
|
+
): Promise<boolean> {
|
|
672
|
+
const response = await this.asyncCall(
|
|
673
|
+
CallMethod.longPressGestureAutoPaste,
|
|
674
|
+
{
|
|
675
|
+
args: {
|
|
676
|
+
point,
|
|
677
|
+
text,
|
|
678
|
+
matchedPackageName,
|
|
679
|
+
matchedText,
|
|
680
|
+
timeoutMillis,
|
|
681
|
+
longPressDuration,
|
|
682
|
+
},
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
return response.getDataOrDefault(false);
|
|
686
|
+
}
|
|
687
|
+
public static async getAppInfo(packageName: string): Promise<any> {
|
|
688
|
+
const response = await this.asyncCall(CallMethod.getAppInfo, {
|
|
689
|
+
args: { packageName },
|
|
690
|
+
});
|
|
691
|
+
return response.getDataOrDefault({});
|
|
692
|
+
}
|
|
693
|
+
public static async getUniqueDeviceId(): Promise<any> {
|
|
694
|
+
const response = await this.asyncCall(CallMethod.getUniqueDeviceId);
|
|
695
|
+
return response.getDataOrDefault("");
|
|
696
|
+
}
|
|
697
|
+
public static async getAndroidID(): Promise<any> {
|
|
698
|
+
const response = await this.asyncCall(CallMethod.getAndroidID);
|
|
699
|
+
return response.getDataOrDefault("");
|
|
700
|
+
}
|
|
701
|
+
public static async getMacAddress(): Promise<any> {
|
|
702
|
+
const response = await this.asyncCall(CallMethod.getMacAddress);
|
|
703
|
+
return response.getDataOrDefault({});
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* 获取屏幕尺寸
|
|
708
|
+
* @returns 屏幕尺寸对象
|
|
709
|
+
*/
|
|
710
|
+
public static async getScreenSize(): Promise<any> {
|
|
711
|
+
const response = await this.asyncCall(CallMethod.getScreenSize);
|
|
712
|
+
return response.getDataOrDefault("{}");
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* 获取应用窗口尺寸
|
|
717
|
+
* @returns 应用窗口尺寸对象
|
|
718
|
+
*/
|
|
719
|
+
public static async getAppScreenSize(): Promise<any> {
|
|
720
|
+
const response = await this.asyncCall(CallMethod.getAppScreenSize);
|
|
721
|
+
return response.getDataOrDefault("{}");
|
|
722
|
+
}
|
|
723
|
+
}
|