feat(test): attach accessibility tree on test failure via saveTreeOnFailure#111
Open
farhanlabib wants to merge 2 commits into
Open
feat(test): attach accessibility tree on test failure via saveTreeOnFailure#111farhanlabib wants to merge 2 commits into
farhanlabib wants to merge 2 commits into
Conversation
…ailure Screenshots show what the screen looks like when a test fails, but not why a locator didn't match. The accessibility tree carries that context — element labels, types, visibility flags, and bounds — which is exactly what you need to debug a failing getBy* call. Add saveTreeOnFailure: boolean to MobilewrightConfig. When enabled, the screen fixture calls viewTree() after a failure and attaches the result as view-tree-on-failure (JSON) to the HTML report, next to the existing screenshot. Opt-in, defaults to false, no impact on existing projects.
4dcb977 to
dd23065
Compare
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.
Motivation
When a test fails, the screenshot tells you what the screen looks like, but not why the locator didn't match. The accessibility tree has that answer — element labels, types, visibility flags, and bounds — but there's currently no way to capture it automatically on failure.
What changed
saveTreeOnFailure?: booleantoMobilewrightConfiginpackages/mobilewright/src/config.tssaveTreeOnFailurefixture option in@mobilewright/test(same pattern asautoAppLaunch) that reads the value from config, defaulting tofalsesaveTreeOnFailure: true, thescreenfixture callsviewTree()and attaches the result asview-tree-on-failure(application/json) to the test report — visible alongside the screenshot in the HTML reportThe feature is opt-in and off by default, so existing projects are unaffected.
Usage
The
view-tree-on-failureattachment appears in the HTML report under the failed test, containing the fullViewNode[]tree serialised as indented JSON.Test plan
saveTreeOnFailure: true— no attachment addedsaveTreeOnFailure: true—view-tree-on-failureJSON attachment appears in the HTML report alongside the screenshotsaveTreeOnFailure: false(default) — no JSON attachment, existingscreenshot-on-failurestill works normally