@empiricalrun/test-gen 0.31.13 → 0.31.14
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/CHANGELOG.md +6 -0
- package/dist/actions/utils/index.d.ts.map +1 -1
- package/dist/actions/utils/index.js +32 -11
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,GAAG,CAAC;QAChB,MAAM,EAAE,GAAG,CAAC;KACb;CACF;AAED,wBAAsB,oCAAoC,CACxD,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,GAAG,CAAC;QAChB,MAAM,EAAE,GAAG,CAAC;KACb;CACF;AAED,wBAAsB,oCAAoC,CACxD,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,gBAmEX;AAED,wBAAgB,cAAc,WAG7B"}
|
|
@@ -8,17 +8,38 @@ async function getPlaywrightLocatorUsingCssSelector(cssSelector, xpath, page) {
|
|
|
8
8
|
.replaceAll(":has-text", ":contains")
|
|
9
9
|
.replaceAll(":text", ":contains");
|
|
10
10
|
return await page.evaluate((locator) => {
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
function getElementByXpath(path) {
|
|
13
|
-
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
|
14
|
-
}
|
|
15
11
|
let selectedElem;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
if (locator.xpath) {
|
|
13
|
+
try {
|
|
14
|
+
const xpath = locator.xpath.replaceAll("text()", "normalize-space()");
|
|
15
|
+
const result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
|
|
16
|
+
let node = result.iterateNext();
|
|
17
|
+
const elements = [];
|
|
18
|
+
// Store all matched elements
|
|
19
|
+
while (node) {
|
|
20
|
+
elements.push(node);
|
|
21
|
+
node = result.iterateNext();
|
|
22
|
+
}
|
|
23
|
+
// Find the least deep nesting (i.e., with the fewest child elements)
|
|
24
|
+
let minChildCount = Infinity;
|
|
25
|
+
const leastNestedElements = [];
|
|
26
|
+
elements.forEach((el) => {
|
|
27
|
+
//@ts-ignore
|
|
28
|
+
const childCount = el.children.length; // Count direct child elements
|
|
29
|
+
if (childCount < minChildCount) {
|
|
30
|
+
minChildCount = childCount;
|
|
31
|
+
leastNestedElements.length = 0;
|
|
32
|
+
leastNestedElements.push(el);
|
|
33
|
+
}
|
|
34
|
+
else if (childCount === minChildCount) {
|
|
35
|
+
leastNestedElements.push(el);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
selectedElem = leastNestedElements[0];
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
// ignore error
|
|
42
|
+
}
|
|
22
43
|
}
|
|
23
44
|
if (!selectedElem) {
|
|
24
45
|
const elements = window.jQuery(locator.cssForJq);
|
|
@@ -32,7 +53,7 @@ async function getPlaywrightLocatorUsingCssSelector(cssSelector, xpath, page) {
|
|
|
32
53
|
selectedElem = elements[elIdx];
|
|
33
54
|
}
|
|
34
55
|
else {
|
|
35
|
-
console.log("using xpath
|
|
56
|
+
console.log("using xpath locator");
|
|
36
57
|
}
|
|
37
58
|
if (!selectedElem) {
|
|
38
59
|
throw Error(`Unable to find element, css: ${locator.css}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.14",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"ts-morph": "^23.0.0",
|
|
45
45
|
"tsx": "^4.16.2",
|
|
46
46
|
"typescript": "^5.3.3",
|
|
47
|
-
"@empiricalrun/
|
|
47
|
+
"@empiricalrun/llm": "^0.9.3",
|
|
48
48
|
"@empiricalrun/reporter": "^0.20.2",
|
|
49
|
-
"@empiricalrun/
|
|
49
|
+
"@empiricalrun/r2-uploader": "^0.3.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/detect-port": "^1.3.5",
|