| name | playwright-auto-bootstrap |
| description | Make .NET/xUnit Playwright integration tests self-install missing Chromium browsers and skip cleanly if bootstrap cannot complete. |
Playwright Auto-Bootstrap
Use this when Playwright integration tests fail locally or in CI with Microsoft.Playwright.PlaywrightException messages such as Executable doesn't exist or Please run ... playwright install.
Pattern
- Put all Playwright-consuming test classes in an xUnit collection, for example
[Collection("PlaywrightBootstrap")].
- Add an
ICollectionFixture<T> fixture that runs once per test process.
- In
InitializeAsync, guard with a static SemaphoreSlim and static bool so parallel discovery/classes do not install browsers more than once.
- Probe availability by launching headless Chromium:
using var playwright = await Playwright.CreateAsync().ConfigureAwait(false);
await using var browser = await playwright.Chromium.LaunchAsync(new() { Headless = true }).ConfigureAwait(false);
- On missing-browser exceptions only, run:
var exitCode = Microsoft.Playwright.Program.Main(["install", "chromium"]);
- If install exits non-zero or throws, call
Assert.Skip(...) so environmental gaps do not red-bar the suite.
Notes
- Keep any CI-level
playwright install chromium step; it remains idempotent and makes the fixture a fast probe.
- Do not catch all Playwright exceptions as missing browsers. Only bootstrap for messages that indicate the executable/cache is missing; real browser/test failures should stay red.
- For headed-browser tests, installing
chromium also provides the headed executable; headless tests use the headless shell cache.