What’s New in Pest v4? Master Browser Testing for Laravel with Playwright

Pest v4 introduces Playwright‑based browser testing, Laravel integration, flexible device modes, parallel execution, smoke and visual regression checks, test sharding, and new assertions, providing a comprehensive upgrade for PHP developers seeking modern, fast, and reliable test automation.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
What’s New in Pest v4? Master Browser Testing for Laravel with Playwright

Overview

On early morning PDT, the Pest team released version 4, introducing a brand‑new browser testing capability built on Playwright that supports Chrome, Firefox, Safari and lets developers write browser tests just like unit tests, especially for Laravel projects.

Example using Laravel:
it('may reset the password', function () {
    // access any laravel testing helpers...
    Notification::fake();

    // use RefreshDatabase trait, etc.
    $this->actingAs(User::factory()->create());

    $page = visit('/sign-in')
        ->on()->mobile()
        ->inDarkMode();

    $page->assertSee('Sign In')
        ->click('Forgot Password?')
        ->type('email', '[email protected]')
        ->press('Send Reset Link')
        ->assertSee('We have emailed your password reset link!')
        ->assertNoJavascriptErrors();

    Notification::assertSent(ResetPassword::class);
});

Key Features

Laravel integration : supports Event::fake(), assertAuthenticated() and model factories.

Flexibility : test in mobile, tablet, desktop modes and toggle dark/light mode.

Interactivity : full click, type, drag‑and‑drop support.

Performance : parallel execution, screenshot debugging, fast speed.

Installation & Usage

Install the Pest Browser plugin:

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

Use the visit() helper anywhere in your tests.

Run the suite with ./vendor/bin/pest.

Other Major Features

Smoke Tests & Visual Regression

Smoke testing : quickly visit a list of URLs and assert no JavaScript or console errors.

visit(['/', '/about', '/contact'])->assertNoSmoke();

Visual regression : compare screenshots with assertScreenshotsMatches().

visit(['/', '/about', '/contact'])->assertScreenshotsMatches();

Test Sharding & Parallelism

For large projects, Pest v4 adds sharding to run subsets of tests in CI pipelines, e.g.: ./vendor/bin/pest --shard=1/4 --parallel Combine with a matrix strategy to distribute jobs and greatly improve execution speed.

Type Coverage & Profanity Checks

Type coverage runs twice as fast and works with sharding.

Optional profanity plugin ( pestphp/pest-plugin-profanity) adds --profanity flag to enforce professional language.

Environment Skipping & New Assertions

skipLocally()

and skipOnCi() let you conditionally skip tests.

New assertions toBeSlug and not->toHaveSuspiciousCharacters() for string validation.

Pest v4 builds on PHPUnit 12, and the official installation guide (https://pestphp.com/docs/installation) and upgrade guide (https://pestphp.com/docs/upgrade) help both newcomers and experienced users get started quickly.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPBrowserPlaywrightLaravelPest
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.