feat: use multiple browsers for individual tests#202
Closed
nexxai wants to merge 4 commits intopestphp:4.xfrom
Closed
feat: use multiple browsers for individual tests#202nexxai wants to merge 4 commits intopestphp:4.xfrom
nexxai wants to merge 4 commits intopestphp:4.xfrom
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.
Problem
This PR was inspired by the fact that Safari's printing functionality works differently than Chrome and Firefox. I needed a way to expose certain individual tests to multiple browsers without having to run the entire test suite for each one. Previously, there was no way to run a single test against multiple browser types within the same test execution; you either have to hard-code the browser in your
Pest.phpconfiguration file, or run your entire test suite using the--browser safarisyntax.Proposed Solution
I added a new browser() method to PendingAwaitablePage that accepts an array of BrowserType enums. This allows developers to run the same assertions across multiple browsers sequentially.
Usage Examples:
Fetch
/pagein both Chrome and Firefox, using dark mode:If you want the results from each browser:
Technical Details
MultiBrowserPendingPageclass that holds multiplePendingAwaitablePageinstances__callmagic method to forward method calls (likeinDarkMode(),withLocale(), etc.) to all pending pages (Note: Phpstan wasn't understanding the magic here, which is why I added the //ignore-line comment. If you are aware of a better way of handling this, please share and I'll update it)each()method runs the callback on each browser sequentially, closing and reconnecting between browsers to work within Playwright's single-browser limitationcloseOthers()method to Playwright class to facilitate switching between browsersClient::disconnect()to properly close the WebSocket connection