automation_model 1.0.40 → 1.0.42
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 +55 -6
- package/package.json +1 -1
package/bin/stable_browser.js
CHANGED
|
@@ -188,6 +188,60 @@ class StableBrowser {
|
|
|
188
188
|
throw e;
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
|
+
|
|
192
|
+
async getText(selector, _params = null, options = {}, info = {}) {
|
|
193
|
+
if (!info.log) {
|
|
194
|
+
info.log = [];
|
|
195
|
+
}
|
|
196
|
+
let element = await this._locate(selector, info, _params);
|
|
197
|
+
await this._screenShot(options);
|
|
198
|
+
let textFound = await element.evaluate((_node) => {
|
|
199
|
+
function isInline(element) {
|
|
200
|
+
var displayStyle = window.getComputedStyle(element, null).getPropertyValue("display");
|
|
201
|
+
return displayStyle === "inline" || displayStyle === "inline-block";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function isElementVisible(element) {
|
|
205
|
+
if (!element.getBoundingClientRect) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const rect = element.getBoundingClientRect();
|
|
209
|
+
if (rect.height === 0 || rect.width === 0) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
|
|
213
|
+
return !(rect.bottom < 0 || rect.top - viewHeight >= 0);
|
|
214
|
+
}
|
|
215
|
+
function getVisibleText(node) {
|
|
216
|
+
if (!isElementVisible(node)) {
|
|
217
|
+
return "";
|
|
218
|
+
}
|
|
219
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
220
|
+
return node.nodeValue.trim();
|
|
221
|
+
}
|
|
222
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
223
|
+
return "";
|
|
224
|
+
}
|
|
225
|
+
let block = !isInline(node);
|
|
226
|
+
let text = "";
|
|
227
|
+
for (let child of node.childNodes) {
|
|
228
|
+
text += getVisibleText(child);
|
|
229
|
+
}
|
|
230
|
+
if (block) {
|
|
231
|
+
text += "\n";
|
|
232
|
+
} else {
|
|
233
|
+
text = " " + text;
|
|
234
|
+
}
|
|
235
|
+
return text;
|
|
236
|
+
}
|
|
237
|
+
return getVisibleText(_node).trim();
|
|
238
|
+
});
|
|
239
|
+
return textFound
|
|
240
|
+
.split("\n")
|
|
241
|
+
.filter((line) => line.trim() !== "")
|
|
242
|
+
.join("\n");
|
|
243
|
+
}
|
|
244
|
+
|
|
191
245
|
async containsText(selector, text, _params = null, options = {}) {
|
|
192
246
|
const info = {};
|
|
193
247
|
info.log = [];
|
|
@@ -195,16 +249,11 @@ class StableBrowser {
|
|
|
195
249
|
info.selector = selector;
|
|
196
250
|
info.value = text;
|
|
197
251
|
try {
|
|
198
|
-
let
|
|
199
|
-
await this._screenShot(options);
|
|
200
|
-
let foundText = await element.textContent();
|
|
252
|
+
let foundText = await this.getText(selector, _params, options, info);
|
|
201
253
|
if (!foundText.includes(text)) {
|
|
202
254
|
info.foundText = foundText;
|
|
203
255
|
throw new Error("element doesn't contain text " + text);
|
|
204
256
|
}
|
|
205
|
-
//await expect(element).toContainText(text, { timeout: 10000 });
|
|
206
|
-
//fill(value, { timeout: 10000 });
|
|
207
|
-
//await element.dispatchEvent("change");
|
|
208
257
|
return info;
|
|
209
258
|
} catch (e) {
|
|
210
259
|
this.logger.error("verify element contains text failed " + JSON.stringify(info));
|