Does Fastify Work With Playwright?

Fully CompatibleLast verified: 2026-02-26

Fastify and Playwright work together seamlessly—use Fastify to build your application and Playwright to test it end-to-end.

Quick Facts

Compatibility
full
Setup Difficulty
Easy
Official Integration
No — community maintained
Confidence
high
Minimum Versions
Fastify: 3.0.0
Playwright: 1.0.0

How Fastify Works With Playwright

Fastify and Playwright are complementary tools that don't depend on each other. Fastify serves as your application backend, while Playwright runs as a separate process to automate browser testing against that running server. The typical workflow involves starting a Fastify server (often on localhost), then using Playwright to spawn browsers and interact with your application through its HTTP endpoints.

Developers appreciate this combination because Fastify's startup speed and low overhead make test suites faster—the server boots quickly for each test run. Playwright handles all the browser automation, so you get true end-to-end testing with real browser rendering, JavaScript execution, and network conditions. You'll manage the server lifecycle in your test setup/teardown hooks, typically using beforeAll/afterAll in your test framework.

The architecture is straightforward: Fastify runs on one port, Playwright connects to it via localhost URLs. For CI/CD pipelines, this is especially clean since both tools are Node.js-based and don't require external services. No special plugins or middleware are needed on the Fastify side—just expose your application normally.

Best Use Cases

Integration testing a Fastify REST API with Playwright to verify UI-to-backend workflows
Testing authentication flows across multiple pages in a Fastify-served SPA
Cross-browser compatibility testing for Fastify-rendered server-side applications
Load testing with Playwright while monitoring Fastify server performance metrics

Quick Setup

bash
npm install fastify playwright @playwright/test
javascript
// server.js
const fastify = require('fastify')();
fastify.get('/', async () => ({ message: 'Hello' }));
fastify.listen({ port: 3000 });

// test.spec.js
const { test, expect } = require('@playwright/test');

test('homepage loads', async ({ page }) => {
  await page.goto('http://localhost:3000');
  const heading = await page.locator('text=Hello').isVisible();
  expect(heading).toBeTruthy();
});

// playwright.config.js
module.exports = {
  use: { baseURL: 'http://localhost:3000' },
  webServer: {
    command: 'node server.js',
    url: 'http://localhost:3000',
    reuseExistingServer: false,
  },
};

Known Issues & Gotchas

warning

Server not ready when tests start

Fix: Use Fastify's .ready() promise or add a health-check endpoint that Playwright polls before running tests

warning

Port conflicts in parallel test execution

Fix: Use dynamic port assignment (port 0) or a port manager library, and pass the actual port to Playwright programmatically

info

Stale server state between tests

Fix: Reset database state and clear caches between test runs using beforeEach hooks or consider spinning up fresh server instances per test

warning

Playwright timeouts on slow Fastify routes

Fix: Configure Playwright timeouts appropriately and monitor Fastify performance—use Fastify's built-in logging to identify slow handlers

Alternatives

  • Express.js with Cypress—similar setup but Cypress is browser-specific and more opinionated
  • Next.js with Playwright—full-stack framework with built-in server; good for SSR applications
  • Koa.js with Selenium—lighter framework option, though Selenium is less modern than Playwright

Resources

Related Compatibility Guides

Explore more compatibility guides