automation_model 1.0.42 → 1.0.44

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.
@@ -195,51 +195,76 @@ class StableBrowser {
195
195
  }
196
196
  let element = await this._locate(selector, info, _params);
197
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
- }
198
+ return await element.innerText();
199
+ // let textFound = await element.evaluate((_node) => {
200
+ // function isInline(element) {
201
+ // var displayStyle = window.getComputedStyle(element, null).getPropertyValue("display");
202
+ // return displayStyle === "inline" || displayStyle === "inline-block";
203
+ // }
203
204
 
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;
205
+ // function isElementVisible(element) {
206
+ // if (!element.getBoundingClientRect) {
207
+ // return true;
208
+ // }
209
+ // const rect = element.getBoundingClientRect();
210
+ // if (rect.height === 0 || rect.width === 0) {
211
+ // return false;
212
+ // }
213
+ // const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
214
+ // return !(rect.bottom < 0 || rect.top - viewHeight >= 0);
215
+ // }
216
+ // function getVisibleText(node) {
217
+ // if (!isElementVisible(node)) {
218
+ // return "";
219
+ // }
220
+ // if (node.nodeType === Node.TEXT_NODE) {
221
+ // return node.nodeValue.trim();
222
+ // }
223
+ // if (node.nodeType !== Node.ELEMENT_NODE) {
224
+ // return "";
225
+ // }
226
+ // let block = !isInline(node);
227
+ // let text = "";
228
+ // for (let child of node.childNodes) {
229
+ // text += getVisibleText(child);
230
+ // }
231
+ // if (block) {
232
+ // text += "\n";
233
+ // } else {
234
+ // text = " " + text;
235
+ // }
236
+ // return text;
237
+ // }
238
+ // return getVisibleText(_node).trim();
239
+ // });
240
+ // return textFound
241
+ // .split("\n")
242
+ // .filter((line) => line.trim() !== "")
243
+ // .join("\n");
244
+ }
245
+ async containsPattern(selector, pattern, text, _params = null, options = {}) {
246
+ const info = {};
247
+ info.log = [];
248
+ info.operation = "containsPattern";
249
+ info.selector = selector;
250
+ info.value = text;
251
+ info.pattern = pattern;
252
+ try {
253
+ let foundText = await this.getText(selector, _params, options, info);
254
+ let escapedText = text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
255
+ let pattern = pattern.replace("{text}", escapedText);
256
+ let regex = new RegExp(pattern);
257
+ if (!regex.test(foundText)) {
258
+ info.foundText = foundText;
259
+ throw new Error("element doesn't contain text " + text);
236
260
  }
237
- return getVisibleText(_node).trim();
238
- });
239
- return textFound
240
- .split("\n")
241
- .filter((line) => line.trim() !== "")
242
- .join("\n");
261
+ return info;
262
+ } catch (e) {
263
+ this.logger.error("verify element contains text failed " + JSON.stringify(info));
264
+ Object.assign(e, { info: info });
265
+ await this._screenShot(options);
266
+ throw e;
267
+ }
243
268
  }
244
269
 
245
270
  async containsText(selector, text, _params = null, options = {}) {
@@ -302,4 +327,5 @@ class StableBrowser {
302
327
  await this._screenShot(options);
303
328
  }
304
329
  }
330
+
305
331
  export { StableBrowser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
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",