Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static void appendNode(
appendAttribute(xml, "visible-to-user", Boolean.toString(node.isVisibleToUser()));
appendDrawingOrderAttribute(xml, node);
appendTrueAttribute(xml, "clickable", node.isClickable());
appendLongClickableAttribute(xml, node.isLongClickable());
appendAttribute(xml, "enabled", Boolean.toString(node.isEnabled()));
appendTrueAttribute(xml, "focusable", node.isFocusable());
appendTrueAttribute(xml, "focused", node.isFocused());
Expand Down Expand Up @@ -188,8 +189,6 @@ private static boolean isHeading(AccessibilityNodeInfo node) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && node.isHeading();
}

// Declared residue (agent-device #1832): long-clickable is not serialized. Adding it is a helper
// protocol change (new attribute + host parser + field on the wire node).
private static void appendDrawingOrderAttribute(StringBuilder xml, AccessibilityNodeInfo node) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
appendAttribute(xml, "drawing-order", Integer.toString(node.getDrawingOrder()));
Expand Down Expand Up @@ -219,6 +218,10 @@ private static void appendAttribute(StringBuilder xml, String name, CharSequence
xml.append('"');
}

static void appendLongClickableAttribute(StringBuilder xml, boolean longClickable) {
appendAttribute(xml, "long-clickable", Boolean.toString(longClickable));
}

static void appendBoundsAttribute(
StringBuilder xml, String name, int left, int top, int right, int bottom) {
xml.append(' ').append(name).append("=\"[")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ static void run() {
assertBounds(
"window-bounds", Integer.MIN_VALUE, -1, 0, Integer.MAX_VALUE,
" window-bounds=\"[-2147483648,-1][0,2147483647]\"");
assertLongClickable(true, " long-clickable=\"true\"");
assertLongClickable(false, " long-clickable=\"false\"");
}

private static void assertLongClickable(boolean longClickable, String expected) {
StringBuilder xml = new StringBuilder();
AccessibilityTreeXml.appendLongClickableAttribute(xml, longClickable);
if (!expected.equals(xml.toString())) {
throw new AssertionError("Expected " + expected + ", got " + xml);
}
}

private static void assertBounds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export function isNavigationSensitiveAction(command: string): boolean {

/**
* Route signature of an Android snapshot, from the fields the Android backend actually carries.
* The helper serializes no `role` or `long-clickable` (declared residue, #1832), so a signature
* keying on them would compare constants and claim discrimination it does not have. `selected`
* The helper serializes no `role` (declared residue, #1832), so a signature keying on it
* would compare constants and claim discrimination it does not have. `selected`
* and `checked` are left out as a judgement call rather than an inability: a tab-bar tap flips
* selection on two nodes and a toggle tap flips one checked state, which the 90%-identical
* threshold below absorbs at every tree size this check runs on, so keying on them would only add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ const PRESENTATION_SCALAR_FIELDS = {
roleDescription: true,
placeholder: true,
hittable: true,
clickable: true,
focusable: true,
longClickable: true,
scrollable: true,
bundleId: true,
systemBar: true,
appName: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/snapshot-private-evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { IosViewportEvidence } from './ios-snapshot.ts';

/**
* Capture-local clickability facts for consumers that reproduce Maestro's private
* TreeNode semantics. This is deliberately kept outside SnapshotNode: the fact
* is retained by object identity, never serialized into the snapshot contract.
* TreeNode semantics. This is deliberately kept outside the regular SnapshotNode:
* the fact is retained by object identity, and only raw Android nodes serialize it.
*/
export type SnapshotClickabilityEvidence =
| {
Expand Down
11 changes: 11 additions & 0 deletions packages/daemon/src/server/__tests__/response-views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ test('attrs digest carries both checked answers, and none for a node that cannot
expect('checked' in plain).toBe(false);
});

test('attrs digest carries the clickability facts a raw node reports, and none it does not', () => {
const facts = { clickable: false, focusable: true, longClickable: false, scrollable: false };
const digest = getView!({ ref: 'e7', node: { ...MATCHED_NODE, ...facts } }, 'digest');
expect(digest.node).toEqual({ ...COMPACT_NODE, ...facts });
const plain = getView!({ ref: 'e7', node: MATCHED_NODE }, 'digest').node as Record<
string,
unknown
>;
for (const field of Object.keys(facts)) expect(field in plain).toBe(false);
});

test('find/get default and full return today’s shape unchanged (same reference)', () => {
const data: DaemonResponseData = { ref: '@e7', text: 'Sign in', node: MATCHED_NODE };
expect(findView!(data, 'default')).toBe(data);
Expand Down
4 changes: 4 additions & 0 deletions packages/daemon/src/server/response-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ const SELECTOR_DIGEST_NODE_FIELDS = [
'selectionStart',
'selectionEnd',
'hittable',
'clickable',
'focusable',
'longClickable',
'scrollable',
] as const;

function compactSelectorNode(node: SnapshotNode): Record<string, unknown> {
Expand Down
4 changes: 4 additions & 0 deletions packages/kernel/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ export type RawSnapshotNode = {
/** UIKit `isUserInteractionEnabled`; absent means the producer did not read it, not false. */
userInteractionEnabled?: boolean;
hittable?: boolean;
clickable?: boolean;
focusable?: boolean;
longClickable?: boolean;
scrollable?: boolean;
depth?: number;
parentIndex?: number;
pid?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ afterEach(() => {
test('retains Android helper clickable facts from the same hierarchy projection', () => {
const built = buildUiHierarchySnapshot(
parseUiHierarchyTree(`<hierarchy>
<node resource-id="true-node" bounds="[0,0][20,20]" clickable="true" />
<node resource-id="false-node" bounds="[0,20][20,40]" clickable="false" focusable="true" />
<node resource-id="absent-node" bounds="[0,40][20,60]" />
<node resource-id="true-node" bounds="[0,0][20,20]" clickable="true" long-clickable="true" />
<node resource-id="false-node" bounds="[0,20][20,40]" clickable="false" long-clickable="false" focusable="true" />
<node resource-id="absent-node" bounds="[0,40][20,60]" scrollable="true" />
</hierarchy>`),
undefined,
{ raw: true },
Expand All @@ -63,11 +63,59 @@ test('retains Android helper clickable facts from the same hierarchy projection'
],
);
assert.equal(publicSnapshot.nodes[1]?.hittable, true);
assert.equal('clickable' in (publicSnapshot.nodes[1] ?? {}), false);
assert.deepEqual(
publicSnapshot.nodes.map((node) => [node.clickable, node.focusable, node.scrollable]),
[
[true, false, false],
[false, true, false],
[false, false, true],
],
);
assert.deepEqual(
publicSnapshot.nodes.map((node) => node.longClickable),
[true, false, undefined],
);
assert.equal(JSON.stringify(publicSnapshot.nodes[2]).includes('longClickable'), false);
assert.equal(readSnapshotClickabilityEvidence(publicSnapshot), undefined);
});

test('snapshotAndroid captures the hierarchy once and retains clickability off-wire', async () => {
test('the regular projection keeps the clickability facts off the node', () => {
const built = buildUiHierarchySnapshot(
parseUiHierarchyTree(`<hierarchy>
<node class="android.widget.ScrollView" resource-id="list" bounds="[0,0][100,100]" scrollable="true">
<node class="android.widget.Button" resource-id="visible-row" text="Visible" bounds="[0,0][100,40]" clickable="true" long-clickable="false" focusable="true" />
<node class="android.widget.Button" resource-id="clipped-row" text="Clipped" bounds="[0,200][100,240]" clickable="true" long-clickable="true" />
</node>
</hierarchy>`),
undefined,
{},
);
const evidence = buildAndroidSnapshotClickabilityEvidence(built);
if (evidence.kind !== 'exact') throw new Error('Android evidence must be exact');

assert.deepEqual(
built.nodes.map((node) => [node.identifier, node.hittable]),
[
['list', undefined],
['visible-row', true],
],
);
assert.deepEqual(
built.nodes.map((node) =>
['clickable', 'focusable', 'longClickable', 'scrollable'].filter((key) => key in node),
),
[[], []],
);
assert.deepEqual(
[...evidence.clickableByNodeIndex.entries()],
[
[0, false],
[1, true],
],
);
});

test('snapshotAndroid captures the hierarchy once and publishes the clickability it retains', async () => {
let hierarchyCaptures = 0;
const helperAdb: AndroidAdbExecutor = async (args) => {
if (args.includes('--show-versioncode')) {
Expand Down Expand Up @@ -119,7 +167,10 @@ test('snapshotAndroid captures the hierarchy once and retains clickability off-w
[2, 2],
],
);
assert.equal(JSON.stringify(result).includes('clickable'), false);
assert.deepEqual(
result.nodes.map((node) => node.clickable),
[false, true, false],
);
assert.equal(JSON.stringify(result).includes('sourceIndexByNodeIndex'), false);
});

Expand Down
9 changes: 8 additions & 1 deletion packages/platform-android/src/snapshot-presentation-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ export function foldSnapshotRect(
export function serializeRegularSnapshotPresentationNode(
node: SnapshotPresentationNode,
): RawSnapshotNode {
const {
clickable: _clickable,
focusable: _focusable,
longClickable: _longClickable,
scrollable: _scrollable,
...published
} = node.raw;
return {
...node.raw,
...published,
...(node.effectiveRect ? { rect: node.effectiveRect } : { rect: undefined }),
hittable:
node.raw.hittable === true && isPositiveFiniteRect(node.effectiveRect) ? true : undefined,
Expand Down
9 changes: 8 additions & 1 deletion packages/platform-android/src/ui-hierarchy-node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { RawSnapshotNode, Rect } from '@agent-device/kernel/snapshot';

/** Normalized attributes carried unchanged into the public node, independent of presentation. */
/**
* Normalized attributes carried unchanged into the public node, independent of presentation.
* The regular projection leaves out `clickable`, `focusable`, `longClickable` and `scrollable`.
*/
type AndroidPassiveNodeFacts = Pick<
RawSnapshotNode,
| 'contentDescription'
Expand All @@ -16,6 +19,10 @@ type AndroidPassiveNodeFacts = Pick<
| 'placeholder'
| 'selectionStart'
| 'selectionEnd'
| 'clickable'
| 'focusable'
| 'longClickable'
| 'scrollable'
>;

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/platform-android/src/ui-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type AndroidUiNodeMetadata = {
bounds: string | null;
rect?: Rect;
clickable?: boolean;
longClickable?: boolean;
enabled?: boolean;
visibleToUser?: boolean;
drawingOrder?: number;
Expand Down Expand Up @@ -166,6 +167,7 @@ function readNodeAttributes(node: string): Omit<AndroidUiNodeMetadata, 'rect'> {
className: getAttr('class'),
bounds: getAttr('bounds'),
clickable: boolAttr('clickable'),
...optionalBoolAttr('longClickable', 'long-clickable'),
enabled: boolAttr('enabled'),
focusable: boolAttr('focusable'),
focused: boolAttr('focused'),
Expand Down Expand Up @@ -343,6 +345,10 @@ function normalizeAndroidUiHierarchyNode(
placeholder: attrs.hint,
selectionStart: attrs.selectionStart,
selectionEnd: attrs.selectionEnd,
clickable: attrs.clickable === true,
focusable: attrs.focusable === true,
longClickable: attrs.longClickable,
scrollable: attrs.scrollable === true,
},
identifier: attrs.resourceId,
packageName: attrs.packageName,
Expand Down
7 changes: 7 additions & 0 deletions website/docs/docs/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ decides which backends it tries.
to conservative behavior there, and `androidSnapshot.occlusionScanUnavailable: true` tells you so.
- `--raw` returns the tree as captured. It also keeps nodes Android marks invisible and stale
application windows.
- `--raw` nodes carry four interaction facts that default and `-i` snapshots leave out. An absent
field means the capture could not read it, not `false`:
- `clickable`: the node accepts a tap.
- `focusable`: keyboard or D-pad focus can land on the node.
- `longClickable`: the node accepts a long press. Absent when an older snapshot helper served the
capture.
- `scrollable`: the node scrolls its content.

## iOS node metadata

Expand Down
Loading