automation_model 1.0.62 → 1.0.63

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/bin/auto_page.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { browserManager } from "./browser_manager.js";
2
2
  import { getContext } from "./init_browser.js";
3
-
3
+ import fs from "fs";
4
+ import path from "path";
4
5
  let context = null;
5
6
  const navigate = async (path = "") => {
6
7
  let url = null;
@@ -20,10 +21,10 @@ const _findEmptyFolder = (folder) => {
20
21
  fs.mkdirSync(folder);
21
22
  }
22
23
  let nextIndex = 1;
23
- while (fs.existsSync(path.join(folder, nextIndex))) {
24
+ while (fs.existsSync(path.join(folder, nextIndex.toString()))) {
24
25
  nextIndex++;
25
26
  }
26
- return path.join(folder, nextIndex);
27
+ return path.join(folder, nextIndex.toString());
27
28
  };
28
29
  const initContext = async (path, doNavigate = true, headless = false, world = null) => {
29
30
  if (context) {
@@ -57,5 +57,5 @@ export class StableBrowser {
57
57
  value: any;
58
58
  }>;
59
59
  waitForPageLoad(options?: {}, world?: null): Promise<void>;
60
- _reportToWorld(world: any, command: any, _params: any): void;
60
+ _reportToWorld(world: any, properties?: {}): void;
61
61
  }
@@ -192,7 +192,7 @@ class StableBrowser {
192
192
  info.log = [];
193
193
  info.operation = "click";
194
194
  info.selector = selector;
195
-
195
+ this._reportToWorld(world, { command: "click", params: _params, selector: selector });
196
196
  try {
197
197
  let element = await this._locate(selector, info, _params);
198
198
 
@@ -201,17 +201,18 @@ class StableBrowser {
201
201
  await element.click({ timeout: 5000 });
202
202
  } catch (e) {
203
203
  info.log.push("click failed, will try force click");
204
+ this._reportToWorld(world, { message: "click failed, will try force click" });
204
205
  await element.click({ timeout: 10000, force: true });
205
206
  }
207
+ this._reportToWorld(world, { result: "success", info: info });
206
208
  await this.waitForPageLoad();
207
209
  return info;
208
210
  } catch (e) {
209
211
  this.logger.error("click failed " + JSON.stringify(info));
212
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
210
213
  Object.assign(e, { info: info });
211
214
  await this._screenShot(options, world);
212
215
  throw e;
213
-
214
- this.logger.info("click failed, will try next selector");
215
216
  }
216
217
  }
217
218
 
@@ -220,7 +221,7 @@ class StableBrowser {
220
221
  info.log = [];
221
222
  info.operation = "selectOptions";
222
223
  info.selector = selector;
223
-
224
+ this._reportToWorld(world, { command: "select", values, params: _params, selector: selector });
224
225
  try {
225
226
  let element = await this._locate(selector, info, _params);
226
227
 
@@ -229,12 +230,14 @@ class StableBrowser {
229
230
  await element.selectOption(values, { timeout: 5000 });
230
231
  } catch (e) {
231
232
  info.log.push("selectOption failed, will try force");
233
+ this._reportToWorld(world, { message: "select failed, will try force select" });
232
234
  await element.selectOption(values, { timeout: 10000, force: true });
233
235
  }
234
236
  await this.waitForPageLoad();
235
237
  return info;
236
238
  } catch (e) {
237
239
  this.logger.error("selectOption failed " + JSON.stringify(info));
240
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
238
241
  Object.assign(e, { info: info });
239
242
  await this._screenShot(options, world);
240
243
  throw e;
@@ -249,6 +252,7 @@ class StableBrowser {
249
252
  info.operation = "fill";
250
253
  info.selector = selector;
251
254
  info.value = value;
255
+ this._reportToWorld(world, { command: "fill", value, enter, params: _params, selector: selector });
252
256
  try {
253
257
  let element = await this._locate(selector, info, _params);
254
258
  await this._screenShot(options, world);
@@ -261,6 +265,7 @@ class StableBrowser {
261
265
  return info;
262
266
  } catch (e) {
263
267
  this.logger.error("fill failed " + JSON.stringify(info));
268
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
264
269
  Object.assign(e, { info: info });
265
270
  await this._screenShot(options, world);
266
271
  throw e;
@@ -288,6 +293,7 @@ class StableBrowser {
288
293
  info.value = text;
289
294
  info.pattern = pattern;
290
295
  let foundText = null;
296
+ this._reportToWorld(world, { command: "contains", pattern, text, params: _params, selector: selector });
291
297
  try {
292
298
  foundText = await this.getText(selector, _params, options, info, world);
293
299
  let escapedText = text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
@@ -301,6 +307,7 @@ class StableBrowser {
301
307
  } catch (e) {
302
308
  this.logger.error("verify element contains text failed " + JSON.stringify(info));
303
309
  this.logger.error("found text " + foundText + " pattern " + pattern);
310
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
304
311
  Object.assign(e, { info: info });
305
312
  await this._screenShot(options, world);
306
313
  throw e;
@@ -322,6 +329,7 @@ class StableBrowser {
322
329
  return info;
323
330
  } catch (e) {
324
331
  this.logger.error("verify element contains text failed " + JSON.stringify(info));
332
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
325
333
  Object.assign(e, { info: info });
326
334
  await this._screenShot(options, world);
327
335
  throw e;
@@ -336,13 +344,11 @@ class StableBrowser {
336
344
  while (fs.existsSync(path.join(world.screenshotPath, nextIndex + ".png"))) {
337
345
  nextIndex++;
338
346
  }
339
- await this.page.screenshot({ path: path.join(world.screenshotPath, nextIndex + ".png") });
340
- await world.attach(
341
- { path: world.screenshotPath },
342
- {
343
- mediaType: "application/json",
344
- }
345
- );
347
+ const screenshotPath = path.join(world.screenshotPath, nextIndex + ".png");
348
+ await this.page.screenshot({ path: screenshotPath });
349
+ await world.attach(JSON.stringify({ path: screenshotPath }), {
350
+ mediaType: "application/json",
351
+ });
346
352
  } else if (options.screenshot) {
347
353
  await this.page.screenshot({ path: options.screenshotPath });
348
354
  }
@@ -353,6 +359,7 @@ class StableBrowser {
353
359
  info.log = [];
354
360
  info.operation = "verify";
355
361
  info.selector = selector;
362
+ this._reportToWorld(world, { command: "verify", params: _params, selector: selector });
356
363
  try {
357
364
  const element = await this._locate(selector, info, _params);
358
365
  await this._screenShot(options, world);
@@ -360,6 +367,7 @@ class StableBrowser {
360
367
  return info;
361
368
  } catch (e) {
362
369
  this.logger.error("verify failed " + JSON.stringify(info));
370
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
363
371
  Object.assign(e, { info: info });
364
372
  await this._screenShot(options, world);
365
373
  throw e;
@@ -375,6 +383,14 @@ class StableBrowser {
375
383
  info.query_fixed = query;
376
384
  info.operator = operator;
377
385
  info.value = value;
386
+ this._reportToWorld(world, {
387
+ command: "analyzeTable",
388
+ query,
389
+ operator,
390
+ value,
391
+ params: _params,
392
+ selector: selector,
393
+ });
378
394
  try {
379
395
  let table = await this._locate(selector, info, _params);
380
396
  await this._screenShot(options, world);
@@ -452,6 +468,7 @@ class StableBrowser {
452
468
  return info;
453
469
  } catch (e) {
454
470
  this.logger.error("analyzeTable failed " + JSON.stringify(info));
471
+ this._reportToWorld(world, { result: "failed", info: info, error: e });
455
472
  Object.assign(e, { info: info });
456
473
  await this._screenShot(options, world);
457
474
  throw e;
@@ -459,6 +476,7 @@ class StableBrowser {
459
476
  }
460
477
  async waitForPageLoad(options = {}, world = null) {
461
478
  let timeout = 10000;
479
+ this._reportToWorld(world, { command: "waitForPageLoade" });
462
480
  if (!configuration) {
463
481
  try {
464
482
  if (fs.existsSync("ai_config.json")) {
@@ -491,11 +509,11 @@ class StableBrowser {
491
509
  await new Promise((resolve) => setTimeout(resolve, 2000));
492
510
  await this._screenShot(options, world);
493
511
  }
494
- _reportToWorld(world, command, _params) {
512
+ _reportToWorld(world, properties = {}) {
495
513
  if (!world || !world.attach) {
496
514
  return;
497
515
  }
498
- world.attach({ command: command, params: _params });
516
+ world.attach(JSON.stringify(properties), { mediaType: "application/json" });
499
517
  }
500
518
  }
501
519
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "An automation infrastructure module to be use for generative AI automation projects.",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",