fix(harmonyos): label snapshot nodes with their visible text

Merged
TH
7d ago
+579-3

Summary

ArkUI reports a control's words outside the control. A Toggle answers with its resource id and no text; the string on the screen is a sibling Text of the row container, and every such container reports the same id (SwitchMenuComponent). The mapping had nowhere to take the words from, so label fell through to the id (#4906).

It now reads them off the control's row: the nearest container that holds the control and no other control. That is the settings row of a Toggle, and the title bar of a back Button. A control holding another control takes no label — those words are the nested control's own, and both would answer one selector. Borrowed text must contain a letter, so the clock digits and padding blanks ArkUI also reports stay out of labels while a node's own value reports them unchanged. The resource id stays the identifier.

That fixes #4907 at this site: the unlabeled back button's press fell through to the nearest label in the whole capture, the merged status-bar window's StatusBarBridgeView, 136 px above it. The title bar now names the button.

Fixes #4906
Fixes #4907

Before / after

snapshot -i on Settings > Developer options:

- @e10 [toggle] "entry_toggle_usb_debug"
+ @e10 [toggle] "USB debugging"

- press @e1 -> "refLabel": "StatusBarBridgeView"
+ press @e1 -> "refLabel": "Developer options"

Validation

  • pnpm lint, pnpm typecheck, pnpm format, pnpm check:layering, pnpm run check:package, npx vitest run --project unit-core (all green)
  • New fixture tests from a sanitized real device dump: 4 fail on 0.22, pass here
  • Live on a nova 14 (OpenHarmony 6.1.1, 4UQ9K25710015363), branch CLI, isolated home:
$ agent-device open com.huawei.hmos.settings --platform harmonyos --session hmos-labels
$ agent-device snapshot -i --session hmos-labels
@e1 [button] "Developer options"
@e3 [toggle] "Developer options"
@e10 [toggle] "USB debugging"
$ agent-device press @e1 --session hmos-labels --json
  "message": "Tapped @e1 (108, 189)",
  "refLabel": "Developer options",
  "selectorChain": ["role=\"button\" label=\"Developer options\""]
$ agent-device close --session hmos-labels
$ agent-device daemon stop

Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.