automation_model 1.0.5 → 1.0.7

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.
@@ -9,47 +9,52 @@ class StableBrowser {
9
9
  timeout: 60000,
10
10
  });
11
11
  }
12
+ async _fixLocator(locator) {
13
+ let count = await locator.count();
14
+ if (count > 1) {
15
+ return locator.nth(0);
16
+ }
17
+ return locator;
18
+ }
12
19
  async _locate(selector, scope) {
13
- if (typeof selector === "object") {
14
- try {
15
- if (Array.isArray(selector)) {
16
- let currentScope = scope;
20
+ try {
21
+ if (Array.isArray(selector)) {
22
+ let currentScope = scope;
17
23
 
18
- for (let i = 0; i < selector.length; i++) {
19
- currentScope = await this._locate(
20
- selector[i],
21
- currentScope
22
- ).first();
23
- }
24
+ for (let i = 0; i < selector.length; i++) {
25
+ currentScope = await this._fixLocator(
26
+ await this._locate(selector[i], currentScope)
27
+ );
24
28
  }
29
+ return currentScope;
30
+ }
31
+ if (typeof selector === "object") {
25
32
  if (selector.css) {
26
- return await scope.locator(selector.css).first();
33
+ return await this._fixLocator(scope.locator(selector.css));
27
34
  }
28
35
  if (selector.role) {
29
- return await scope
30
- .getByRole(selector.role[0], selector.role[1])
31
- .first();
36
+ return await this._fixLocator(
37
+ scope.getByRole(selector.role[0], selector.role[1])
38
+ );
32
39
  }
33
40
  if (selector.text) {
34
- return await scope.getByText(selector.text).first();
41
+ return await this._fixLocator(scope.getByText(selector.text));
35
42
  }
36
- throw new Error(`Unknown locator type ${type}`);
37
- } catch (e) {
38
- console.log("invalid locator object, will try to parse as text");
39
43
  }
44
+ throw new Error(`Unknown locator type ${type}`);
45
+ } catch (e) {
46
+ console.log("invalid locator object, will try to parse as text");
40
47
  }
41
48
 
42
49
  if (selector.startsWith("TEXT=")) {
43
- return await this.page
44
- .getByText(selector.substring("TEXT=".length))
45
- .first();
50
+ return await this.page.getByText(selector.substring("TEXT=".length));
46
51
  } else {
47
- return await this.page.locator(selector).first();
52
+ return await this.page.locator(selector);
48
53
  }
49
54
  }
50
55
 
51
56
  async click(selector) {
52
- (await this._locate(selector, this.page)).click();
57
+ await (await this._locate(selector, this.page)).click();
53
58
  }
54
59
  async fill(selector, value) {
55
60
  let element = await this._locate(selector, this.page);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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",