What is Laravel Dusk
Laravel Dusk is an E2E testing tool that verifies your entire application by actually driving a browser.By default, Dusk can run tests via ChromeDriver without requiring a separate Selenium server.
Installation
First, install Google Chrome, then add Dusk as a development dependency.dusk:chrome-driver command.
Environment configuration (.env.dusk.local)
To use environment variables specific to Dusk, create a .env.dusk.{environment} file in the project root.For a local environment, use
.env.dusk.local.
.env is backed up and the contents of .env.dusk.local are temporarily applied.
Basic browser tests
Generate a test and run it withphp artisan dusk.
A basic example
visit(), type(), press(), and assertSee() are the most commonly used Dusk operations.
Page object pattern
When testing complex screens, generating a page object withdusk:page improves maintainability.
url() and elements() in tests/Browser/Pages/Login.php and reuse them from your tests.
Screenshots and debugging
Saving screenshots and console logs is effective for investigating failures.- Screenshots:
tests/Browser/screenshots - Console logs:
tests/Browser/console
Running in CI (GitHub Actions)
On GitHub Actions, start ChromeDriver and Laravel’s built-in server, then runphp artisan dusk.
Dusk execution flow
Official documentation
Laravel Dusk — Official documentation
For the complete Dusk API (waiting, assertions, keyboard operations, iframe operations, and more), see the official documentation.