automation_model 1.0.7 → 1.0.9
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 +4 -84
- package/package.json +2 -1
package/bin/stable_browser.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { expect } from "@playwright/test";
|
|
1
2
|
class StableBrowser {
|
|
2
3
|
constructor(browser, page) {
|
|
3
4
|
this.browser = browser;
|
|
@@ -61,90 +62,9 @@ class StableBrowser {
|
|
|
61
62
|
await element.fill(value);
|
|
62
63
|
await element.dispatchEvent("change");
|
|
63
64
|
}
|
|
64
|
-
async
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
if (!(elem instanceof Element)) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
const style = getComputedStyle(elem);
|
|
71
|
-
if (style.display === "none") return false;
|
|
72
|
-
if (style.visibility !== "visible") return false;
|
|
73
|
-
if (style.opacity < 0.1) return false;
|
|
74
|
-
if (
|
|
75
|
-
elem.offsetWidth +
|
|
76
|
-
elem.offsetHeight +
|
|
77
|
-
elem.getBoundingClientRect().height +
|
|
78
|
-
elem.getBoundingClientRect().width ===
|
|
79
|
-
0
|
|
80
|
-
) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
const elemCenter = {
|
|
84
|
-
x: elem.getBoundingClientRect().left + elem.offsetWidth / 2,
|
|
85
|
-
y: elem.getBoundingClientRect().top + elem.offsetHeight / 2,
|
|
86
|
-
};
|
|
87
|
-
if (elemCenter.x < 0) return false;
|
|
88
|
-
if (
|
|
89
|
-
elemCenter.x >
|
|
90
|
-
(document.documentElement.clientWidth || window.innerWidth)
|
|
91
|
-
)
|
|
92
|
-
return false;
|
|
93
|
-
if (elemCenter.y < 0) return false;
|
|
94
|
-
if (
|
|
95
|
-
elemCenter.y >
|
|
96
|
-
(document.documentElement.clientHeight || window.innerHeight)
|
|
97
|
-
) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
function isBackgrounElement(element) {
|
|
103
|
-
let rec = element.getBoundingClientRect();
|
|
104
|
-
let xCenter = rec.left + rec.width / 2;
|
|
105
|
-
let yCenter = rec.top + rec.height / 2;
|
|
106
|
-
let elementAtPoint = document.elementFromPoint(xCenter, yCenter);
|
|
107
|
-
if (!elementAtPoint) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (elementAtPoint.contains(element)) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
// check if the element is the same element or same as parent
|
|
114
|
-
let toCheck = elementAtPoint;
|
|
115
|
-
while (toCheck) {
|
|
116
|
-
if (toCheck === element) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
toCheck = toCheck.parentElement;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const rows = table.querySelectorAll('tr, role="row"');
|
|
126
|
-
let foundRow = null;
|
|
127
|
-
for (let i = 0; i < rows.length; i++) {
|
|
128
|
-
const row = rows[i];
|
|
129
|
-
const rowData = [];
|
|
130
|
-
const cells = row.querySelectorAll(
|
|
131
|
-
"td, th, [role='cell'], [role='columnheader']"
|
|
132
|
-
);
|
|
133
|
-
cells.forEach((cell) => {
|
|
134
|
-
if (!isVisible(cell) || isBackgrounElement(cell)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const text = getTextFromElement(cell);
|
|
138
|
-
rowData.push(text);
|
|
139
|
-
});
|
|
140
|
-
if (rowData.includes(textInRow)) {
|
|
141
|
-
foundRow = row;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return foundRow;
|
|
146
|
-
});
|
|
147
|
-
await foundRow.locator(actionLocator).click();
|
|
65
|
+
async verifyTextFoundInPage(text) {
|
|
66
|
+
const element = await page.getByText(text);
|
|
67
|
+
await expect(element !== undefined).toBeTruthy();
|
|
148
68
|
}
|
|
149
69
|
async waitForPageLoad() {
|
|
150
70
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "automation_model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"expect-playwright": "^0.8.0",
|
|
18
19
|
"playwright": "^1.33.0"
|
|
19
20
|
}
|
|
20
21
|
}
|