Skip to content

Commit 3015efe

Browse files
committed
feat(mobile): Extend mobile snapshot with selectors from getElements
- Use local fallback `getBestAndroidLocator(attrs)` and `getBestIOSLocator(attrs)` - Emit noisy mobile node roles from the snapshot
1 parent 041f208 commit 3015efe

5 files changed

Lines changed: 463 additions & 80 deletions

File tree

packages/elements/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ export { getElements } from './get-elements.js'
1717
export type { VisibleElementsResult } from './get-elements.js'
1818

1919
export { serializeWebSnapshot, serializeMobileSnapshot } from './snapshot.js'
20-
export type {
21-
WebSnapshotOptions,
22-
MobileSnapshotOptions
23-
} from './snapshot.js'
20+
export type { WebSnapshotOptions, MobileSnapshotOptions } from './snapshot.js'
2421
export type { JSONElement } from './locators/types.js'

packages/elements/src/locators/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ function processElement(element: JSONElement, ctx: ProcessingContext): void {
209209
return
210210
}
211211

212+
// Stash the best locator on the tree node so serializeMobileSnapshot
213+
// can reuse the full locator pipeline instead of recomputing.
214+
element.attributes._selector = locators[0][1]
215+
212216
const transformed = transformElement(element, locators, ctx)
213217
if (Object.keys(transformed.locators).length === 0) {
214218
return

packages/elements/src/mobile-elements.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ export async function getMobileVisibleElementsWithTree(
161161

162162
const tree = xmlToJSON(pageSource)
163163

164+
// Stash the source XML on the root element so serializeMobileSnapshot
165+
// can use the full locator pipeline without requiring it as a separate arg.
166+
if (tree) {
167+
tree.attributes._sourceXML = pageSource
168+
}
169+
164170
const elementLocators = generateAllElementLocators(pageSource, {
165171
platform,
166172
viewportSize,

0 commit comments

Comments
 (0)