Web Development 5-8 minutes

Browser Testing in Laravel 13: Pest with Playwright vs Dusk

Diego Cortés
Diego Cortés
Full Stack Developer & SEO Specialist
Share:
Browser Testing in Laravel 13: Pest with Playwright vs Dusk
Image generated with AI

The official Laravel 13 documentation recommends Pest 4 for browser testing: it drives Playwright, waits automatically, and runs in parallel, with E2E suites dropping from 12 minutes to 90 seconds in CI. This guide shows you how to install it and write your first test.

Why Laravel 13 No Longer Pushes You Toward Dusk

The Official Recommendation Change: Pest 4 and Its Browser Testing

Pest 4 was introduced as the project's biggest release yet, featuring powerful browser testing with parallel support and full Laravel integration. The Laravel 13.x documentation itself acknowledges that Pest 4's browser testing offers significant performance and usability improvements compared to Laravel Dusk. In practice, that means for a new project the default choice is no longer installing Dusk but setting up Pest Browser Testing.

What It Means for New Projects and for Teams Already Using Dusk

If you are starting a project today, the recommended path is Pest with Playwright. If you already have a large Dusk suite, you do not have to migrate all at once: Dusk still works and is maintained, and migration can happen test by test. The important thing is not to assume that what was the official recommendation in Laravel 10 or 11 still is in Laravel 13.

Dusk vs Pest Browser Testing: Key Differences

ChromeDriver vs Playwright: Which Browser Each One Drives

Dusk uses a standalone ChromeDriver: no JDK and no Selenium, but always Chrome, with the fragility of driver version matching. Pest 4 does not use Selenium or WebDriver: it drives Playwright, which manages its own browser inside the same test process. That removes an entire class of synchronization problems between driver version and browser version.

Automatic Waits and Test Stability

The difference you notice most when writing tests is waiting. With Dusk you get used to implicit waits and sometimes explicit ones when the page is still loading. Pest Browser Testing automatically waits for the page to finish loading before continuing, which makes tests more stable and less prone to intermittent timing failures.

Parallelism: --parallel and --shard in CI

Pest 4 ships with parallelism support out of the box. With --parallel it distributes tests across multiple processes, and with --shard you can split the suite into shards that run on different CI runners. Dusk also allows parallelism, but the combination of auto-waits, Playwright, and sharding is what produces the most dramatic time cuts.

Installing Pest Browser Testing in Laravel 13

Installation takes three steps: add the Pest plugin, install Playwright, and download the browsers.

composer require pestphp/pest-plugin-browser --dev
npm install playwright@latest
npx playwright install

composer require pestphp/pest-plugin-browser and npm install playwright

The Pest plugin is installed as a dev dependency with Composer. Playwright is installed from Node, so you need Node available in your environment. Both commands are fast and do not touch your production configuration.

npx playwright install: The Browsers

The last step downloads the browser binaries that Playwright will control. You run it once in development, and it is also part of the CI runner setup, because without those binaries the tests cannot start.

Your First Browser Test with Pest

A typical login test is written with an expressive API: visit a URL, fill in the form, click, and assert that the expected content appears.

it('lets a user sign in', function () {
    $user = User::factory()->create();

    $this->browse(function (Browser $browser) use ($user) {
        $browser->visit('/login')
            ->fill('email', $user->email)
            ->fill('password', 'password')
            ->click('button[type="submit"]')
            ->assertSee('Welcome back');
    });
});

visit, fill, click, and assertSee: The Login Flow

visit navigates to the URL, fill populates the fields, click presses the button, and assertSee checks that the text appears on the page. The interesting part is that you do not need manual waits: Pest waits for the page to load before each interaction, so the test reads like a description of what the user does.

Leveraging Laravel Utilities Inside the Test

Inside the same test you can use the whole Laravel testing stack: factories to create data, event faking to simulate events, and authentication assertions while navigating in a real browser. That gives you the best of both worlds: real data from your application and an actual browser session.

Migrating from Dusk to Pest Without Breaking the Suite

Method Mapping: visit, type, press, assertSee

If you come from Dusk, migration is almost mechanical because the API is very similar. visit stays the same, Dusk's type becomes fill in Pest, and press becomes click.

// Dusk
$browser->visit('/login')
    ->type('@email', 'test@example.com')
    ->press('Login')
    ->assertSee('Welcome');

// Pest
$browser->visit('/login')
    ->fill('email', 'test@example.com')
    ->click('button[type="submit"]')
    ->assertSee('Welcome');

Incremental Test-by-Test Migration

You do not need to migrate the whole suite in one day. With the mapping above, you can convert Dusk tests to Pest one at a time, verifying that each migrated test still passes before moving to the next. That is the safe path for teams with hundreds of E2E tests.

Running E2E Tests in CI

--parallel and --shard to Cut Down Time

In CI, browser tests run like any Pest test, but with parallelism to take advantage of multiple cores or multiple runners.

./vendor/bin/pest --parallel
./vendor/bin/pest --parallel --shard=1/4
./vendor/bin/pest --parallel --shard=2/4

The Documented Case: From 12 Minutes to 90 Seconds

A documented case from May 2026 shows an E2E suite going from about 12 minutes with Dusk to about 90 seconds with Pest 4 Browser Testing, combining auto-waits, --parallel, and --shard. Results vary by machine and suite, but the order of magnitude is not unusual: fewer manual waits and more parallel processes change total time dramatically.

When Dusk Still Makes Sense

Dusk remains a valid, maintained option, especially if your suite is already written with it and working well. Migrating just to migrate adds nothing if your tests are stable and your team does not need the extra parallelism. The Pest recommendation is for new projects and for teams that want to cut CI time; if you are comfortable with Dusk, there is no rush to switch.

Conclusion

Laravel 13 committed to Pest 4 for browser testing, and the combination of Playwright, automatic waits, and built-in parallelism makes E2E tests more stable and much faster in CI. Dusk is not going away, but for new projects the official answer is clear. Try Pest Browser Testing with a login test and decide with real data in hand. Keep reading the blog for more Laravel and testing guides.

Categories