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
256 changes: 52 additions & 204 deletions README.md

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions bench/media/narrated-video/checklist.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Flashwright contributors. Licensed under Apache-2.0.

import { test, expect } from '@playwright/test';

const app = `<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Launch checklist</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; background: #101521; color: #eef2ff; font: 18px/1.5 system-ui, sans-serif; }
header { padding: 24px 48px; border-bottom: 1px solid #2b3346; display: flex; justify-content: space-between; }
header strong { letter-spacing: -.5px; } header span, .eyebrow { color: #a5b4fc; font-size: 14px; }
main { max-width: 780px; margin: 60px auto; }
.eyebrow { text-transform: uppercase; letter-spacing: 2px; }
h1 { font-size: 42px; letter-spacing: -1.5px; margin: 8px 0; }
.description { margin: 0 0 32px; color: #aab5cc; }
form { display: flex; gap: 12px; }
input { flex: 1; min-width: 0; border: 1px solid #45516d; border-radius: 10px; padding: 14px 18px; background: #1a2233; color: white; font: inherit; }
input:focus { outline: 2px solid #a5b4fc; outline-offset: 2px; }
button { border: 0; border-radius: 10px; padding: 14px 22px; background: #b7c4ff; color: #101521; font: 600 17px system-ui; cursor: pointer; }
ul { padding: 0; list-style: none; margin: 22px 0; }
li { display: flex; gap: 16px; align-items: center; padding: 20px; border: 1px solid #35405a; border-radius: 12px; background: #1a2233; }
li input { flex: none; width: 22px; height: 22px; accent-color: #a5b4fc; }
li:has(:checked) span { text-decoration: line-through; color: #9ba7bd; }
#empty { text-align: center; padding: 28px; border: 1px dashed #35405a; border-radius: 12px; color: #aab5cc; }
footer { display: flex; justify-content: space-between; color: #aab5cc; font-size: 14px; }
#status { color: #9ce4bc; }
</style></head><body>
<header><strong>Flashwright</strong><span>Example app</span></header>
<main>
<div class="eyebrow">Ready to ship</div>
<h1>Launch checklist</h1>
<p class="description">One less thing to remember before your next release.</p>
<form><input aria-label="New task" placeholder="What needs to happen?"><button>Add task</button></form>
<ul aria-label="Tasks"></ul>
<p id="empty">Your checklist is empty. Add your first task.</p>
<footer><span id="count">0 tasks remaining</span><span id="status" role="status">All changes saved</span></footer>
</main>
<script>
const form = document.querySelector('form');
const input = form.querySelector('input');
const list = document.querySelector('ul');
form.onsubmit = event => {
event.preventDefault();
if (!input.value.trim()) return;
const item = document.createElement('li');
const check = document.createElement('input');
check.type = 'checkbox';
check.setAttribute('aria-label', 'Complete ' + input.value);
const label = document.createElement('span');
label.textContent = input.value;
item.append(check, label);
list.append(item);
input.value = '';
document.getElementById('empty').hidden = true;
check.onchange = update;
update();
};
function update() {
const left = list.querySelectorAll('input:not(:checked)').length;
document.getElementById('count').textContent = left + (left === 1 ? ' task remaining' : ' tasks remaining');
}
</script></body></html>`;

test('adds a task and marks it done', async ({ page, narrate }) => {
await page.setContent(app);
await narrate('Start with an empty launch checklist.');
await page.getByRole('textbox', { name: 'New task' }).fill('Ship the README');
await page.getByRole('button', { name: 'Add task' }).click();
await expect(page.getByRole('listitem')).toHaveText('Ship the README');
await narrate('Add a task before the next release.');
await page.getByRole('checkbox', { name: 'Complete Ship the README' }).check();
await expect(page.getByText('0 tasks remaining')).toBeVisible();
await narrate('Mark it done. The checklist is clear.');
});
16 changes: 16 additions & 0 deletions bench/media/narrated-video/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Flashwright contributors. Licensed under Apache-2.0.

import { defineConfig } from '@playwright/test';

export default defineConfig({
testDir: '.',
testMatch: 'checklist.spec.ts',
workers: 1,
reporter: 'list',
use: {
viewport: { width: 1280, height: 720 },
launchOptions: process.env.FLASHWRIGHT_EXAMPLE_CHROMIUM
? { executablePath: process.env.FLASHWRIGHT_EXAMPLE_CHROMIUM }
: {},
},
});
29 changes: 29 additions & 0 deletions bench/media/narrated-video/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Flashwright contributors. Licensed under Apache-2.0.

// Record the same test in both modes, then make a silent side-by-side README preview.
// Run from the repository root: node bench/media/narrated-video/render.ts
import { execFileSync } from 'node:child_process';
import { copyFileSync, mkdirSync } from 'node:fs';

mkdirSync('docs/media', { recursive: true });
for (const mode of ['video', 'demo']) {
const output = `workbench/narrated-${mode}`;
execFileSync(process.execPath, [
'packages/playwright/cli.js', 'test',
'--config=bench/media/narrated-video/playwright.config.ts',
`--${mode}`, `--output=${output}`,
], { stdio: 'inherit', env: { ...process.env, FLASHWRIGHT_SESSION: '0' } });
copyFileSync(`${output}/video.mp4`, `docs/media/narrated-${mode}.mp4`);
}

const common = ['-hide_banner', '-loglevel', 'error', '-y'];
execFileSync('ffmpeg', [...common,
'-i', 'docs/media/narrated-video.mp4', '-i', 'docs/media/narrated-demo.mp4',
'-filter_complex', '[0:v]scale=640:-2,setsar=1,pad=640:400:0:40:color=0x101521,drawtext=font=Arial:text=--video:fontcolor=white:fontsize=22:x=(w-tw)/2:y=8,tpad=stop_mode=clone:stop_duration=60[left];[1:v]scale=640:-2,setsar=1,pad=640:400:0:40:color=0x101521,drawtext=font=Arial:text=--demo:fontcolor=white:fontsize=22:x=(w-tw)/2:y=8,tpad=stop_mode=clone:stop_duration=60[right];[left][right]hstack=inputs=2[v]',
'-map', '[v]', '-t', '22', '-an', '-c:v', 'libx264', '-crf', '23', '-pix_fmt', 'yuv420p',
'-movflags', '+faststart', 'workbench/narrated-comparison.mp4',
], { stdio: 'inherit' });
execFileSync('ffmpeg', [...common, '-i', 'workbench/narrated-comparison.mp4',
'-filter_complex', 'fps=6,scale=1000:-2,split[a][b];[a]palettegen=stats_mode=diff[p];[b][p]paletteuse=dither=bayer',
'-loop', '0', 'docs/media/narrated-comparison.gif',
], { stdio: 'inherit' });
53 changes: 53 additions & 0 deletions docs/agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Running tests with agents

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

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).

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.

`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

`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

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.

| Run, 1.5 s after the previous one | Playwright | Flashwright | Flashwright, warm session |
| --- | ---: | ---: | ---: |
| One TodoMVC test | 673 ms | 240 ms | 76 ms (8.9×) |
| TodoMVC suite, 1 worker | 3648 ms | 1023 ms | 900 ms (4.1×) |
| TodoMVC suite, 4 workers | 1804 ms | 728 ms | 508 ms (3.6×) |
| SVGOMG suite, 1 worker | 1725 ms | 510 ms | 377 ms (4.6×) |
| SVGOMG suite, 4 workers | 1257 ms | 476 ms | 278 ms (4.5×) |
| 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>

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.
70 changes: 70 additions & 0 deletions docs/benchmarks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Benchmarks

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

## 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.

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:

| Tool | Grouped, 1 worker | Grouped, 4 workers | One test per file, 1 worker | One test per file, 4 workers |
| --- | ---: | ---: | ---: | ---: |
| **Flashwright** | **2.41 s** | **1.54 s** | **2.41 s** | **1.47 s** |
| Bun test + Bun.WebView | 4.39 s | 2.80 s | 4.41 s | 3.99 s |
| Playwright | 4.63 s | 3.12 s | 4.70 s | 2.92 s |
| Selenium + Mocha | 5.48 s | 2.77 s | 10.27 s | 4.81 s |
| Puppeteer + Jest | 6.29 s | 2.98 s | 6.14 s | 2.77 s |
| Nightwatch | 6.45 s | 3.38 s | 11.48 s | 5.44 s |
| WebdriverIO | 10.57 s | 4.91 s | 23.67 s | 9.21 s |
| TestCafe | 22.55 s | 9.28 s | 22.61 s | 9.32 s |
| Cypress | 17.29 s | 17.37 s¹ | 38.44 s | 38.41 s¹ |

<sub>¹ Cypress runs one spec file at a time: parallel runs need Cypress Cloud. Versions: Flashwright 1.64.1-flashwright.8, Playwright 1.64.1, Cypress 16.2.1, WebdriverIO 10.1.0, selenium-webdriver 4.52.0, Puppeteer 25.16.0, TestCafe 3.7.7, Nightwatch 3.16.0, Bun 1.4.4. `Bun.WebView` is an experimental browser API without assertions or text locators; its port waits with a small helper. Bun failed 1 of its 60 runs (not counted). Setup, every port and how to reproduce: [bench/competitors](../bench/competitors). Found a faster setting for a tool, or a port its users wouldn't write that way? Issues and pull requests are welcome.</sub>

## Compared to Playwright

![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`.

### Full results

| Scenario | Tests | Workers | Playwright | Flashwright | Speedup |
| --- | ---: | ---: | ---: | ---: | ---: |
| TodoMVC example suite | 24 | 1 | 3670 ms | 1011 ms | 3.63× |
| TodoMVC example suite | 24 | 4 | 1812 ms | 734 ms | 2.47× |
| SVGOMG example suite | 6 | 1 | 1738 ms | 511 ms | 3.40× |
| SVGOMG example suite | 6 | 4 | 1253 ms | 498 ms | 2.52× |
| Shop app (setup project, 40 ms API latency) | 18 | 1 | 6297 ms | 2967 ms | 2.12× |
| Shop app | 18 | 4 | 2599 ms | 1194 ms | 2.18× |
| Admin app (8,500 elements, role, label and text locators) | 19 | 1 | 6805 ms | 3031 ms | 2.25× |
| Admin app | 19 | 4 | 2699 ms | 1320 ms | 2.04× |
| Trivial tests | 15 | 1 | 1024 ms | 341 ms | 3.00× |
| Click + assertion | 15 | 1 | 1611 ms | 402 ms | 4.01× |
| Assertion on a delayed update | 15 | 1 | 1191 ms | 473 ms | 2.52× |
| Navigation | 15 | 1 | 1266 ms | 415 ms | 3.05× |
| Fixture setup only | 15 | 1 | 1170 ms | 351 ms | 3.33× |
| Form submit to a backend (20 ms API) | 15 | 1 | 1983 ms | 729 ms | 2.72× |
| `toHaveScreenshot()` against a baseline | 15 | 1 | 2333 ms | 963 ms | 2.42× |
| `page.screenshot()` to a file | 15 | 1 | 1915 ms | 765 ms | 2.50× |
| Suite with real failures (every third test) | 15 | 1 | 4334 ms | 1154 ms | 3.76× |
| Expected failures (250 ms timeout each) | 15 | 1 | 4757 ms | 1498 ms | 3.18× |
| A single test, as an agent re-runs it | 1 | 1 | 593 ms | 184 ms | 3.22× |
| A single TodoMVC test | 1 | 1 | 666 ms | 240 ms | 2.77× |

The one-file scenarios run in a single worker whatever the setting, so their 4-worker runs (2.49×–4.16×) match the ones above.

Some of that time belongs to the app: explicit delays and server responses still take as long as they take. Subtract those waits, and Flashwright's remaining overhead is 3.0×–4.5× lower than Playwright's:

| Scenario | Workers | The application's waits | Playwright adds | Flashwright adds | |
| --- | ---: | ---: | ---: | ---: | ---: |
| Form submit to a backend | 1 | 15 × 20 ms | 1683 ms | 429 ms | 3.92× |
| Assertion on a delayed update | 1 | 15 × 8 ms | 1071 ms | 353 ms | 3.03× |
| Shop app | 1 | ~2.1 s of API time | 4181 ms | 924 ms | 4.52× |
| Shop app | 4 | ~1.16 s / ~0.83 s of API time | 1435 ms | 361 ms | 3.98× |
Loading
Loading