automation_model 1.0.25 → 1.0.27
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 +26 -14
- package/package.json +1 -1
package/bin/stable_browser.js
CHANGED
|
@@ -15,28 +15,40 @@ class StableBrowser {
|
|
|
15
15
|
timeout: 60000,
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
_fixUsingParams(text, _params) {
|
|
19
|
+
if (!_params) {
|
|
20
|
+
return text;
|
|
21
|
+
}
|
|
22
|
+
for (let key in _params) {
|
|
23
|
+
text = text.replaceAll(new RegExp("{" + key + "}", "g"), _params[key]);
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
_getLocator(locator, scope, _params) {
|
|
19
28
|
if (locator.role) {
|
|
20
29
|
if (locator.role[1].nameReg) {
|
|
21
30
|
locator.role[1].name = reg_parser(locator.role[1].nameReg);
|
|
22
31
|
delete locator.role[1].nameReg;
|
|
23
32
|
}
|
|
33
|
+
if (locator.role[1].name) {
|
|
34
|
+
locator.role[1].name = this._fixUsingParams(locator.role[1].name, _params);
|
|
35
|
+
}
|
|
24
36
|
return scope.getByRole(locator.role[0], locator.role[1]);
|
|
25
37
|
}
|
|
26
38
|
if (locator.css) {
|
|
27
|
-
return scope.locator(locator.css);
|
|
39
|
+
return scope.locator(this._fixUsingParams(locator.css, _params));
|
|
28
40
|
}
|
|
29
41
|
if (locator.text) {
|
|
30
|
-
return scope.getByText(locator.text);
|
|
42
|
+
return scope.getByText(this._fixUsingParams(locator.text, _params));
|
|
31
43
|
}
|
|
32
44
|
throw new Error("unknown locator type");
|
|
33
45
|
}
|
|
34
46
|
|
|
35
|
-
async _collectLocatorInformation(locators, index, scope, foundLocators) {
|
|
47
|
+
async _collectLocatorInformation(locators, index, scope, foundLocators, _params) {
|
|
36
48
|
if (index === locators.length) {
|
|
37
49
|
return;
|
|
38
50
|
}
|
|
39
|
-
const locator = this._getLocator(locators[index], scope);
|
|
51
|
+
const locator = this._getLocator(locators[index], scope, _params);
|
|
40
52
|
let count = await locator.count();
|
|
41
53
|
let visibleCount = 0;
|
|
42
54
|
let visibleLocator = null;
|
|
@@ -51,7 +63,7 @@ class StableBrowser {
|
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
|
-
async _locate(selectors, info, timeout = 10000) {
|
|
66
|
+
async _locate(selectors, info, _params, timeout = 10000) {
|
|
55
67
|
let locatorsByPriority = [];
|
|
56
68
|
let startTime = performance.now();
|
|
57
69
|
let locatorsCount = 0;
|
|
@@ -62,10 +74,10 @@ class StableBrowser {
|
|
|
62
74
|
|
|
63
75
|
let foundLocators = [];
|
|
64
76
|
try {
|
|
65
|
-
await this._collectLocatorInformation(selectorList, 0, this.page, foundLocators);
|
|
77
|
+
await this._collectLocatorInformation(selectorList, 0, this.page, foundLocators, _params);
|
|
66
78
|
} catch (e) {
|
|
67
79
|
foundLocators = [];
|
|
68
|
-
await this._collectLocatorInformation(selectorList, 0, this.page, foundLocators);
|
|
80
|
+
await this._collectLocatorInformation(selectorList, 0, this.page, foundLocators, _params);
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
info.log.push("total elements found " + foundLocators.length);
|
|
@@ -97,14 +109,14 @@ class StableBrowser {
|
|
|
97
109
|
throw new Error("failed to locate first element no elements found, " + JSON.stringify(info));
|
|
98
110
|
}
|
|
99
111
|
|
|
100
|
-
async click(selector, options = {}) {
|
|
112
|
+
async click(selector, _params = null, options = {}) {
|
|
101
113
|
const info = {};
|
|
102
114
|
info.log = [];
|
|
103
115
|
info.operation = "click";
|
|
104
116
|
info.selector = selector;
|
|
105
117
|
|
|
106
118
|
try {
|
|
107
|
-
let element = await this._locate(selector, info);
|
|
119
|
+
let element = await this._locate(selector, info, _params);
|
|
108
120
|
|
|
109
121
|
await this._screenShot(options);
|
|
110
122
|
await element.click({ timeout: 10000 });
|
|
@@ -118,14 +130,14 @@ class StableBrowser {
|
|
|
118
130
|
this.logger.info("click failed, will try next selector");
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
|
-
async fill(selector, value, options = {}) {
|
|
133
|
+
async fill(selector, value, _params = null, options = {}) {
|
|
122
134
|
const info = {};
|
|
123
135
|
info.log = [];
|
|
124
136
|
info.operation = "fill";
|
|
125
137
|
info.selector = selector;
|
|
126
138
|
info.value = value;
|
|
127
139
|
try {
|
|
128
|
-
let element = await this._locate(selector, info);
|
|
140
|
+
let element = await this._locate(selector, info, _params);
|
|
129
141
|
await this._screenShot(options);
|
|
130
142
|
await element.fill(value, { timeout: 10000 });
|
|
131
143
|
await element.dispatchEvent("change");
|
|
@@ -142,13 +154,13 @@ class StableBrowser {
|
|
|
142
154
|
await this.page.screenshot({ path: options.screenshotPath });
|
|
143
155
|
}
|
|
144
156
|
}
|
|
145
|
-
async verifyElementExistInPage(selector, options = {}) {
|
|
157
|
+
async verifyElementExistInPage(selector, _params = null, options = {}) {
|
|
146
158
|
const info = {};
|
|
147
159
|
info.log = [];
|
|
148
160
|
info.operation = "verify";
|
|
149
161
|
info.selector = selector;
|
|
150
162
|
try {
|
|
151
|
-
const element = await this._locate(selector, info);
|
|
163
|
+
const element = await this._locate(selector, info, _params);
|
|
152
164
|
await this._screenShot(options);
|
|
153
165
|
await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
154
166
|
return info;
|