- What is Laravel Dusk used for?
- Laravel Dusk is Laravel's first-party end-to-end browser testing and automation package. It boots the real application and drives a browser, so it can validate routing, middleware, sessions, CSRF, and rendered Blade, Livewire, or Inertia output that feature tests cannot fully cover.
- How do I install Laravel Dusk in a Laravel app?
- Run composer require laravel/dusk --dev, then php artisan dusk:install. Commit the generated tests/Browser directory, DuskTestCase.php, phpunit.dusk.xml, and .env.dusk.* conventions, then run suites with php artisan dusk.
- Does Laravel Dusk require Selenium or a JDK?
- No. By default Dusk uses a standalone Chromedriver downloaded during dusk:install and does not require a JDK or Selenium server. You can still point it at an external Selenium grid with DUSK_DRIVER_URL when you need one.
- Which Laravel and PHP versions does Laravel Dusk support?
- The evaluation context covers Laravel 10 through 13 on PHP 8.x with PHPUnit 10 through 12 or Pest 3. Because Dusk 8.0.0 dropped Laravel 9 and PHPUnit 9, treat framework and Dusk upgrades as coupled events and verify the support matrix before upgrading.
- How do I run Laravel Dusk tests in CI?
- Install a matching Chrome and Chromedriver pair, pin the Chrome version in your CI image instead of relying on auto-download, and run php artisan dusk headlessly. Exclude Dusk from production builds with --no-dev and update the browser image deliberately.
- How do I stop Laravel Dusk tests from being flaky?
- Flakiness usually comes from implicit-wait timing, shared real-database state, and browser or driver drift rather than application code. Use explicit waits, stable @dusk selectors, page objects, isolated test data, and pinned Chrome and Chromedriver versions; Dusk 8.3.2 disabled smooth scrolling as a mitigation.
- Does Laravel Dusk support Firefox and Safari?
- Dusk is effectively Chromium-first by default. Firefox and Safari coverage requires an external Selenium grid configured through DUSK_DRIVER_URL and is not first-class, so confirm your required browser matrix before standardizing on Dusk.
- Is Laravel Dusk a dev dependency or should it be installed in production?
- Install Dusk as a dev-only dependency with composer require laravel/dusk --dev; its service provider is auto-discovered and gated to the local environment. Production builds should use --no-dev so Dusk and its browser tooling are not shipped.
- How does Laravel Dusk compare with Pest feature tests, Playwright, or Cypress?
- Pest and PHPUnit feature tests are faster and sufficient for most request and response assertions, while Dusk validates the full browser-rendered stack. For separately deployed SPAs or polyglot front ends, Playwright or Cypress usually offer broader ecosystem support, so scope Dusk to a few revenue-critical journeys instead of duplicating coverage.
- How should I handle database state in Laravel Dusk tests?
- Dusk issues real HTTP requests, so the browser and application processes need a dedicated testing database configured through .env.dusk.* rather than development data. Migrate and seed that database per run, and use per-process database isolation only if your database engine supports it cheaply. Keep tests independent so failures do not depend on execution order.