pestphp / pestphp/pest

[Bug]: visit()->on()->desktop() only works when fully chained; fails when stored and used later

Open
#1,500 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
11.7k
Forks
538
Avg merge
4d 11h
Merged PRs (30d)
8

Description

What Happened

In Pest Browser tests, using on()->desktop() and storing the page in a variable (then calling interaction methods later like ->type() or ->fill() doesn’t behave like a single chained call, the page is reinitialized and a new tab/window gets opened on each interaction.

How to Reproduce

Use the attached minimal repo (Laravel + Pest + pest-plugin-browser).
Run only the browser login tests:

php artisan test --filter="LoginTest"

Observe:
These pass:

it('logs a user in via the login screen', function () {
    $user = User::factory()->create();

    $page = visit(route('login'));

    $page->fill('email', $user->email);
    $page->fill('password', 'password');
    $page->press('Log in');

    $this->assertAuthenticated();
    $page->assertUrlIs(route('dashboard'));
});

it('logs a user in when on()->desktop() is applied in a single method chain', function () {
    $user = User::factory()->create();

    $page = visit(route('login'))
        ->on()->desktop()
        ->fill('email', $user->email)
        ->fill('password', 'password')
        ->press('Log in');

    $this->assertAuthenticated();
    $page->assertUrlIs(route('dashboard'));
});

This fails:

it('logs a user in when on()->desktop() is applied then reused later (non-chained)', function () {
    $user = User::factory()->create();

    $page = visit(route('login'))->on()->desktop();

    $page->fill('email', $user->email);
    $page->fill('password', 'password');
    $page->press('Log in');

    $this->assertAuthenticated();
    $page->assertUrlIs(route('dashboard'));
});
Sample Repository

https://github.com/falfox/pest-browser-repro

Pest Version

4.0.4

PHP Version

8.4.11

Operation System

Linux (WSL2)

Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running php artisan test --filter="LoginTest" in the attached Laravel and Pest reproduction, comparing the chained and stored uses of visit()->on()->desktop(). Trace the visit(), on(), and desktop() entry points; done means later fill() and press() calls reuse the same page without opening new tabs, and the login assertions pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.