automation_model 1.0.12 → 1.0.13
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/stable_browser.js +14 -11
- package/package.json +1 -1
package/bin/stable_browser.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { expect } from "@playwright/test";
|
|
2
2
|
class StableBrowser {
|
|
3
|
-
constructor(browser, page) {
|
|
3
|
+
constructor(browser, page, logger = console) {
|
|
4
4
|
this.browser = browser;
|
|
5
5
|
this.page = page;
|
|
6
|
+
this.logger = logger;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
async goto(url) {
|
|
@@ -10,10 +11,16 @@ class StableBrowser {
|
|
|
10
11
|
timeout: 60000,
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
|
-
async
|
|
14
|
+
async _checkUnique(locator) {
|
|
14
15
|
let count = await locator.count();
|
|
15
16
|
if (count > 1) {
|
|
16
|
-
|
|
17
|
+
logger.error("Found more than one element for locator", JSON.stringify(locator));
|
|
18
|
+
for (let i = 0; i < count; i++) {
|
|
19
|
+
let loc = locator.nth(i);
|
|
20
|
+
if ((await loc.isVisible()) && (await loc.isEnabled())) {
|
|
21
|
+
return loc;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
25
|
return locator;
|
|
19
26
|
}
|
|
@@ -23,23 +30,19 @@ class StableBrowser {
|
|
|
23
30
|
let currentScope = scope;
|
|
24
31
|
|
|
25
32
|
for (let i = 0; i < selector.length; i++) {
|
|
26
|
-
currentScope = await this.
|
|
27
|
-
await this._locate(selector[i], currentScope)
|
|
28
|
-
);
|
|
33
|
+
currentScope = await this._locate(selector[i], currentScope);
|
|
29
34
|
}
|
|
30
35
|
return currentScope;
|
|
31
36
|
}
|
|
32
37
|
if (typeof selector === "object") {
|
|
33
38
|
if (selector.css) {
|
|
34
|
-
return await this.
|
|
39
|
+
return await this._checkUnique(scope.locator(selector.css));
|
|
35
40
|
}
|
|
36
41
|
if (selector.role) {
|
|
37
|
-
return await this.
|
|
38
|
-
scope.getByRole(selector.role[0], selector.role[1])
|
|
39
|
-
);
|
|
42
|
+
return await this._checkUnique(scope.getByRole(selector.role[0], selector.role[1]));
|
|
40
43
|
}
|
|
41
44
|
if (selector.text) {
|
|
42
|
-
return await this.
|
|
45
|
+
return await this._checkUnique(scope.getByText(selector.text));
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
throw new Error(`Unknown locator type ${type}`);
|