### Install Dependencies Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Installs project dependencies using Bun. ```bash bun install ``` -------------------------------- ### Browser Automation DSL Example Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Example of using the Bunwright browser automation DSL to log in. ```typescript import { browser, defineConfig } from "bunwright"; export const config = defineConfig({ // ... }); export default browser.script(async () => { await browser.goto("https://example.com"); await browser.type("#username", "myuser"); await browser.type("#password", "mypass"); await browser.click("button:text('Login')"); }); ``` -------------------------------- ### Install Bunwright as a Project Dependency Source: https://github.com/jonaspm/bunwright/blob/main/README.md Install Bunwright using Bun to add it as a dependency to your project. ```bash bun add bunwright ``` -------------------------------- ### Run CLI Directly Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Executes the CLI directly in development mode with a specified script and example. ```bash bun run src/bunwright.ts examples/login.ts ``` -------------------------------- ### Getting Per-Step Results with .all() Source: https://github.com/jonaspm/bunwright/blob/main/README.md Demonstrates using `.all()` instead of awaiting the chain directly to retrieve an array of results from every step in the order they were executed. ```typescript const [, , title] = await page .navigate("https://example.com") .click("role:button") .evaluate(() => document.title) .all(); ``` -------------------------------- ### Install Bunwright Globally for CLI Usage Source: https://github.com/jonaspm/bunwright/blob/main/README.md Install Bunwright globally using npm for command-line interface access. ```bash npm install -g bunwright ``` -------------------------------- ### Bunwright Project Commands Source: https://github.com/jonaspm/bunwright/blob/main/AGENTS.md Common commands for managing the Bunwright project, including installation, testing, linting, formatting, building, and running the CLI. ```bash bun install # install deps bun test # all tests (bun:test runner) bun test tests/dsl.test.ts # single test file bun test -t "name" # filter by test name bun run typecheck # tsc --noEmit bun run lint # oxlint bun run lint:fix bun run format # oxfmt bun run build # bundles dist/ (build.ts) + emits .d.ts bun run docs # build + regenerate docs/api-reference.md (auto-generated, never hand-edit) bun run src/bunwright.ts examples/login.ts # run CLI directly in dev ``` -------------------------------- ### Bunwright Configuration Example Source: https://github.com/jonaspm/bunwright/blob/main/README.md Configure Bunwright settings like backend, resolution, and timeouts using a TypeScript configuration file. This configuration is merged with defaults and programmatic settings. ```typescript // bunwright.config.ts import { defineConfig } from "bunwright"; export default defineConfig({ backend: "chrome", // "webkit" | "chrome" | { type: "chrome", path, argv } width: 1440, // default 1280 height: 900, // default 800 url: "", // initial URL when the WebView opens console: true, // forward page console logs dataStore: "ephemeral", // or a directory path for persistent state retryTimeout: 10000, // auto-wait/retry budget per action, ms headless: true, // default: true on Windows, false elsewhere }); ``` -------------------------------- ### Fail-fast Behavior in Chaining Source: https://github.com/jonaspm/bunwright/blob/main/README.md Illustrates the fail-fast mechanism where if one step in a chain throws an error, subsequent steps are skipped. This example shows catching a TimeoutError. ```typescript import { browser, TimeoutError } from "bunwright"; try { await page .navigate("https://example.com") .click("role:button[name='Missing']") // throws TimeoutError .waitForURL("**/success"); // never runs } catch (error) { if (error instanceof TimeoutError) { // handle, fall back, continue } } ``` -------------------------------- ### Generate Documentation Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Builds the project and regenerates docs/api-reference.md. ```bash bun run docs ``` -------------------------------- ### Build Project Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Bundles the project into dist/ and emits .d.ts files using build.ts. ```bash bun run build ``` -------------------------------- ### Login, Type, Click, and Screenshot with Bunwright Source: https://github.com/jonaspm/bunwright/blob/main/README.md This snippet demonstrates a typical workflow: navigating to a page, filling in form fields, clicking a button, waiting for a URL change, and taking a screenshot. Ensure you have the necessary environment variables set for passwords. ```typescript import { browser } from "bunwright"; const page = await browser.newPage(); await page .navigate("https://example.com/login") .type("label:Username", "user@example.com") .type("label:Password", process.env.APP_PASSWORD!) .click("role:button[name='Login']") .waitForURL("**/dashboard") .screenshot("./dashboard.png"); await browser.close(); ``` -------------------------------- ### Chaining Navigation and Interaction Source: https://github.com/jonaspm/bunwright/blob/main/README.md Demonstrates chaining multiple actions like navigation, typing, clicking, and waiting for a URL change. Each call enqueues a step, and await executes them sequentially. ```typescript await page .navigate("https://example.com/login") .type("label:Username", "user") .click("role:button[name='Login']") .waitForURL("**/dashboard"); ``` -------------------------------- ### Run All Tests Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Executes all tests using the bun:test runner. ```bash bun test ``` -------------------------------- ### Format Code Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Formats the code using oxfmt. ```bash bun run format ``` -------------------------------- ### Run Single Test File Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Executes tests within a specific file. ```bash bun test tests/dsl.test.ts ``` -------------------------------- ### defineConfig Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Defines and returns a browser configuration object. This function is used to set up the environment for browser automation. ```APIDOC ## defineConfig ### Description Defines and returns a browser configuration object. This function is used to set up the environment for browser automation. ### Function Signature ```typescript defineConfig(config: BrowserConfig): BrowserConfig ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **config** (BrowserConfig) - Required - The browser configuration object. - **backend?** ("webkit" | "chrome" | { type: "chrome"; path?: string; argv?: string[]; }) - **width?** (number) - **height?** (number) - **url?** (string) - **console?** (boolean) - **dataStore?** ("ephemeral" | string) - **retryTimeout?** (number) - **headless?** (boolean) - `--headless=new`. When false, it runs in headed mode. Defaults to true on Windows, false elsewhere. ### Request Example ```json { "config": { "backend": "chrome", "width": 1024, "height": 768, "headless": false } } ``` ### Response #### Success Response (200) - **BrowserConfig** (BrowserConfig) - The validated and returned browser configuration object. #### Response Example ```json { "backend": "chrome", "width": 1024, "height": 768, "headless": false } ``` ``` -------------------------------- ### Run Bunwright Script with CLI Source: https://github.com/jonaspm/bunwright/blob/main/README.md Execute a Bunwright script using the Bunx command. The CLI automatically loads .env files. ```bash bunx bunwright shot.ts ``` -------------------------------- ### Page Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Represents a web page, providing methods for navigation, interaction, and element querying. ```APIDOC ## Class: Page ### Description Represents a single web page, offering functionalities for navigating between pages, interacting with elements, and managing page state. ### Methods - `close(): void`: Closes the current page. - `navigate(url: string, opts?: { waitForLoadState?: LoadState; }): Promise`: Navigates to a new URL. - `back(): Promise`: Navigates back to the previous page. - `forward(): Promise`: Navigates forward to the next page. - `reload(): Promise`: Reloads the current page. - `click(sel: Selector, opts?: { timeout?: number; }): Promise`: Clicks an element identified by a selector. - `dblClick(sel: Selector, opts?: { timeout?: number; }): Promise`: Double-clicks an element identified by a selector. - `type(sel: Selector, text: string, opts?: { timeout?: number; }): Promise`: Types text into an element identified by a selector. - `press(key: string, modifiers?: Bun.WebView.Modifier[]): Promise`: Presses a key, optionally with modifiers. - `scroll(dx: number, dy: number): Promise`: Scrolls the page by the specified amounts. - `scrollTo(sel: Selector, opts?: { block?: "start" | "center" | "end"; timeout?: number; }): Promise`: Scrolls to an element identified by a selector. - `resize(width: number, height: number): Promise`: Resizes the page. - `screenshot(path?: string): Promise`: Takes a screenshot of the page. - `expect(sel: Selector, opts?: { timeout?: number; }): Promise`: Expects an element identified by a selector to be present. - `check(sel: Selector): Promise`: Checks a checkbox identified by a selector. - `waitForLoadState(state: LoadState, opts?: { timeout?: number; }): Promise`: Waits for a specific load state. - `evaluate(fn: () => T): Promise`: Evaluates a function in the page's context. - `locator(sel: Selector): Locator`: Creates a locator for an element. - `$(sel: Selector): Promise`: Finds the first element matching the selector. - `$$ (sel: Selector): Promise`: Finds all elements matching the selector. - `waitForSelector(sel: Selector, opts?: { timeout?: number; }): Promise`: Waits for an element identified by a selector to appear. - `waitForURL(url: string | RegExp, opts?: { timeout?: number; }): Promise`: Waits for the page URL to match the given pattern. - `exists(sel: Selector): Promise`: Checks if an element identified by a selector exists. - `waitFor(sel: Selector, opts?: { timeout?: number; }): Promise`: Waits for an element identified by a selector to be present. - `waitForTimeout(ms: number): Promise`: Waits for a specified duration. - `cdp(method: string, params?: Record): Promise`: Executes a Chrome DevTools Protocol command. ``` -------------------------------- ### Link Local Bunwright Repository Source: https://github.com/jonaspm/bunwright/blob/main/README.md Link the local Bunwright repository to make it available for other Bun projects. This is useful for testing local changes in a consuming project. ```bash bun link ``` -------------------------------- ### Basic Browser Automation Script Source: https://github.com/jonaspm/bunwright/blob/main/README.md A simple Bunwright script to open a new page, navigate to a URL, take a screenshot, and close the browser. Requires Bun and Chrome/WebKit. ```typescript // shot.ts import { browser } from "bunwright"; const page = await browser.newPage(); await page.navigate("https://example.com").screenshot("./example.png"); await browser.close(); ``` -------------------------------- ### BrowserContext Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Manages a browser context, allowing for the creation of new pages and closing the context. ```APIDOC ## Class: BrowserContext ### Description Manages a browser context, providing methods to create new pages and close the context. ### Methods - `newPage(): Promise`: Creates and returns a new page within the browser context. - `close(): Promise`: Closes the current browser context. ``` -------------------------------- ### defineConfig Function Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Defines browser configuration settings. ```typescript defineConfig(config: BrowserConfig): BrowserConfig ``` -------------------------------- ### Fix Linting Issues Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Automatically fixes linting issues using oxlint. ```bash bun run lint:fix ``` -------------------------------- ### Windows Chrome Workaround - Debug Logging Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Enables debug logging for the Windows Chrome workaround when spawning Chrome. ```bash BUNWRIGHT_DEBUG=1 ``` -------------------------------- ### Lint Code Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Lints the code using oxlint. ```bash bun run lint ``` -------------------------------- ### chainable Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Creates a chainable interface for a given target. This allows for sequential operations on the target object. ```APIDOC ## chainable ### Description Creates a chainable interface for a given target. This allows for sequential operations on the target object. ### Function Signature ```typescript chainable(target: T): Chain ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **target** (T) - Required - The target object to make chainable. ### Request Example ```json { "target": { ... } } ``` ### Response #### Success Response (200) - **Chain** - A chainable object wrapping the target. #### Response Example ```json { "chainableObject": { ... } } ``` ``` -------------------------------- ### Locator Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Provides a way to locate and interact with elements on a page using selectors. ```APIDOC ## Class: Locator ### Description Represents a locator for a DOM element, offering methods to interact with it and chain operations for more specific selections. ### Methods - `getPage(): Page`: Returns the page associated with this locator. - `resolveSelector(): Promise`: Resolves the selector to its string representation. - `click(opts?: { timeout?: number; }): Promise`: Clicks the element. - `dblClick(opts?: { timeout?: number; }): Promise`: Double-clicks the element. - `type(text: string, opts?: { timeout?: number; }): Promise`: Types the given text into the element. - `fill(text: string): Promise`: Fills the element with the given text. - `press(key: string, modifiers?: Bun.WebView.Modifier[]): Promise`: Presses a key on the element, optionally with modifiers. - `screenshot(opts?: { path?: string; }): Promise`: Takes a screenshot of the element. - `evaluate(fn: (el: Element) => T): Promise`: Evaluates a function in the context of the element. - `innerText(): Promise`: Gets the inner text of the element. - `innerHTML(): Promise`: Gets the inner HTML of the element. - `getAttribute(name: string): Promise`: Gets the value of a specified attribute. - `isVisible(): Promise`: Checks if the element is visible. - `isEnabled(): Promise`: Checks if the element is enabled. - `isChecked(): Promise`: Checks if the element is checked. - `filter(sel: Selector): Locator`: Filters the locator with a new selector. - `first(): Locator`: Returns the first element matching the locator. - `last(): Locator`: Returns the last element matching the locator. - `nth(index: number): Locator`: Returns the nth element matching the locator. - `count(): Promise`: Gets the number of elements matching the locator. - `toElement(): Promise`: Converts the locator to an ElementHandle. ``` -------------------------------- ### Link Bunwright in Consuming Project Source: https://github.com/jonaspm/bunwright/blob/main/README.md Link the Bunwright package into another Bun project after running 'bun link' in the Bunwright repository. This command makes the local Bunwright available to the other project. ```bash bun link bunwright ``` -------------------------------- ### Filter Tests by Name Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Runs tests that match a specific name pattern. ```bash bun test -t "name" ``` -------------------------------- ### LoadState Type Alias Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Defines the possible states for page loading events. ```typescript "load" | "domcontentloaded" | "networkidle"; ``` -------------------------------- ### Awaiting Chain Result Source: https://github.com/jonaspm/bunwright/blob/main/README.md Shows how awaiting a chain resolves to the final target. If the last step returns a value (e.g., count(), evaluate()), awaiting resolves to that value. ```typescript const count = await page.locator("css:input").count(); // number const title = await page.evaluate(() => document.title); // string ``` -------------------------------- ### ElementHandle Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Represents a handle to an element in the DOM, providing methods for interaction and inspection. ```APIDOC ## Class: ElementHandle ### Description Represents a handle to a DOM element, enabling interactions like clicking, typing, and retrieving element properties. ### Methods - `click(): Promise`: Clicks the element. - `dblClick(): Promise`: Double-clicks the element. - `type(text: string): Promise`: Types the given text into the element. - `press(key: string, modifiers?: Bun.WebView.Modifier[]): Promise`: Presses a key on the element, optionally with modifiers. - `screenshot(opts?: { path?: string; }): Promise`: Takes a screenshot of the element. - `evaluate(fn: (el: Element) => T): Promise`: Evaluates a function in the context of the element. - `innerText(): Promise`: Gets the inner text of the element. - `innerHTML(): Promise`: Gets the inner HTML of the element. - `getAttribute(name: string): Promise`: Gets the value of a specified attribute. - `isVisible(): Promise`: Checks if the element is visible. - `isEnabled(): Promise`: Checks if the element is enabled. ``` -------------------------------- ### chainable Function Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Creates a chainable interface for a given target. ```typescript chainable(target: T): Chain ``` -------------------------------- ### Typecheck Code Source: https://github.com/jonaspm/bunwright/blob/main/CLAUDE.md Performs type checking using TypeScript compiler (tsc --noEmit). ```bash bun run typecheck ``` -------------------------------- ### Selector Type Alias Source: https://github.com/jonaspm/bunwright/blob/main/docs/api-reference.md Defines the various types of selectors that can be used to target elements. ```typescript `role:${string}` | `label:${string}` | `text:${string}` | `css:${string}` | `xpath:${string}`; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.