jackbayliss / laravel-playwright-dusk
Playwright driver for Laravel Dusk. Same API, powered by Playwright
Package info
github.com/jackbayliss/laravel-playwright-dusk
pkg:composer/jackbayliss/laravel-playwright-dusk
Requires
- php: ^8.2
- amphp/amp: ^3.1
- amphp/websocket-client: ^2.0
- laravel/dusk: ^8.0
- symfony/process: ^6.0|^7.0|^8.0
Requires (Dev)
- laravel/pint: ^1.29
- orchestra/testbench: ^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.0|^12.0|^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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