Search by

jackbayliss / laravel-playwright-dusk

jackbayliss

Playwright driver for Laravel Dusk. Same API, powered by Playwright

Package info

github.com/jackbayliss/laravel-playwright-dusk

pkg:composer/jackbayliss/laravel-playwright-dusk

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.2 2026-12-02 11:37 UTC

This package is auto-updated.

Last update: 2026-12-02 12:24:53 UTC


README

Warning

This isn't confirmed to work, there may be edge cases so try it out and create an issue if something is broken!

Laravel Playwright Dusk

A Playwright driver for Laravel Dusk. Same API, powered by Playwright.

Write your Dusk tests exactly as you always have. This package swaps the browser driver under the hood, replacing ChromeDriver with Playwright's Chromium.

Requirements

  • PHP 8.2+
  • Node.js 18+
  • Laravel 11+ / Dusk 8+

Installation

Install via Composer:

composer require jackbayliss/laravel-playwright-dusk

Then install the Node dependencies and Playwright's Chromium browser:

composer run setup

This runs npm install and npx playwright install chromium.

Usage

Extend JackBayliss\LaravelPlaywrightDusk\TestCase instead of Laravel\Dusk\TestCase in your test suite's base class:

use JackBayliss\LaravelPlaywrightDusk\TestCase as PlaywrightTestCase;

abstract class TestCase extends PlaywrightTestCase
{
}

Your individual tests are unchanged. browse(), visit(), assertSee(), type(), click(), and all other Dusk assertions work exactly as before:

class ExampleTest extends TestCase
{
    public function test_it_can_visit_a_page(): void
    {
        $this->browse(function ($browser) {
            $browser->visit('/')
                    ->assertSee('Welcome');
        });
    }
}

Running the Tests

Before running the tests, make sure your application's dev server is running on the URL configured in APP_URL (default: http://localhost:8000):

php artisan serve

Then run PHPUnit:

composer test
# or
vendor/bin/phpunit

Headed mode

To watch the browser while tests run, set the DUSK_HEADLESS_DISABLED environment variable:

DUSK_HEADLESS_DISABLED=1 vendor/bin/phpunit

Browser context options

To set options such as the viewport, user agent or locale for every browser context, override contextOptions():

protected function contextOptions(): array
{
    return [
        'viewport' => ['width' => 1920, 'height' => 1200],
        'userAgent' => 'Laravel/Dusk',
        'locale' => 'en-GB',
    ];
}

Remote Playwright server

To connect to an already running Playwright server (e.g. a separate Docker container running playwright run-server --mode launchServer) instead of starting one from node_modules, override playwrightServerUrl():

protected static function playwrightServerUrl(): ?string
{
    return 'browser:3000';
}

How it works

The package starts a Playwright server (playwright run-server) over a local WebSocket before the test class begins, connects a PHP WebSocket client to it, and maps every Dusk driver call (click, type, executeScript, etc.) to the equivalent Playwright protocol message. A fresh browser context and page are created for each browse() callback, giving the same isolation semantics as Dusk.

Running in CI

See the Workflow the project uses

Contributing

Pull requests are welcome. Make sure the test suite passes before opening a PR:

# Install dependencies
composer install
composer run setup

# Ensure you lint
composer run lint

# Start the workbench dev server
composer serve 

# Run tests in a seperate tab
composer test

Credits

A lot of the Playwright WebSocket communication layer in this package is heavily pulled from Pest's browser plugin. Huge credit to the Pest team for figuring out that side of things.

License

MIT