Skip to main content

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.
The official documentation also recommends Pest 4 browser tests for new projects. Use this page when you’re using Dusk on an existing project, or when you want to use Dusk’s API.

Installation

First, install Google Chrome, then add Dusk as a development dependency.
To adjust the ChromeDriver version, use the 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.
While Dusk is running, .env is backed up and the contents of .env.dusk.local are temporarily applied.

Basic browser tests

Generate a test and run it with php artisan dusk.
To re-run only the failing tests:

A basic example

visit(), type(), press(), and assertSee() are the most commonly used Dusk operations.
Do not use RefreshDatabase in Dusk tests. As noted in the official documentation, use DatabaseMigrations or DatabaseTruncation to reset data between tests.

Page object pattern

When testing complex screens, generating a page object with dusk:page improves maintainability.
Define 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 run php 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.
Last modified on July 13, 2026