fix: Address snapshot and sanitization issues in packages/core#255
Merged
Conversation
Winify
marked this pull request as ready for review
July 19, 2026 20:20
…resent with child-text and sanitize page source XML that may contain HTML artifacts - Adding xml-parsing unit tests for sanitizePageSource - Including changeset
Winify
force-pushed
the
fix/elements-snapshot
branch
from
July 19, 2026 20:22
30333b2 to
f0cbe45
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.
What & why
Fixes two classes of bugs in the mobile element snapshot and XML parsing pipelines discovered during focused review for platform gaps (iOS, Android, WebView).
1. Element snapshot: child-text name enrichment (
element-snapshot.ts)The previous code promoted class-based Android locators to text-based selectors by reading child text. This had three defects:
UiSelector().text("...")resolves to the child TextView, not the clickable parent container the locator was generated for.Replaced with name enrichment: when an interactive Android element has only a class-based locator and no name, child text is pulled (BFS, length-guarded <100) and used as the element display name. The selector stays class-based, correctly targeting the parent.
2. XML parsing: sanitize page source before parsing (
xml-parsing.ts)Closes #240. iOS page source from XCUITest (especially WebView content) can contain HTML artifacts that
@xmldom/xmldomstrict XML parser rejects:&in URLs, ,©) not defined in XML<link>,<meta>,<br>,<img>) without explicit/>self-closureAdded
sanitizePageSource()called from bothxmlToJSONandxmlToDOM. Two-pass: escape bare&→&(preserving valid XML entities), then self-close 13 known HTML void elements. Platform-agnostic — runs for both Android and iOS.3.
escapeText: added\rand\tescaping (locator-generation.ts)Control characters in element text would produce invalid Java string literals in
UiSelector().text("...")selectors.Type of change
Packages touched
shared(types and contracts)core(framework-agnostic capture/reporting)service(WebdriverIO adapter)nightwatch-devtools(Nightwatch adapter)selenium-devtools(Selenium adapter)backend(server)app(UI)script(page-injected runtime)Notes for reviewers
getFirstChildTextreadsattributes.text(Android attribute). An iOS equivalent would need to checkname/label/value. Filed as follow-up._sourceXMLauto-detection added tojsonElementToSnapshotNodesto matchserializeMobileSnapshotbehavior.getBestAndroidLocatoruses~prefix forattrs.text(~maps tocontent-desc, nottexton Android). Same pattern ingetBestIOSLocatorforlabel/value. Fixing would change behavior for existing consumers — needs a separate change.