assistsx-js 0.1.23 → 0.1.24

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.
@@ -118,6 +118,23 @@ export declare class AssistsXAsync {
118
118
  overlayHiddenScreenshotDelayMillis?: number;
119
119
  timeout?: number;
120
120
  }): Promise<string>;
121
+ /**
122
+ * 保存截图到文件(支持多个节点)
123
+ * @param options 截图保存选项
124
+ * @param options.nodes 要截图的节点数组(可选,不提供则保存全屏截图)
125
+ * @param options.filePath 文件路径(可选,不提供则自动生成。多个节点时会自动添加索引后缀)
126
+ * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
127
+ * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
128
+ * @param options.timeout 超时时间(秒),默认30秒
129
+ * @returns 保存的文件路径数组
130
+ */
131
+ static takeScreenshotToFile(options?: {
132
+ nodes?: Node[];
133
+ filePath?: string;
134
+ format?: "PNG" | "JPEG" | "JPG" | "WEBP";
135
+ overlayHiddenScreenshotDelayMillis?: number;
136
+ timeout?: number;
137
+ }): Promise<string[]>;
121
138
  /**
122
139
  * 截图识别文本
123
140
  * @param param0 识别参数
@@ -146,6 +146,34 @@ export class AssistsXAsync {
146
146
  const data = response.getDataOrDefault({ file: "" });
147
147
  return data.file;
148
148
  }
149
+ /**
150
+ * 保存截图到文件(支持多个节点)
151
+ * @param options 截图保存选项
152
+ * @param options.nodes 要截图的节点数组(可选,不提供则保存全屏截图)
153
+ * @param options.filePath 文件路径(可选,不提供则自动生成。多个节点时会自动添加索引后缀)
154
+ * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
155
+ * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
156
+ * @param options.timeout 超时时间(秒),默认30秒
157
+ * @returns 保存的文件路径数组
158
+ */
159
+ static async takeScreenshotToFile(options = {}) {
160
+ const { nodes, filePath, format = "PNG", overlayHiddenScreenshotDelayMillis = 250, timeout, } = options;
161
+ const response = await this.asyncCall(CallMethod.takeScreenshotToFile, {
162
+ nodes,
163
+ args: {
164
+ filePath,
165
+ format,
166
+ overlayHiddenScreenshotDelayMillis,
167
+ },
168
+ timeout,
169
+ });
170
+ const data = response.getDataOrDefault({ files: [] });
171
+ if (!Array.isArray(data.files)) {
172
+ throw new Error(`AssistsXAsync.takeScreenshotToFile: Expected files array, but got ${typeof data.files}. ` +
173
+ `Value: ${JSON.stringify(data.files)}`);
174
+ }
175
+ return data.files;
176
+ }
149
177
  /**
150
178
  * 截图识别文本
151
179
  * @param param0 识别参数
@@ -1,6 +1,7 @@
1
1
  export declare const CallMethod: {
2
2
  readonly takeScreenshot: "takeScreenshot";
3
3
  readonly takeScreenshotSave: "takeScreenshotSave";
4
+ readonly takeScreenshotToFile: "takeScreenshotToFile";
4
5
  readonly overlayToast: "overlayToast";
5
6
  readonly setNodeText: "setNodeText";
6
7
  readonly findByTags: "findByTags";
@@ -2,6 +2,7 @@
2
2
  export const CallMethod = {
3
3
  takeScreenshot: "takeScreenshot",
4
4
  takeScreenshotSave: "takeScreenshotSave",
5
+ takeScreenshotToFile: "takeScreenshotToFile",
5
6
  overlayToast: "overlayToast",
6
7
  setNodeText: "setNodeText",
7
8
  findByTags: "findByTags",
package/dist/Node.d.ts CHANGED
@@ -219,6 +219,19 @@ export declare class Node {
219
219
  * @returns 截图路径
220
220
  */
221
221
  takeScreenshot(overlayHiddenScreenshotDelayMillis?: number): Promise<string>;
222
+ /**
223
+ * 保存节点截图到文件
224
+ * @param options 截图保存选项
225
+ * @param options.filePath 文件路径(可选,不提供则自动生成)
226
+ * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
227
+ * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
228
+ * @returns 保存的文件路径
229
+ */
230
+ takeScreenshotToFile(options?: {
231
+ filePath?: string;
232
+ format?: "PNG" | "JPEG" | "JPG" | "WEBP";
233
+ overlayHiddenScreenshotDelayMillis?: number;
234
+ }): Promise<string>;
222
235
  /**
223
236
  * 设置节点文本
224
237
  * @param text 要设置的文本
package/dist/Node.js CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Bounds } from "./Bounds";
6
6
  import { AssistsX } from "./AssistsX";
7
+ import { AssistsXAsync } from "./AssistsXAsync";
7
8
  import { Step } from "./Step";
8
9
  import { NodeAsync } from "./NodeAsync";
9
10
  // 将接口改造为类
@@ -208,6 +209,23 @@ export class Node {
208
209
  Step.assert(this.stepId);
209
210
  return result[0];
210
211
  }
212
+ /**
213
+ * 保存节点截图到文件
214
+ * @param options 截图保存选项
215
+ * @param options.filePath 文件路径(可选,不提供则自动生成)
216
+ * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
217
+ * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
218
+ * @returns 保存的文件路径
219
+ */
220
+ async takeScreenshotToFile(options = {}) {
221
+ Step.assert(this.stepId);
222
+ const result = await AssistsXAsync.takeScreenshotToFile({
223
+ nodes: [this],
224
+ ...options,
225
+ });
226
+ Step.assert(this.stepId);
227
+ return result[0];
228
+ }
211
229
  /**
212
230
  * 设置节点文本
213
231
  * @param text 要设置的文本
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -254,6 +254,52 @@ export class AssistsXAsync {
254
254
  return data.file;
255
255
  }
256
256
 
257
+ /**
258
+ * 保存截图到文件(支持多个节点)
259
+ * @param options 截图保存选项
260
+ * @param options.nodes 要截图的节点数组(可选,不提供则保存全屏截图)
261
+ * @param options.filePath 文件路径(可选,不提供则自动生成。多个节点时会自动添加索引后缀)
262
+ * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
263
+ * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
264
+ * @param options.timeout 超时时间(秒),默认30秒
265
+ * @returns 保存的文件路径数组
266
+ */
267
+ public static async takeScreenshotToFile(
268
+ options: {
269
+ nodes?: Node[];
270
+ filePath?: string;
271
+ format?: "PNG" | "JPEG" | "JPG" | "WEBP";
272
+ overlayHiddenScreenshotDelayMillis?: number;
273
+ timeout?: number;
274
+ } = {}
275
+ ): Promise<string[]> {
276
+ const {
277
+ nodes,
278
+ filePath,
279
+ format = "PNG",
280
+ overlayHiddenScreenshotDelayMillis = 250,
281
+ timeout,
282
+ } = options;
283
+
284
+ const response = await this.asyncCall(CallMethod.takeScreenshotToFile, {
285
+ nodes,
286
+ args: {
287
+ filePath,
288
+ format,
289
+ overlayHiddenScreenshotDelayMillis,
290
+ },
291
+ timeout,
292
+ });
293
+ const data = response.getDataOrDefault({ files: [] });
294
+ if (!Array.isArray(data.files)) {
295
+ throw new Error(
296
+ `AssistsXAsync.takeScreenshotToFile: Expected files array, but got ${typeof data.files}. ` +
297
+ `Value: ${JSON.stringify(data.files)}`
298
+ );
299
+ }
300
+ return data.files;
301
+ }
302
+
257
303
  /**
258
304
  * 截图识别文本
259
305
  * @param param0 识别参数
package/src/CallMethod.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  export const CallMethod = {
3
3
  takeScreenshot: "takeScreenshot",
4
4
  takeScreenshotSave: "takeScreenshotSave",
5
+ takeScreenshotToFile: "takeScreenshotToFile",
5
6
  overlayToast: "overlayToast",
6
7
  setNodeText: "setNodeText",
7
8
  findByTags: "findByTags",
package/src/Node.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Bounds } from "./Bounds";
6
6
  import { AssistsX } from "./AssistsX";
7
+ import { AssistsXAsync } from "./AssistsXAsync";
7
8
  import { Step } from "./Step";
8
9
  import { NodeAsync } from "./NodeAsync";
9
10
 
@@ -401,6 +402,29 @@ export class Node {
401
402
  Step.assert(this.stepId);
402
403
  return result[0];
403
404
  }
405
+ /**
406
+ * 保存节点截图到文件
407
+ * @param options 截图保存选项
408
+ * @param options.filePath 文件路径(可选,不提供则自动生成)
409
+ * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
410
+ * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
411
+ * @returns 保存的文件路径
412
+ */
413
+ public async takeScreenshotToFile(
414
+ options: {
415
+ filePath?: string;
416
+ format?: "PNG" | "JPEG" | "JPG" | "WEBP";
417
+ overlayHiddenScreenshotDelayMillis?: number;
418
+ } = {}
419
+ ): Promise<string> {
420
+ Step.assert(this.stepId);
421
+ const result = await AssistsXAsync.takeScreenshotToFile({
422
+ nodes: [this],
423
+ ...options,
424
+ });
425
+ Step.assert(this.stepId);
426
+ return result[0];
427
+ }
404
428
  /**
405
429
  * 设置节点文本
406
430
  * @param text 要设置的文本