Skip to content

Commit 120e689

Browse files
committed
fix(android): read hint-showing from the helper so a cleared field verifies
Live Pixel 9 emulator, adb-shell channel: clearing the Settings search field succeeded on the device but reported 'Android fill verification failed', because a cleared EditText dumps its HINT as text — getText() returns the hint for an empty field on modern Android, so 'Search settings' read back as a residual value. This is the same placeholder-as-value trap the Apple runner already handles with treatingPlaceholderAsEmpty. The helper now emits hint-showing (isShowingHintText, API 26+), the hierarchy parser carries it, and fill verification matches against the field's VALUE — hint-only text is an empty value, for empty and non-empty expectations alike. A field whose real value equals its hint string keeps failing the clear check: only the authoritative flag, never the text, says it is a hint. Raw uiautomator dumps carry no such fact and keep the fail-closed behavior. Live evidence, both admission channels, after this fix: test-ime and adb-shell clears both report Filled 0 chars with the field back on its placeholder; the pre-fix adb-shell run failed closed (never a false success).
1 parent 95a5238 commit 120e689

4 files changed

Lines changed: 61 additions & 7 deletions

File tree

‎android/snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/AccessibilityTreeXml.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ static void appendNode(
3535
appendWindowMetadata(xml, windowMetadata);
3636
}
3737
appendNonEmptyAttribute(xml, "text", node.getText());
38+
// getText() returns the HINT for an empty field on modern Android, so `text` alone cannot
39+
// distinguish a cleared field from one whose value equals its hint; only this flag can
40+
// (#2063 empty-fill verification).
41+
appendTrueAttribute(
42+
xml,
43+
"hint-showing",
44+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && node.isShowingHintText());
3845
appendNonEmptyAttribute(xml, "resource-id", node.getViewIdResourceName());
3946
appendAttribute(xml, "class", node.getClassName());
4047
appendNonEmptyAttribute(xml, "package", node.getPackageName());

‎src/platforms/android/__tests__/text-input-fill.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,40 @@ test('verifyAndroidFilledTextInHierarchy refuses an empty expectation when no in
397397
assert.equal(inputElsewhere.ok, false);
398398
});
399399

400+
// Live Pixel 9 emulator (Settings search, adb-shell channel): a CLEARED EditText dumps its hint
401+
// as `text` ("Search settings"), because getText() returns the hint for an empty field on
402+
// modern Android. The helper's hint-showing fact is the only way to tell that apart from a
403+
// field whose VALUE equals the hint string.
404+
test('verifyAndroidFilledTextInHierarchy accepts hint-only text for an empty expectation', () => {
405+
const hintShowing = verifyAndroidFilledTextInHierarchy(
406+
'<?xml version="1.0" encoding="UTF-8"?><hierarchy><node package="com.example" class="android.widget.EditText" text="Search settings" hint-showing="true" focused="true" bounds="[0,0][200,100]"/></hierarchy>',
407+
10,
408+
10,
409+
'',
410+
);
411+
assert.equal(hintShowing.ok, true);
412+
413+
// Without the fact, identical text is a real value and the clear must NOT verify.
414+
const valueEqualsHint = verifyAndroidFilledTextInHierarchy(
415+
androidInputXml({ text: 'Search settings' }),
416+
10,
417+
10,
418+
'',
419+
);
420+
assert.equal(valueEqualsHint.ok, false);
421+
});
422+
423+
test('verifyAndroidFilledTextInHierarchy treats hint-only text as an empty value for a non-empty expectation', () => {
424+
const verification = verifyAndroidFilledTextInHierarchy(
425+
'<?xml version="1.0" encoding="UTF-8"?><hierarchy><node package="com.example" class="android.widget.EditText" text="Search settings" hint-showing="true" focused="true" bounds="[0,0][200,100]"/></hierarchy>',
426+
10,
427+
10,
428+
'battery saver',
429+
);
430+
assert.equal(verification.ok, false);
431+
assert.equal(verification.actual, 'Search settings');
432+
});
433+
400434
test('verifyAndroidFilledTextInHierarchy still refuses a non-empty field for an empty expectation', () => {
401435
const verification = verifyAndroidFilledTextInHierarchy(
402436
androidInputXml({ text: 'still here' }),

‎src/platforms/android/fill-verification.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ export type { AndroidFillVerification } from './fill-diagnostics.ts';
2424

2525
type AndroidFillVerificationCandidate = AndroidFillVerificationNode & {
2626
editText: boolean;
27+
// Helper-only fact: the node's dump text is its HINT, so the field itself is empty.
28+
hintShowing: boolean;
2729
};
2830

2931
type AndroidTextAtPointInspection = {
30-
targetInput: AndroidFillVerificationNode | null;
31-
actualInput: AndroidFillVerificationNode | null;
32+
targetInput: AndroidFillVerificationCandidate | null;
33+
actualInput: AndroidFillVerificationCandidate | null;
3234
};
3335

3436
type AndroidTextAtPointScan = {
@@ -309,12 +311,16 @@ function textAndroidFillVerification(
309311
): AndroidFillVerification {
310312
const actualInput = inspection.actualInput;
311313
const actual = actualInput?.text ?? null;
314+
// An empty field's dump text is its HINT on modern Android (the placeholder-as-value trap the
315+
// Apple runner solves with treatingPlaceholderAsEmpty): match against the field's VALUE, which
316+
// the helper's hint-showing fact says is absent. `actual` keeps the raw text for diagnostics.
317+
const valueText = actualInput?.hintShowing === true ? null : actual;
312318
return {
313-
// An observed input node is required before any match: `actual` is also null when the scan
314-
// found NO input at all (wrong point, lost focus), and an empty expectation accepts null —
315-
// without the gate, three empty samples of nothing would report a clear that never touched
316-
// an app field.
317-
ok: actualInput !== null && isAcceptableAndroidFillMatch(actual, expected),
319+
// An observed input node is required before any match: `valueText` is also null when the
320+
// scan found NO input at all (wrong point, lost focus), and an empty expectation accepts
321+
// null — without the gate, three empty samples of nothing would report a clear that never
322+
// touched an app field.
323+
ok: actualInput !== null && isAcceptableAndroidFillMatch(valueText, expected),
318324
actual,
319325
reason: 'text_mismatch',
320326
targetInput: inspection.targetInput,
@@ -384,6 +390,7 @@ function androidFillCandidateFromNode(
384390
}),
385391
area,
386392
editText: isEditTextClass(node.className ?? ''),
393+
hintShowing: node.hintShowing === true,
387394
};
388395
}
389396

‎src/platforms/android/ui-hierarchy.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export type AndroidUiNodeMetadata = {
3535
focusable?: boolean;
3636
focused?: boolean;
3737
password?: boolean;
38+
/**
39+
* Helper-only: the `text` attribute is the field's HINT, not its value (an empty input's
40+
* `getText()` returns the hint on modern Android). Absent in raw uiautomator dumps.
41+
*/
42+
hintShowing?: boolean;
3843
scrollable?: boolean;
3944
canScrollForward?: boolean;
4045
canScrollBackward?: boolean;
@@ -142,6 +147,7 @@ function readNodeAttributes(node: string): Omit<AndroidUiNodeMetadata, 'rect'> {
142147
focusable: boolAttr('focusable'),
143148
focused: boolAttr('focused'),
144149
password: boolAttr('password'),
150+
...optionalBoolAttr('hintShowing', 'hint-showing'),
145151
...optionalBoolAttr('visibleToUser', 'visible-to-user'),
146152
...optionalNumberAttr('drawingOrder', 'drawing-order'),
147153
...optionalBoolAttr('scrollable', 'scrollable'),

0 commit comments

Comments
 (0)