@letsrunit/playwright 0.1.0 → 0.3.0
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 +3 -2
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/package.json +21 -11
- package/src/field/calendar.ts +1 -2
- package/src/field/native-select.ts +1 -2
- package/src/screenshot.ts +8 -1
- package/src/scrub-html.ts +1 -1
- package/src/wait.ts +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Browser, BrowserContextOptions, Page, Locator, PageScreenshotOptions } from '@playwright/test';
|
|
1
|
+
import { Browser, BrowserContextOptions, Page, Locator, LocatorScreenshotOptions, PageScreenshotOptions } from '@playwright/test';
|
|
2
2
|
import { Scalar, Range } from '@letsrunit/utils';
|
|
3
3
|
|
|
4
4
|
declare function browse(browser: Browser, options?: BrowserContextOptions): Promise<Page>;
|
|
@@ -65,6 +65,7 @@ interface PageInfo {
|
|
|
65
65
|
|
|
66
66
|
declare function snapshot(page: Page): Promise<Snapshot>;
|
|
67
67
|
|
|
68
|
+
declare function screenshotElement(page: Page, selector: string, options?: LocatorScreenshotOptions): Promise<File>;
|
|
68
69
|
declare function screenshot(page: Page, options?: PageScreenshotOptions): Promise<File>;
|
|
69
70
|
|
|
70
71
|
declare function scrollToCenter(locator: Locator): Promise<void>;
|
|
@@ -103,4 +104,4 @@ declare function waitAfterInteraction(page: Page, target: Locator, opts?: {
|
|
|
103
104
|
quietMs?: number;
|
|
104
105
|
}): Promise<void>;
|
|
105
106
|
|
|
106
|
-
export { type PageInfo, type Snapshot, browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml, getMonthNames, locator, screenshot, scrollToCenter, setFieldValue, snapshot, suppressInterferences, waitAfterInteraction, waitForAnimationsToFinish, waitForDomIdle, waitForIdle, waitForMeta, waitForUrlChange, waitUntilEnabled };
|
|
107
|
+
export { type PageInfo, type Snapshot, browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml, getMonthNames, locator, screenshot, screenshotElement, scrollToCenter, setFieldValue, snapshot, suppressInterferences, waitAfterInteraction, waitForAnimationsToFinish, waitForDomIdle, waitForIdle, waitForMeta, waitForUrlChange, waitUntilEnabled };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { getWeekNumber, sleep, chain, hashKey, isRange, isDate, isArray, cartesian } from '@letsrunit/utils';
|
|
2
|
-
import { diffArray, uniqueItem } from '@letsrunit/utils/src/array';
|
|
1
|
+
import { getWeekNumber, sleep, chain, hashKey, isRange, isDate, isArray, diffArray, cartesian, uniqueItem } from '@letsrunit/utils';
|
|
3
2
|
import rehypeFormat from 'rehype-format';
|
|
4
3
|
import rehypeParse from 'rehype-parse';
|
|
5
4
|
import rehypeStringify from 'rehype-stringify';
|
|
@@ -190,7 +189,7 @@ async function waitAfterInteraction(page, target, opts = {}) {
|
|
|
190
189
|
});
|
|
191
190
|
return;
|
|
192
191
|
}
|
|
193
|
-
if (kind === "button" && await target.isDisabled()) {
|
|
192
|
+
if (kind === "button" && await target.isDisabled({ timeout: 1e3 }).catch(() => false)) {
|
|
194
193
|
await Promise.race([
|
|
195
194
|
waitUntilEnabled(page, target, settleTimeout).catch(() => {
|
|
196
195
|
}),
|
|
@@ -208,14 +207,15 @@ async function waitAfterInteraction(page, target, opts = {}) {
|
|
|
208
207
|
}
|
|
209
208
|
}
|
|
210
209
|
async function elementKind(target) {
|
|
211
|
-
const
|
|
210
|
+
const PROBE = 1e3;
|
|
211
|
+
const role = await target.getAttribute("role", { timeout: PROBE }).catch(() => null);
|
|
212
212
|
if (role === "link") return "link";
|
|
213
213
|
if (role === "button") return "button";
|
|
214
|
-
const tag = await target.evaluate((el) => el.tagName.toLowerCase()).catch(() => "");
|
|
214
|
+
const tag = await target.evaluate((el) => el.tagName.toLowerCase(), null, { timeout: PROBE }).catch(() => "");
|
|
215
215
|
if (tag === "a") return "link";
|
|
216
216
|
if (tag === "button") return "button";
|
|
217
217
|
if (tag === "input") {
|
|
218
|
-
const type = await target.getAttribute("type").catch(() => null);
|
|
218
|
+
const type = await target.getAttribute("type", { timeout: PROBE }).catch(() => null);
|
|
219
219
|
if (type === "button" || type === "submit" || type === "reset") return "button";
|
|
220
220
|
}
|
|
221
221
|
return "other";
|
|
@@ -1412,6 +1412,11 @@ var createFieldEngine = () => ({
|
|
|
1412
1412
|
return candidates.map((el) => ({ el, texts: textFor(el) })).filter(({ texts }) => texts.some(match)).map(({ el }) => el);
|
|
1413
1413
|
}
|
|
1414
1414
|
});
|
|
1415
|
+
async function screenshotElement(page, selector, options) {
|
|
1416
|
+
const buffer = await page.locator(selector).first().screenshot(options);
|
|
1417
|
+
const filename = await hashKey("screenshot-{hash}.png", buffer);
|
|
1418
|
+
return new File([new Uint8Array(buffer)], filename, { type: "image/png" });
|
|
1419
|
+
}
|
|
1415
1420
|
async function screenshot(page, options) {
|
|
1416
1421
|
const buffer = options?.mask?.length ? await screenshotWithMask(page, options) : await page.screenshot(options);
|
|
1417
1422
|
const filename = await hashKey(`screenshot-{hash}.png`, buffer);
|
|
@@ -3001,6 +3006,6 @@ async function suppressInterferences(page, opts = {}) {
|
|
|
3001
3006
|
}
|
|
3002
3007
|
}
|
|
3003
3008
|
|
|
3004
|
-
export { browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml, getMonthNames, locator, screenshot, scrollToCenter, setFieldValue, snapshot, suppressInterferences, waitAfterInteraction, waitForAnimationsToFinish, waitForDomIdle, waitForIdle, waitForMeta, waitForUrlChange, waitUntilEnabled };
|
|
3009
|
+
export { browse, createDateEngine, createFieldEngine, formatDate, formatDateForInput, formatHtml, getMonthNames, locator, screenshot, screenshotElement, scrollToCenter, setFieldValue, snapshot, suppressInterferences, waitAfterInteraction, waitForAnimationsToFinish, waitForDomIdle, waitForIdle, waitForMeta, waitForUrlChange, waitUntilEnabled };
|
|
3005
3010
|
//# sourceMappingURL=index.js.map
|
|
3006
3011
|
//# sourceMappingURL=index.js.map
|