Skip to content

feat: add saving storage states - #207

Open
veljkho wants to merge 3 commits into
pestphp:4.xfrom
veljkho:add/feature/storage-state
Open

veljkho wants to merge 3 commits into
pestphp:4.xfrom
veljkho:add/feature/storage-state

Conversation

@veljkho

@veljkho veljkho commented Apr 6, 2026 •

Copy link
Copy Markdown

Adds support for Playwright's storage state feature, allowing tests to save and restore browser context state (cookies and localStorage). The primary use case is skipping repetitive login flows across tests.

After a login flow, save the authenticated state:

// tests/Browser/Auth/LoginTest.php
test('store authenticated state', function (): void {
    visit('/login')
        ->fill('#email', 'admin@example.com')
        ->fill('#password', 'secret')
        ->click('Login')
        ->assertUrlContains('/dashboard')
        ->saveStorageState('logged_in');  <--- this
});

All other tests just reuse it:

// tests/Browser/DashboardTest.php
test('can see dashboard', function (): void {
    visit('/dashboard')
        ->withStorageState('logged_in')  <--- this
        ->assertSee('Welcome back');
});

test('can see settings', function (): void {
    visit('/settings')
        ->withStorageState('logged_in')  <--- this
        ->assertSee('Account Settings');
});

This will save significant time when executing e2e browser tests that include logging before each test.

@veljkho veljkho changed the title Add feature saving storage states feat: add saving storage states Apr 6, 2026
Veljko Vujanovic and others added 3 commits October 9, 2026 16:46
This adds feature to save browser's storage state just like in Playwright
@veljkho
veljkho force-pushed the add/feature/storage-state branch from 92b5ad7 to 81a4386 Compare October 9, 2026 14:47
@veljkho

veljkho commented Oct 9, 2026

Copy link
Copy Markdown
Author

Hi @nunomaduro 👋

I opened this in April and it's had no review yet, so I wanted to check whether this is something you'd want in Pest Browser.

It adds Playwright-style storage state: saveStorageState('logged_in') after a login, then withStorageState('logged_in') in later tests. That lets tests skip repeating the login flow.

Two questions:

Is this a feature you'd accept? If not, I'll close the PR.
Should it target 4.x or 5.x? I based it on 4.x, but I see 5.x is the default branch. I'm happy to rebase or retarget it.
I've just rebased it onto the latest 4.x. If you're interested, I can add more tests or docs, or change the API. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant