Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,34 @@ Flashwright needs Node.js 22.18 or newer. You can also run TypeScript configs an

Projects that use the library without the test runner replace `playwright` the same way (`npm i playwright@npm:flashwright`), and `playwright-core` is `flashwright-core`. Browsers, configs, reporters, the trace viewer, codegen and the VS Code extension are Playwright's.

## Documentation

- [Performance](docs/performance.md): optimisations, defaults, opt-in settings and implementation details.
- [Quality-of-life features](docs/features.md): videos, diagnostics, snapshots, project servers and migration tools.
- [Configuration](docs/configuration.md): options, examples and limitations.
- [Agent workflows](docs/agents.md): reporters, JSON summaries, watch mode, warm sessions and MCP.
- [Videos and demos](docs/videos.md): recording, narration and voices.
- [Migration](docs/migration.md): behaviour differences, deprecated APIs, codemod and Bun.
- [Benchmarks](docs/benchmarks.md): methodology, reproduction steps and full results.

## Compared to other frameworks

<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/media/competitors-dark.svg">
<img alt="The same 24 TodoMVC tests in 9 frameworks. With 1 worker: Flashwright 2.41 s, Bun test with Bun.WebView 4.39 s, Playwright 4.63 s, Selenium 5.48 s, Puppeteer 6.29 s, Nightwatch 6.45 s, WebdriverIO 10.57 s, Cypress 17.29 s, TestCafe 22.55 s. With 4 workers: Flashwright 1.54 s, Selenium 2.77 s, Bun 2.80 s, Puppeteer 2.98 s, Playwright 3.12 s, Nightwatch 3.38 s, WebdriverIO 4.91 s, TestCafe 9.28 s, Cypress 17.37 s." src="docs/media/competitors.svg">
</picture>

The same 24 TodoMVC tests, ported to nine tools with the same actions, assertions and CSS selectors. Each tool drives Chromium 156 on the same machine, using its recommended waits and default test isolation. Numbers are the complete test command, median of 15 passing runs.
The same 24 TodoMVC tests, ported to nine tools with the same actions, assertions and CSS selectors. Each tool drives Chromium 156 on the same machine, using its recommended waits and default test isolation. Numbers are median times for the complete test command.

Cypress runs one spec at a time without Cypress Cloud. Bun's experimental `Bun.WebView` needs a helper for waits and failed one of its 60 runs, which was excluded. [Full results, versions and reproduction steps](docs/benchmarks.md#compared-to-other-frameworks).

## Benchmarks

![Bar chart: wall-clock time of 18 scenarios, Playwright vs Flashwright; Flashwright is 2.04× to 4.01× faster in each](docs/media/benchmarks.svg)

Complete test commands, from launch to exit, median of 15 alternating runs on the same 6-CPU Linux machine with Chromium's headless shell. The tests are unchanged, and the warm session is off, as in CI. The matrix covers Playwright's TodoMVC and SVGOMG examples, shop and admin apps, failures, screenshots and visual comparisons.
Median times for complete test commands, from launch to exit, on the same 6-CPU Linux machine with Chromium's headless shell. The tests are unchanged, and the warm session is off, as in CI. The matrix covers Playwright's TodoMVC and SVGOMG examples, shop and admin apps, failures, screenshots and visual comparisons.

[Full results and methodology](docs/benchmarks.md#compared-to-playwright). Reproduce with `node bench/matrix.mjs 15`.
[Full results, methodology and reproduction steps](docs/benchmarks.md).

## How is it so fast?

Expand All @@ -60,7 +70,7 @@ Flashwright spends less time starting browsers, compiling the same JavaScript an
- **Start work early.** Workers and browsers start while the CLI reads the config, and the longest tests run first. Code caching, lazy loading and fewer browser round trips reduce startup and per-call overhead.
- **Do less work per locator and screenshot.** Locator queries avoid repeated style and accessible-name calculations. Screenshots use faster PNG encoding with the same pixels, and visual comparisons have fast paths for unchanged images.

These choices have [observable differences from Playwright](#differences-from-playwright). The [configuration reference](docs/configuration.md) explains the options and their tradeoffs.
See [all optimisations and how they work](docs/performance.md), including defaults, local workflows and optional settings. These choices have [observable differences from Playwright](#differences-from-playwright); the [configuration reference](docs/configuration.md) explains the options and tradeoffs.

## Speed options

Expand Down Expand Up @@ -94,11 +104,11 @@ The same test, recorded twice. `--video` includes the test title, action caption

It needs `ffmpeg`. Recording adds waits for the page to paint, and captions include typed text, including passwords, so use test data you're happy to share. [Examples, voice setup and recording options](docs/videos.md).

## Additions
## Quality-of-life features

Flashwright also supports a web server per project, `use` options on individual tests, pruning stale snapshots with `--prune-snapshots`, and accepting changed snapshots without a rerun with `npx playwright accept-snapshots`.

[Examples and limitations](docs/configuration.md#additions).
[All quality-of-life features](docs/features.md), with links to examples and limitations.

## Differences from Playwright

Expand Down
66 changes: 46 additions & 20 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,31 @@

Short test runs matter when an agent checks its work after every edit. Flashwright reduces startup time and keeps passing-test output out of the way:

- **Re-running one test** takes about 75 ms instead of 673 ms, in the [warm session](#warm-session) that the first run starts; that first run takes 240 ms. `playwright cli` commands start in ~45 ms instead of ~260 ms.
- **Screenshots** take about half the time, and `toHaveScreenshot()` returns immediately when nothing changed.
- **Agent mode**: when Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot CLI or any tool that sets `AI_AGENT` runs `playwright test`, the output is the failures and nothing else, and the outcome is also written as JSON. See [agent mode](#agent-mode).
- **Failures say what the page has instead.** When an action or assertion waits for an element that never appears, the call log says which part of the locator stopped matching, whether a hidden element matches, and which elements are close, as locators to copy:
```
- waiting for getByRole('button', { name: 'Logout' })
- no element matched
- similar buttons: getByRole('button', { name: 'Log out' })
```
It covers role names, text, labels, placeholders, test ids, `nth()` and chains, and points at iframes when nothing is close.
- **`npx playwright doctor`** checks, without changing anything, what a run needs: Node, a single copy of Playwright, a config that loads, test files for each project, each project's browser and its system libraries, and a display for headed projects. It also says whether agent mode and the warm session are on. `--json` prints the checks for a script or an agent; it exits with 1 when something would stop a run.
- **The MCP server** can answer as soon as the page has settled instead of after a fixed 500 ms: `playwright mcp --adaptive-settle` (or `timeouts.adaptiveSettle: true`). A click that saves through an API returns in 234 ms instead of 1014 ms.

### Agent mode

When a coding agent runs the tests, an `agent` reporter replaces `list`, `line` and `dot`. It prints nothing for passing tests or their console output, prints each failure once (its last attempt, with the test's output), and ends with the counts and `npx playwright test --last-failed`. No colors, no rules of dashes, and the HTML report is never opened or served. 201 tests with one failure print 26 lines (888 bytes) instead of 425 (17.5 KB).
- [Agent mode](#agent-mode) prints failures and a short summary instead of passing-test noise.
- [Structured summaries](#structured-test-summary) expose outcomes, errors, attachments and rerun commands as JSON.
- [Watch mode](#watch-mode) re-runs affected tests on save and prepares the next run in advance.
- [Warm sessions](#warm-session) keep browsers ready between commands; one measured TodoMVC test re-runs in 76 ms instead of 673 ms.
- [Locator diagnostics](#locator-diagnostics) suggest what the page actually contains when an element never appears.
- [Doctor](#check-the-project-setup) checks whether the project is ready to run without changing it.
- [Adaptive MCP settling](#adaptive-mcp-settling) returns when the page settles instead of after a fixed delay.

It also writes `test-results/summary.json`, with an `outcome` that tells apart failed tests (`failed`), errors outside tests such as a file that does not load (`error`), `no-tests`, `timedout` and `interrupted`; the counts; and for each failure its location, error, attachment paths and the command that reruns it. Exit codes stay the same.
## Agent mode

When Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot CLI or a tool that sets `AI_AGENT` runs the tests, an `agent` reporter replaces `list`, `line` and `dot`. It prints nothing for passing tests or their console output, prints each failure once (its last attempt, with the test's output), and ends with the counts and `npx playwright test --last-failed`. No colors, no rules of dashes, and the HTML report is never opened or served. 201 tests with one failure print 26 lines (888 bytes) instead of 425 (17.5 KB).

`agentMode: true` or `false` in the config sets it, and `FLASHWRIGHT_AGENT_MODE=1` or `0` overrides both. A `--reporter` on the command line and file reporters (`html`, `json`, `junit`, `blob`) are kept. `reporter: 'agent'` works outside agent mode too, with `outputFile` to move the JSON.

### Watch mode
### Structured test summary

It also writes `test-results/summary.json`, with an `outcome` that tells apart failed tests (`failed`), errors outside tests such as a file that does not load (`error`), `no-tests`, `timedout` and `interrupted`; the counts; and for each failure its location, error, attachment paths and the command that reruns it. Exit codes stay the same.

## Watch mode

`npx playwright test --watch` runs, in the terminal, the tests of each test file you save and of the test files that import a file you save, with the command's filters. This is Playwright's terminal watch mode, exposed without its environment-variable switch. Press `h` for the other commands: run everything, run failures, repeat, change the project, file or title filter, or show the browser.

A saved file's tests report 255 ms after the save instead of 1065 ms (4.2×; one test that opens a page, medians of 9): the changed files run right away instead of after listing every test, and while you read the results the next run's worker starts with its browser, and so does the process that loads test files, with babel already loaded.

### Warm session
## Warm session

Outside CI, the first `playwright test` in a project starts a session in the background. The session keeps the next run's runner process and workers started, and it keeps the browsers: a worker that exits hands its browser to the session instead of closing it, with the context reset as between two tests and with the renderer that has already compiled the application. The next run's first test starts as warm as the second test of a run.

Expand All @@ -45,9 +42,38 @@ Outside CI, the first `playwright test` in a project starts a session in the bac
| Shop app, 1 worker | 6321 ms | 2969 ms | 2839 ms (2.2×) |
| Shop app, 4 workers | 2593 ms | 1194 ms | 1003 ms (2.6×) |

<sub>Medians of 15 (one test) or 9 alternating runs with a 1.5 s pause before each, like an agent that edits between runs; the session prepares the next run during that pause. Reproduce with `BENCH_PAUSE=1500 node bench/run.mjs todomvc 4 9 stock,fork,fork:FLASHWRIGHT_SESSION=1`.</sub>
<sub>Medians from alternating runs with a 1.5 s pause before each, like an agent that edits between runs; the session prepares the next run during that pause. [Run counts](benchmarks.md#how-many-runs). Reproduce with `BENCH_PAUSE=1500 node bench/run.mjs todomvc 4 9 stock,fork,fork:FLASHWRIGHT_SESSION=1`.</sub>

Every run still gets new runner and worker processes, so changed tests, configs and environment variables are picked up as usual. A run whose environment, terminal or Flashwright install differs from the session's runs on its own, like without the session. A run returns once its results are reported; its workers hand their browsers over afterwards, unless a worker fixture of the project still has to tear down.

- **When it is on:** by default, except when the `CI` environment variable is set, when a debugger is attached, with `PWDEBUG`, `--ui` or `--debug`, and on Windows. A CI job usually runs its tests once, so a session would only hold memory there. `FLASHWRIGHT_SESSION=0` turns it off and `FLASHWRIGHT_SESSION=1` turns it on in CI.
- **What it holds:** one session per project directory, until 5 minutes after its last run (`FLASHWRIGHT_SESSION_TIMEOUT=<seconds>` changes that) or until Flashwright is reinstalled. While it waits, it keeps a runner, a worker for each kept browser and the browsers: about 0.4 GB after one-test runs and 1 GB after a 4-worker suite. Headed browsers are closed, not kept.

## Locator diagnostics

When an action or assertion waits for an element that never appears, its call log says which part of the locator stopped matching, whether a hidden element matches, and which similar elements exist:

```text
- waiting for getByRole('button', { name: 'Logout' })
- no element matched
- similar buttons: getByRole('button', { name: 'Log out' })
```

Suggestions cover roles, text, labels, placeholders, test IDs, `nth()` and chained locators. If nothing is close, the log points at iframes. Finding these suggestions takes at most 500 ms after the call has failed.

## Check the project setup

```bash
npx playwright doctor
npx playwright doctor --json
```

Doctor checks what a run needs without changing anything: Node, a single Playwright installation, a config that loads, tests for each project, browser executables and system libraries, and a display for headed projects. It also reports whether agent mode and the warm session are on. It exits with code 1 when a check finds something that would stop a run.

## Adaptive MCP settling

```bash
playwright mcp --adaptive-settle
```

Set this flag, or `timeouts.adaptiveSettle: true`, to return once the page settles instead of waiting a fixed 500 ms. In the measured API-save example, a click returns in 234 ms instead of 1014 ms.
17 changes: 15 additions & 2 deletions docs/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

[Back to the README](../README.md)

## How many runs?

| Benchmark | Measured runs | Reported value |
| --- | --- | --- |
| Playwright comparison matrix | 15 per implementation, scenario and worker setting, with the order alternating | Median time from command launch to exit |
| Other frameworks | 15 attempted per tool, file layout and worker setting, with the starting tool rotated | Median of passing runs; failed runs are excluded |
| Warm session, single test | 15 per implementation or session variant | Median complete-command time |
| Warm session, suites | 9 per implementation or session variant | Median complete-command time |

Warm-session runs pause for 1.5 seconds before each command; the pause is not timed.

The main matrix has the warm session off, as in CI. [Warm-session results and reproduction](agents.md#warm-session) are documented separately. These counts describe the published results, rather than the scripts' default iteration counts.

## Compared to other frameworks

<picture>
<source media="(prefers-color-scheme: dark)" srcset="media/competitors-dark.svg">
<img alt="The same 24 TodoMVC tests in 9 frameworks. With 1 worker: Flashwright 2.41 s, Bun test with Bun.WebView 4.39 s, Playwright 4.63 s, Selenium 5.48 s, Puppeteer 6.29 s, Nightwatch 6.45 s, WebdriverIO 10.57 s, Cypress 17.29 s, TestCafe 22.55 s. With 4 workers: Flashwright 1.54 s, Selenium 2.77 s, Bun 2.80 s, Puppeteer 2.98 s, Playwright 3.12 s, Nightwatch 3.38 s, WebdriverIO 4.91 s, TestCafe 9.28 s, Cypress 17.37 s." src="media/competitors.svg">
</picture>

Playwright's TodoMVC example suite, ported to each tool from one shared description of its 24 tests, so every tool runs the same actions and assertions with the same CSS selectors. Every tool drives the same Chromium 156 on the same machine with its own recommended waits (no fixed sleeps) and its default isolation between tests, and a run counts only when all 24 tests pass. Each number is the whole test command, median of 15 runs.
Playwright's TodoMVC example suite, ported to each tool from one shared description of its 24 tests, so every tool runs the same actions and assertions with the same CSS selectors. Every tool drives the same Chromium 156 on the same machine with its own recommended waits (no fixed sleeps) and its default isolation between tests, and a run counts only when all 24 tests pass. Each number is the median time for the whole test command.

File layout matters too. Cypress bundles each spec, and WebdriverIO, Selenium and Nightwatch start a browser session per file. That adds up when every test has its own file, which is how Playwright's example is laid out:

Expand All @@ -31,7 +44,7 @@ File layout matters too. Cypress bundles each spec, and WebdriverIO, Selenium an

![Bar chart: wall-clock time of 18 scenarios, Playwright vs Flashwright; Flashwright is 2.04× to 4.01× faster in each](media/benchmarks.svg)

Each bar is the complete `test` command, from launch to exit, median of 15 alternating runs on the same machine (6 CPUs, Linux), with Chromium's headless shell. Flashwright runs with its defaults apart from the [warm session](agents.md#warm-session), which is off, as in CI; nothing in the test code changes. The TodoMVC and SVGOMG suites are Playwright's own examples, the shop is a small single-page app with a sign-in setup project and 40 ms API latency, the admin app is a page of 8,500 elements whose 19 tests find them by role, label and text, and the other rows are 15-test files that each exercise one thing. Reproduce with `node bench/matrix.mjs 15`.
Each bar shows the median time for the complete `test` command, from launch to exit, on the same machine (6 CPUs, Linux) with Chromium's headless shell. Flashwright runs with its defaults apart from the [warm session](agents.md#warm-session), which is off, as in CI; nothing in the test code changes. The TodoMVC and SVGOMG suites are Playwright's own examples, the shop is a small single-page app with a sign-in setup project and 40 ms API latency, the admin app is a page of 8,500 elements whose 19 tests find them by role, label and text, and the other rows are 15-test files that each exercise one thing. Reproduce with `node bench/matrix.mjs 15`.

### Full results

Expand Down
Loading
Loading