@letsrunit/playwright 0.3.8 → 0.3.10
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/dist/index.d.ts +2 -2
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/{locator.ts → fuzzy-locator.ts} +12 -8
- package/src/index.ts +1 -1
- package/src/selector/field-selector.ts +8 -0
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare function formatHtml(page: string | Page): Promise<string>;
|
|
|
17
17
|
/**
|
|
18
18
|
* Locates an element using Playwright selectors, with fallbacks.
|
|
19
19
|
*/
|
|
20
|
-
declare function
|
|
20
|
+
declare function fuzzyLocator(page: Page, selector: string): Promise<Locator>;
|
|
21
21
|
|
|
22
22
|
declare const createDateEngine: () => {
|
|
23
23
|
query(root: Element | Document, body: string): Element | null;
|
|
@@ -136,4 +136,4 @@ declare function realScrubHtml({ html, url }: {
|
|
|
136
136
|
url: string;
|
|
137
137
|
}, opts?: ScrubHtmlOptions): Promise<string>;
|
|
138
138
|
|
|
139
|
-
export { type PageInfo, type ScrubHtmlOptions, type Snapshot, browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml,
|
|
139
|
+
export { type PageInfo, type ScrubHtmlOptions, type Snapshot, browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml, fuzzyLocator, getMonthNames, realScrubHtml, screenshot, screenshotElement, scrollToCenter, scrubHtml, setFieldValue, snapshot, suppressInterferences, waitAfterInteraction, waitForAnimationsToFinish, waitForDomIdle, waitForIdle, waitForMeta, waitForUrlChange, waitUntilEnabled };
|
package/dist/index.js
CHANGED
|
@@ -1068,8 +1068,8 @@ async function formatHtml(page) {
|
|
|
1068
1068
|
return String(file);
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
1071
|
-
// src/locator.ts
|
|
1072
|
-
async function
|
|
1071
|
+
// src/fuzzy-locator.ts
|
|
1072
|
+
async function fuzzyLocator(page, selector) {
|
|
1073
1073
|
const primary = page.locator(selector).first();
|
|
1074
1074
|
if (await primary.count()) return primary;
|
|
1075
1075
|
return await tryRelaxNameToHasText(page, selector) || await tryTagInsteadOfRole(page, selector) || await tryRoleNameProximity(page, selector) || await tryFieldAlternative(page, selector) || await tryAsField(page, selector) || primary;
|
|
@@ -1107,6 +1107,7 @@ async function tryFieldAlternative(page, selector) {
|
|
|
1107
1107
|
const matchField = selector.match(/^field="([^"]+)"i?$/i);
|
|
1108
1108
|
if (!matchField) return null;
|
|
1109
1109
|
const [, field] = matchField;
|
|
1110
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(field)) return null;
|
|
1110
1111
|
return firstMatch(page, `#${field} > input`);
|
|
1111
1112
|
}
|
|
1112
1113
|
async function tryAsField(page, selector) {
|
|
@@ -1409,6 +1410,18 @@ var createFieldEngine = () => ({
|
|
|
1409
1410
|
if (name) texts.push(name);
|
|
1410
1411
|
const ph = el.placeholder ?? el.getAttribute("placeholder");
|
|
1411
1412
|
if (ph) texts.push(ph);
|
|
1413
|
+
for (let sib = el.nextElementSibling; sib; sib = sib.nextElementSibling) {
|
|
1414
|
+
if (sib.tagName === "LABEL") {
|
|
1415
|
+
texts.push(sib.textContent ?? "");
|
|
1416
|
+
break;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
for (let sib = el.previousElementSibling; sib; sib = sib.previousElementSibling) {
|
|
1420
|
+
if (sib.tagName === "LABEL") {
|
|
1421
|
+
texts.push(sib.textContent ?? "");
|
|
1422
|
+
break;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1412
1425
|
return texts;
|
|
1413
1426
|
}
|
|
1414
1427
|
return candidates.map((el) => ({ el, texts: textFor(el) })).filter(({ texts }) => texts.some(match)).map(({ el }) => el);
|
|
@@ -1527,10 +1540,10 @@ async function getContentWithMarkedHidden(page) {
|
|
|
1527
1540
|
}
|
|
1528
1541
|
|
|
1529
1542
|
// src/scroll.ts
|
|
1530
|
-
async function scrollToCenter(
|
|
1531
|
-
const count = await
|
|
1543
|
+
async function scrollToCenter(locator) {
|
|
1544
|
+
const count = await locator.count();
|
|
1532
1545
|
if (!count) return;
|
|
1533
|
-
await
|
|
1546
|
+
await locator.evaluate((el) => {
|
|
1534
1547
|
el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
1535
1548
|
});
|
|
1536
1549
|
}
|
|
@@ -3259,6 +3272,6 @@ function limitListsAndRows(doc, limit) {
|
|
|
3259
3272
|
});
|
|
3260
3273
|
}
|
|
3261
3274
|
|
|
3262
|
-
export { browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml,
|
|
3275
|
+
export { browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml, fuzzyLocator, getMonthNames, realScrubHtml, screenshot, screenshotElement, scrollToCenter, scrubHtml, setFieldValue, snapshot, suppressInterferences, waitAfterInteraction, waitForAnimationsToFinish, waitForDomIdle, waitForIdle, waitForMeta, waitForUrlChange, waitUntilEnabled };
|
|
3263
3276
|
//# sourceMappingURL=index.js.map
|
|
3264
3277
|
//# sourceMappingURL=index.js.map
|