E2E Testing with Playwright and WordPress Playground
End-to-end testing verifies that your WordPress plugin or theme works correctly from a user's perspective — clicking buttons, filling forms, and navigating pages in a real browser. This guide shows how to combine Playwright with the WordPress Playground CLI to write reliable E2E tests without Docker, databases, or manual setup.
This guide assumes familiarity with WordPress plugin or theme development. For an introduction to using Playground in your development workflow, see WordPress Playground for Plugin Developers. For Blueprint configuration details, see Blueprints Getting Started.
Prerequisites
- Node.js 20+ and up
- A WordPress plugin/theme or an entire WordPress site to test
- Recommended: enable the
@typescript-eslint/no-floating-promisesESLint rule to catch missingawaiton async Playwright calls
Project setup
Install dependencies
From your plugin or theme root directory:
npm init -y
npm install --save-dev @playwright/test @wp-playground/cli
npx playwright install chromium
This installs Playwright as the test runner, the Playground CLI for creating WordPress instances, and the Chromium browser for test execution.
Configure Playwright
Create a playwright.config.ts file in your project root:
import { defineConfig } from "@playwright/test";
export default defineConfig({
testDir: "./tests/e2e",
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: 1,
reporter: "html",
timeout: 120_000,
expect: {
timeout: 30_000,
},
use: {
screenshot: "only-on-failure",
trace: "on-first-retry",
},
});
WordPress Playground needs more time to start than a typical web app. The 120-second test timeout and 30-second assertion timeout account for WordPress boot time and page loads. Setting workers: 1 prevents port conflicts when multiple tests share a Playground server.
By default, Playground will sign the port 9400. If you want to select a different port, pass port: [NEW_PORT_NUMBER] in the runCLI options to select a different port:
const cli = await runCLI({ command: "server", port: 9500, blueprint });
Then add baseURL: "http://localhost:9500" to the use section above. Note that testMatch defaults to **/*.spec.ts — customize it if your test files use a different naming pattern.
The WordPress Playground project uses even longer timeouts (300s test, 60s assertion) for its own tests. Start with the values above and increase if your CI environment is slower.