Does Laravel Work With Playwright?

Fully CompatibleLast verified: 2026-02-26

Laravel and Playwright work excellently together for end-to-end testing of PHP web applications with no framework-specific barriers.

Quick Facts

Compatibility
full
Setup Difficulty
Easy
Official Integration
No — community maintained
Confidence
high
Minimum Versions
Laravel: 8.0
Playwright: 1.40

How Laravel Works With Playwright

Laravel and Playwright integrate seamlessly because Playwright operates as an external browser automation tool that doesn't require framework-specific bindings. You run your Laravel application normally (via `php artisan serve` or on a deployed server), then point Playwright at it—whether you're using Node.js, Python, or other Playwright implementations. The typical workflow involves starting your Laravel dev server, optionally seeding test data via Laravel's database factories and seeders, then writing Playwright tests that navigate your app as a real user would. This separation of concerns means you test the actual rendered output rather than mocking, catching integration bugs that unit tests miss. For CI/CD pipelines, you'd typically spin up the Laravel container, run migrations and seeders, start the server, then run Playwright tests—all orchestrated through Docker or GitHub Actions. The main advantage over Laravel's built-in testing tools is cross-browser testing and visual regression detection, making it ideal for complex UIs where you need confidence across Chrome, Firefox, Safari, and mobile viewports.

Best Use Cases

Testing multi-step user flows like checkout processes, authentication, and role-based access control across real browsers
Visual regression testing for CSS changes to ensure design consistency across browser versions
Performance monitoring and accessibility testing of rendered Laravel pages in production-like environments
Testing third-party integrations (payment gateways, OAuth, APIs) in their actual browser context rather than mocked

Basic Laravel + Playwright Test

bash
npm install -D @playwright/test
typescript
import { test, expect } from '@playwright/test';

test.beforeEach(async ({ page }) => {
  await page.goto('http://localhost:8000');
});

test('user can register and login', async ({ page }) => {
  await page.click('a:has-text("Register")');
  await page.fill('input[name="name"]', 'John Doe');
  await page.fill('input[name="email"]', 'john@example.com');
  await page.fill('input[name="password"]', 'password123');
  await page.click('button[type="submit"]');
  
  await expect(page).toHaveURL('http://localhost:8000/dashboard');
  await expect(page.locator('text=Welcome, John')).toBeVisible();
});

Known Issues & Gotchas

warning

Laravel's dev server isn't always ready when tests start in CI environments, causing connection timeouts

Fix: Use wait utilities or health check endpoints before starting tests; services like `wait-on` npm package help here

warning

CSRF tokens and session cookies require explicit handling; Playwright doesn't automatically manage Laravel's session state between requests

Fix: Use Playwright's context and cookie management, or leverage Laravel's test helpers to generate valid tokens for POST requests

warning

Database state pollution across tests—Playwright doesn't have native transaction rollback like Laravel's test suite

Fix: Seed a fresh database state before each test using database factories, or wrap in transactions at the application level

info

Debugging failures is harder because you're testing the HTTP layer, not running in-process

Fix: Use Playwright's debug mode (`--debug` flag), screenshots on failure, and trace files for post-mortem analysis

Alternatives

  • Laravel Dusk + PHPUnit: Laravel's native E2E testing solution using ChromeDriver, tightly integrated but limited to single browser
  • Cypress + Laravel: Similar developer experience to Playwright with excellent debugging, but heavier setup and no Safari support
  • Selenium + Laravel: More mature but significantly more verbose, slower, and harder to maintain than Playwright

Resources

Related Compatibility Guides

Explore more compatibility guides