feat: save page source on failed assertions - #240
Closed
jeremy-langevin-twc wants to merge 1 commit into
Closed
Conversation
jeremy-langevin-twc
force-pushed
the
feat/source-on-failure
branch
from
July 29, 2026 15:42
2b5956d to
44de2e0
Compare
Author
|
Closing this is not ready |
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.
This PR adds an opt-in capability to save the full HTML source of the page when a browser assertion fails, alongside the failure screenshot, console logs, and JavaScript errors that are already captured:
When enabled and a browser assertion fails, the page source is written to
tests/Browser/Source/and the failure message gains a line pointing to it, mirroring the existing screenshot line:Why: a screenshot cannot show
data-testattributes, hidden or collapsed elements, hydration state, or the actual markup a failing selector was matched against. Laravel Dusk stores page source on failure for exactly this reason, so this also closes a Dusk-parity gap.Why default-off: rendered pages can be large, and page HTML can expose PII more structurally than a screenshot does.
Naming:
source()follows the existing terse config grammar (debug(),diff(),headed()) and reuses the term the API already uses for page HTML (assertSourceHas()); the directory matches Dusk'stests/Browser/sourcein this repo's capitalization.Behavior details:
Source::cleanup()runs at suite boot exactly likeScreenshot::cleanup(), andtests/Browser/Sourceis gitignored like the screenshots directory.source().This is a backwards-compatible, opt-in addition (SemVer minor). Covered by unit tests for the support class and browser tests for both the enabled and disabled failure paths;
composer testpasses.