automation_model 1.0.3 → 1.0.5

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