automation_model 1.0.6 → 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,29 +9,36 @@ 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
20
  try {
14
21
  if (Array.isArray(selector)) {
15
22
  let currentScope = scope;
16
23
 
17
24
  for (let i = 0; i < selector.length; i++) {
18
- currentScope = (
25
+ currentScope = await this._fixLocator(
19
26
  await this._locate(selector[i], currentScope)
20
- ).first();
27
+ );
21
28
  }
22
29
  return currentScope;
23
30
  }
24
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 (
30
- await scope.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);
41
+ return await this._fixLocator(scope.getByText(selector.text));
35
42
  }
36
43
  }
37
44
  throw new Error(`Unknown locator type ${type}`);
@@ -40,16 +47,14 @@ class StableBrowser {
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.6",
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",