Avoid retrying side-effecting browser actions#227
Open
CalorieStar wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I had an issue where
click()was timing out on some pages, even though the click visibly occurred in the browser when using --debug.This appears to relate to the behaviour described in:
Related to pestphp/pest#1511
What changed
This PR updates
AwaitableWebpageso state-changing browser actions are no longer routed throughExecution::waitForExpectation().This includes actions such as:
clickpressfillcheckselectdragattachAssertions and read-style expectations still use the existing retry loop.
Why
Execution::waitForExpectation()retries the callback using a 1000ms Playwright timeout. That behaviour is useful for assertions, because repeatedly checking whether something is true is usually safe.For example, retrying an assertion such as
assertSee()is useful because the page may need time to update.However, this retry behaviour is less suitable for browser actions. Actions such as
click()andpress()can change the page, trigger JavaScript, submit forms, start navigation, or update application state.In these cases, the action may already have succeeded, but Pest may still report
Timeout 1000ms exceededif the operation did not complete within the 1000ms attempt window. Retrying the action can then cause further issues because:This PR avoids the pattern where a browser action visibly succeeds, but Pest still fails because the action was handled through the expectation retry loop.
Behaviour after this change
State-changing browser actions are attempted once and use the configured Playwright/browser timeout.
Assertions continue to be retried until the configured timeout expires.
This preserves the useful retry behaviour for assertions, while avoiding unsafe retries for actions that may alter browser or application state.
Side-effecting / state-changing actions
A side-effecting action is an operation that changes something.
In browser testing, this means the command does not merely observe the page. It may alter:
Examples include
click,press,fill,check,select,drag, andattach.These actions should be awaited using the configured action timeout, but not retried in the same way as assertions.