automation_model 1.0.17 → 1.0.19

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.
@@ -15,46 +15,55 @@ class StableBrowser {
15
15
  timeout: 60000,
16
16
  });
17
17
  }
18
- async _checkUnique(locator) {
18
+ async _checkUnique(locator, info) {
19
+ info.log.push("check unique");
19
20
  let count = await locator.count();
21
+ info.log.push("count=" + count);
20
22
  if (count > 1) {
21
23
  this.logger.error("Found more than one element for locator" + JSON.stringify(locator.toString()));
22
24
  for (let i = 0; i < count; i++) {
23
25
  let loc = locator.nth(i);
24
26
  if ((await loc.isVisible()) && (await loc.isEnabled())) {
27
+ info.box = await loc.boundingBox();
25
28
  return loc;
26
29
  }
27
30
  }
28
31
  }
32
+ if (count === 1) {
33
+ info.box = await locator.boundingBox();
34
+ }
29
35
  return locator;
30
36
  }
31
- async _locate(selector, scope) {
37
+ async _locate(selector, scope, info) {
32
38
  try {
33
39
  if (Array.isArray(selector)) {
34
40
  let currentScope = scope;
35
41
 
36
42
  for (let i = 0; i < selector.length; i++) {
37
- currentScope = await this._locate(selector[i], currentScope);
43
+ currentScope = await this._locate(selector[i], currentScope, info);
38
44
  }
39
45
  return currentScope;
40
46
  }
41
47
  if (typeof selector === "object") {
48
+ info.log.push("try selector " + JSON.stringify(selector));
42
49
  if (selector.css) {
43
- return await this._checkUnique(scope.locator(selector.css));
50
+ return await this._checkUnique(scope.locator(selector.css), info);
44
51
  }
45
52
  if (selector.role) {
46
53
  if (selector.role[1].nameReg) {
47
54
  selector.role[1].name = reg_parser(selector.role[1].nameReg);
48
55
  delete selector.role[1].nameReg;
49
56
  }
50
- return await this._checkUnique(scope.getByRole(selector.role[0], selector.role[1]));
57
+ return await this._checkUnique(scope.getByRole(selector.role[0], selector.role[1]), info);
51
58
  }
52
59
  if (selector.text) {
53
- return await this._checkUnique(scope.getByText(selector.text));
60
+ return await this._checkUnique(scope.getByText(selector.text), info);
54
61
  }
55
62
  } else if (typeof selector === "string" && selector.startsWith("TEXT=")) {
63
+ info.log.push("try getByText");
56
64
  return await this.page.getByText(selector.substring("TEXT=".length));
57
65
  } else {
66
+ info.log.push("try direct css selector");
58
67
  return await this.page.locator(selector);
59
68
  }
60
69
  throw new Error(`Unknown locator type ${type}`);
@@ -64,44 +73,65 @@ class StableBrowser {
64
73
  }
65
74
 
66
75
  async click(selector) {
76
+ const info = {};
77
+ info.log = [];
78
+ info.operation = "click";
79
+ info.selector = selector;
67
80
  for (let i = 0; i < selector.length; i++) {
81
+ info.log.push("try selector " + i);
68
82
  try {
69
- await (await this._locate(selector[i], this.page)).click();
70
- return;
83
+ await (await this._locate(selector[i], this.page, info)).click({ timeout: 10000 });
84
+ return info;
71
85
  } catch (e) {
72
86
  if (i === selector.length - 1) {
87
+ this.logger.error("click failed " + JSON.stringify(info));
88
+ Object.assign(e, { info: info });
73
89
  throw e;
74
90
  }
75
- console.log("click failed, will try next selector");
91
+ this.logger.info("click failed, will try next selector");
76
92
  }
77
93
  }
78
94
  }
79
95
  async fill(selector, value) {
96
+ const info = {};
97
+ info.log = [];
98
+ info.operation = "fill";
99
+ info.selector = selector;
100
+ info.value = value;
80
101
  for (let i = 0; i < selector.length; i++) {
102
+ info.log.push("try selector " + i);
81
103
  try {
82
- let element = await this._locate(selector[i], this.page);
83
- await element.fill(value);
104
+ let element = await this._locate(selector[i], this.page, info);
105
+ await element.fill(value, { timeout: 10000 });
84
106
  await element.dispatchEvent("change");
85
- return;
107
+ return info;
86
108
  } catch (e) {
87
109
  if (i === selector.length - 1) {
110
+ this.logger.error("fill failed " + JSON.stringify(info));
111
+ Object.assign(e, { info: info });
88
112
  throw e;
89
113
  }
90
- console.log("click failed, will try next selector");
114
+ this.logger.info("click failed, will try next selector");
91
115
  }
92
116
  }
93
117
  }
94
118
  async verifyElementExistInPage(selector) {
119
+ const info = {};
120
+ info.log = [];
121
+ info.operation = "verify";
122
+ info.selector = selector;
95
123
  for (let i = 0; i < selector.length; i++) {
96
124
  try {
97
- const element = await this._locate(selector[0], this.page);
98
- await expect(element).toHaveCount(1);
99
- return;
125
+ const element = await this._locate(selector[0], this.page, info);
126
+ await expect(element).toHaveCount(1, { timeout: 10000 });
127
+ return info;
100
128
  } catch (e) {
101
129
  if (i === selector.length - 1) {
130
+ this.logger.error("verify failed " + JSON.stringify(info));
131
+ Object.assign(e, { info: info });
102
132
  throw e;
103
133
  }
104
- console.log("click failed, will try next selector");
134
+ this.logger.info("click failed, will try next selector");
105
135
  }
106
136
  }
107
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
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",