Skip to content

fix: reuse a single PendingAwaitablePage in On::__call() - #274

Open
DaniilSkLi wants to merge 1 commit into
pestphp:5.xfrom
DaniilSkLi:fix/on-reuse-pending-page
Open

DaniilSkLi wants to merge 1 commit into
pestphp:5.xfrom
DaniilSkLi:fix/on-reuse-pending-page

Conversation

@DaniilSkLi

Copy link
Copy Markdown

Every magic method call on On created a fresh PendingAwaitablePage and a
new browser context, so separate (non-chained) calls lost state:

// ❌ BROKEN before this PR — each call opens a new browser context
$page = visit('/')->on()->mobile();
$page->click('@search-button');        // page #1
$page->assertVisible('@search-modal'); // page #2 — state lost

This PR:

  • Caches the PendingAwaitablePage instance in On::__call() (the same lazy
    pattern PendingAwaitablePage already uses for AwaitableWebpage), keeping
    the class readonly
  • Adds missing @mixin Webpage|AwaitableWebpage to On so IDEs resolve
    forwarded methods without relying on recursive @mixin resolution
  • Adds regression tests covering separate calls with a device (desktop, mobile,
    iPhone14Pro) and without choosing a device

Fixes pestphp/pest#1931

Every magic method call on On created a fresh PendingAwaitablePage and
a new browser context, so separate (non-chained) calls lost state:

    $page = visit('/')->on()->mobile();
    $page->click('@search-button');        // page pestphp#1
    $page->assertVisible('@search-modal'); // page pestphp#2 — state lost

Cache the instance like PendingAwaitablePage already does, and add
Webpage/AwaitableWebpage mixins to On so IDEs resolve methods without
relying on recursive @mixin resolution.

Fixes pestphp/pest#1931
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.

[Bug]: On::__call() creates a new browser context on every method call - breaks stateful page interactions

1 participant