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