@letsrunit/playwright 0.1.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/README.md +44 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +3006 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
- package/src/browser.ts +20 -0
- package/src/field/calendar.ts +300 -0
- package/src/field/date-group.ts +253 -0
- package/src/field/date-text-input.ts +270 -0
- package/src/field/index.ts +57 -0
- package/src/field/native-checkbox.ts +21 -0
- package/src/field/native-date.ts +62 -0
- package/src/field/native-input.ts +17 -0
- package/src/field/native-select.ts +75 -0
- package/src/field/otp.ts +22 -0
- package/src/field/radio-group.ts +27 -0
- package/src/field/slider.ts +132 -0
- package/src/field/types.ts +16 -0
- package/src/format-html.ts +17 -0
- package/src/index.ts +12 -0
- package/src/locator.ts +102 -0
- package/src/page-info.ts +33 -0
- package/src/screenshot.ts +84 -0
- package/src/scroll.ts +10 -0
- package/src/scrub-html.ts +333 -0
- package/src/selector/date-selector.ts +272 -0
- package/src/selector/field-selector.ts +121 -0
- package/src/selector/index.ts +2 -0
- package/src/snapshot.ts +55 -0
- package/src/suppress-interferences.ts +288 -0
- package/src/translations/af.ts +41 -0
- package/src/translations/ar.ts +7 -0
- package/src/translations/az.ts +40 -0
- package/src/translations/bg.ts +7 -0
- package/src/translations/bn.ts +40 -0
- package/src/translations/bs.ts +7 -0
- package/src/translations/ca.ts +41 -0
- package/src/translations/cs.ts +7 -0
- package/src/translations/da.ts +44 -0
- package/src/translations/de.ts +47 -0
- package/src/translations/el.ts +40 -0
- package/src/translations/en.ts +7 -0
- package/src/translations/es.ts +7 -0
- package/src/translations/et.ts +7 -0
- package/src/translations/eu.ts +7 -0
- package/src/translations/fa.ts +7 -0
- package/src/translations/fi.ts +39 -0
- package/src/translations/fr.ts +42 -0
- package/src/translations/ga.ts +40 -0
- package/src/translations/he.ts +45 -0
- package/src/translations/hi.ts +39 -0
- package/src/translations/hr.ts +7 -0
- package/src/translations/hu.ts +7 -0
- package/src/translations/hy.ts +7 -0
- package/src/translations/id.ts +7 -0
- package/src/translations/index.ts +68 -0
- package/src/translations/is.ts +7 -0
- package/src/translations/it.ts +7 -0
- package/src/translations/ja.ts +7 -0
- package/src/translations/ka.ts +36 -0
- package/src/translations/ko.ts +7 -0
- package/src/translations/lt.ts +7 -0
- package/src/translations/lv.ts +43 -0
- package/src/translations/nl.ts +43 -0
- package/src/translations/no.ts +46 -0
- package/src/translations/pl.ts +39 -0
- package/src/translations/pt.ts +41 -0
- package/src/translations/ro.ts +40 -0
- package/src/translations/ru.ts +7 -0
- package/src/translations/sk.ts +7 -0
- package/src/translations/sl.ts +7 -0
- package/src/translations/sv.ts +44 -0
- package/src/translations/sw.ts +7 -0
- package/src/translations/ta.ts +7 -0
- package/src/translations/th.ts +39 -0
- package/src/translations/tl.ts +7 -0
- package/src/translations/tr.ts +41 -0
- package/src/translations/uk.ts +7 -0
- package/src/translations/ur.ts +43 -0
- package/src/translations/vi.ts +7 -0
- package/src/translations/zh.ts +7 -0
- package/src/types.ts +37 -0
- package/src/unified-html-diff.ts +22 -0
- package/src/utils/date.ts +40 -0
- package/src/utils/pick-field-element.ts +48 -0
- package/src/utils/type-check.ts +7 -0
- package/src/wait.ts +170 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Playwright Package (`@letsrunit/playwright`)
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @letsrunit/playwright
|
|
7
|
+
# or
|
|
8
|
+
yarn add @letsrunit/playwright
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Low-level Playwright utilities and enhancements for `@letsrunit`. This package provides a robust set of tools for interacting with and extracting information from web pages, optimized for AI-driven automation.
|
|
12
|
+
|
|
13
|
+
## Exported Utilities
|
|
14
|
+
|
|
15
|
+
### Element Discovery & Interaction
|
|
16
|
+
|
|
17
|
+
- **`smartLocator(page, selector)`**: An enhanced locator that supports both standard CSS/XPath and higher-level semantic selectors.
|
|
18
|
+
- **`findField(page, label)`**: Finds form fields based on their associated labels or placeholders.
|
|
19
|
+
- **`scrollIntoView(locator)`**: Ensures an element is visible before interaction.
|
|
20
|
+
|
|
21
|
+
### Page Analysis
|
|
22
|
+
|
|
23
|
+
- **`extractPageInfo(page)`**: A comprehensive helper that extracts the title, URL, metadata, and captures a screenshot of the page.
|
|
24
|
+
- **`detectLanguage(page)`**: Detects the primary language of the page content.
|
|
25
|
+
- **`snapshot(page)`**: Captures a cleaned-up and formatted HTML snapshot of the current page, optimized for LLM consumption.
|
|
26
|
+
|
|
27
|
+
### Wait Helpers
|
|
28
|
+
|
|
29
|
+
- **`waitForIdle(page)`**: Waits for the page to reach a network-idle and stability state.
|
|
30
|
+
- **`waitForText(page, text)`**: Waits for specific text to appear on the page.
|
|
31
|
+
|
|
32
|
+
### DOM & HTML Utilities
|
|
33
|
+
|
|
34
|
+
- **`formatHtml(html)`**: Prettifies and cleans up HTML strings.
|
|
35
|
+
- **`scrubHtml(html)`**: Removes noisy elements (scripts, styles, etc.) from HTML to reduce token usage for AI.
|
|
36
|
+
- **`unifiedHtmlDiff(oldHtml, newHtml)`**: Calculates a meaningful diff between two HTML states.
|
|
37
|
+
|
|
38
|
+
## Testing
|
|
39
|
+
|
|
40
|
+
Run tests for this package:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
yarn test
|
|
44
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Browser, BrowserContextOptions, Page, Locator, PageScreenshotOptions } from '@playwright/test';
|
|
2
|
+
import { Scalar, Range } from '@letsrunit/utils';
|
|
3
|
+
|
|
4
|
+
declare function browse(browser: Browser, options?: BrowserContextOptions): Promise<Page>;
|
|
5
|
+
|
|
6
|
+
interface SetOptions {
|
|
7
|
+
force?: boolean;
|
|
8
|
+
noWaitAfter?: boolean;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
type Value = Scalar | Scalar[] | Range | boolean | null;
|
|
12
|
+
|
|
13
|
+
declare function setFieldValue(el: Locator, value: Value, options?: SetOptions): Promise<void>;
|
|
14
|
+
|
|
15
|
+
declare function formatHtml(page: string | Page): Promise<string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Locates an element using Playwright selectors, with fallbacks.
|
|
19
|
+
*/
|
|
20
|
+
declare function locator(page: Page, selector: string): Promise<Locator>;
|
|
21
|
+
|
|
22
|
+
declare const createDateEngine: () => {
|
|
23
|
+
query(root: Element | Document, body: string): Element | null;
|
|
24
|
+
queryAll(root: Element | Document, body: string): Element[];
|
|
25
|
+
_parseSelector(body: string): Date | null;
|
|
26
|
+
_matchesDate(el: Element, targetDate: Date, locale: string, body: string): {
|
|
27
|
+
matched: boolean;
|
|
28
|
+
type: "full" | "partial";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
declare const createFieldEngine: () => {
|
|
33
|
+
_compileMatcher(body: string): (s: string | null | undefined) => boolean;
|
|
34
|
+
query(root: Element | Document, body: string): Element | null;
|
|
35
|
+
queryAll(root: Element | Document, body: string): Element[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface Snapshot {
|
|
39
|
+
url: string;
|
|
40
|
+
html: string;
|
|
41
|
+
screenshot: File;
|
|
42
|
+
}
|
|
43
|
+
interface PageInfo {
|
|
44
|
+
/** Page name (from <title> or meta tags) */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Short page description (meta description or OG/Twitter) */
|
|
47
|
+
description?: string;
|
|
48
|
+
/** Main image for previews (OpenGraph/Twitter) */
|
|
49
|
+
image?: string;
|
|
50
|
+
/** Site or brand logo if available */
|
|
51
|
+
logo?: string;
|
|
52
|
+
/** Author name if specified */
|
|
53
|
+
author?: string;
|
|
54
|
+
/** Publisher or organization name */
|
|
55
|
+
publisher?: string;
|
|
56
|
+
/** Page language, e.g. "en", "nl-NL" */
|
|
57
|
+
lang?: string;
|
|
58
|
+
/** Favicon URL */
|
|
59
|
+
favicon?: string;
|
|
60
|
+
/** Canonical or resolved page URL */
|
|
61
|
+
url: string;
|
|
62
|
+
/** Screenshot of the page */
|
|
63
|
+
screenshot?: File;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare function snapshot(page: Page): Promise<Snapshot>;
|
|
67
|
+
|
|
68
|
+
declare function screenshot(page: Page, options?: PageScreenshotOptions): Promise<File>;
|
|
69
|
+
|
|
70
|
+
declare function scrollToCenter(locator: Locator): Promise<void>;
|
|
71
|
+
|
|
72
|
+
type Options = {
|
|
73
|
+
timeoutMs?: number;
|
|
74
|
+
preferReject?: boolean;
|
|
75
|
+
lang?: string;
|
|
76
|
+
pollIntervalMs?: number;
|
|
77
|
+
settleAfterActionMs?: number;
|
|
78
|
+
quietPeriodMs?: number;
|
|
79
|
+
minSweepMs?: number;
|
|
80
|
+
maxActions?: number;
|
|
81
|
+
verbose?: boolean;
|
|
82
|
+
};
|
|
83
|
+
declare function suppressInterferences(page: Page, opts?: Options): Promise<void>;
|
|
84
|
+
|
|
85
|
+
declare function formatDateForInput(date: Date, type: string | null): string;
|
|
86
|
+
declare function formatDate(d: Date, format: string): string;
|
|
87
|
+
declare function getMonthNames(locale?: string): string[];
|
|
88
|
+
|
|
89
|
+
declare function waitForIdle(page: Page, timeout?: number): Promise<void>;
|
|
90
|
+
declare function waitForMeta(page: Page, timeout?: number): Promise<void>;
|
|
91
|
+
/** Wait until the DOM hasn't changed for `quiet` (default 500ms). */
|
|
92
|
+
declare function waitForDomIdle(page: Page, { quiet, timeout }?: {
|
|
93
|
+
quiet?: number;
|
|
94
|
+
timeout?: number;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
declare function waitForAnimationsToFinish(root: Locator): Promise<void>;
|
|
97
|
+
declare function waitForUrlChange(page: Page, prevUrl: string, timeout: number): Promise<boolean>;
|
|
98
|
+
declare function waitUntilEnabled(page: Page, target: Locator, timeout: number): Promise<void>;
|
|
99
|
+
declare function waitAfterInteraction(page: Page, target: Locator, opts?: {
|
|
100
|
+
prevUrl?: string;
|
|
101
|
+
navTimeout?: number;
|
|
102
|
+
settleTimeout?: number;
|
|
103
|
+
quietMs?: number;
|
|
104
|
+
}): Promise<void>;
|
|
105
|
+
|
|
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 };
|