Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ test.each<Partial<SnapshotNode>>([
{ value: 'Draft' },
{ identifier: 'create' },
{ contentDescription: 'Create a draft' },
{ text: '' },
{ enabled: false },
{ selected: true },
{ checked: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const PRESENTATION_SCALAR_FIELDS = {
label: true,
value: true,
contentDescription: true,
text: true,
identifier: true,
enabled: true,
editable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ test('get attrs digest compacts the node under a ref target', () => {
test('attrs digest keeps explicit false/zero/empty field facts; unavailable ones stay absent (#2288)', () => {
const fieldFacts = {
value: '',
text: '',
editable: false,
password: false,
hintShowing: false,
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/server/response-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const SELECTOR_DIGEST_NODE_FIELDS = [
'label',
'value',
'contentDescription',
'text',
'identifier',
'enabled',
'selected',
Expand Down
6 changes: 6 additions & 0 deletions packages/kernel/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ export type RawSnapshotNode = {
* filled or hinted field) is carried here for consumers that want the accessible name.
*/
contentDescription?: string;
/**
* Android view text when it is not already the `label`: the empty string on a view that has
* a content description and no text, where the description is the label. Absent otherwise,
* so `text ?? label` is the text the view shows.
*/
text?: string;
identifier?: string;
rect?: Rect;
enabled?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/platform-android/src/ui-hierarchy-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { RawSnapshotNode, Rect } from '@agent-device/kernel/snapshot';
type AndroidPassiveNodeFacts = Pick<
RawSnapshotNode,
| 'contentDescription'
| 'text'
| 'enabled'
| 'selected'
| 'heading'
Expand Down
1 change: 1 addition & 0 deletions packages/platform-android/src/ui-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ function normalizeAndroidUiHierarchyNode(
value: androidFieldValue(attrs),
passiveFacts: {
contentDescription: attrs.desc && attrs.desc !== label ? attrs.desc : undefined,
text: label && !attrs.text ? '' : undefined,
enabled: attrs.enabled,
selected: attrs.selected,
heading: attrs.heading,
Expand Down
8 changes: 5 additions & 3 deletions packages/provider-webdriver/src/webdriver-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ test('Android WebDriver facts treat invalid state attributes as false', () => {
// by, so a filled field used to read as a node labelled with its own value and no value at all:
// `toHaveValue` saw "" on a field holding "Ada Lovelace".
test("Android WebDriver facts name a node by its text, carry a content description beside it, and read a field's text as its value", () => {
const [field, label] = parseWebDriverSourceFacts(
const [field, label, described] = parseWebDriverSourceFacts(
'<hierarchy>' +
'<android.widget.EditText text="Ada Lovelace" content-desc="Name field" hint="Your name" bounds="[0,0][100,40]" />' +
'<android.widget.TextView text="Ada Lovelace" bounds="[0,120][100,160]" />' +
'<android.widget.TextView text="" content-desc="Name field" bounds="[0,160][100,200]" />' +
'</hierarchy>',
'android',
).nodes;
Expand All @@ -55,9 +56,10 @@ test("Android WebDriver facts name a node by its text, carry a content descripti
['Ada Lovelace', 'Ada Lovelace', 'Name field', 'Your name', undefined, undefined],
);
assert.deepEqual(
[label!.label, label!.value, 'editable' in label!],
['Ada Lovelace', undefined, false],
[label!.label, label!.value, 'editable' in label!, 'text' in label!, 'text' in field!],
['Ada Lovelace', undefined, false, false, false],
);
assert.deepEqual([described!.label, described!.text], ['Name field', '']);
});

test('Android WebDriver facts read a hinted field as empty, a masked field as a password, and editability as unavailable when unreported', () => {
Expand Down
11 changes: 7 additions & 4 deletions packages/provider-webdriver/src/webdriver-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,25 @@ function sourceNodeFromAttributes(
* How a node is named. An Android node is labelled by its text and falls back to the content
* description only when it has none, as `normalizeAndroidUiHierarchyNode` reads the same
* attributes for the native helper; a content description beside visible text travels as
* `contentDescription`. A hinted empty field is labelled by its hint, which is its text. XCUITest
* names a node by `label`, else `name`.
* `contentDescription`, and a node labelled by its description carries an empty `text`. A hinted
* empty field is labelled by its hint, which is its text. XCUITest names a node by `label`, else
* `name`.
*/
function labelFacts(
attrs: Record<string, string>,
platform: WebDriverSourcePlatform,
): Pick<RawSnapshotNode, 'label' | 'contentDescription'> {
): Pick<RawSnapshotNode, 'label' | 'contentDescription' | 'text'> {
if (platform === 'ios')
return { label: firstWebDriverAttribute(attrs, ['label', 'text', 'name']) };
const description = nonEmptyWebDriverAttribute(attrs['content-desc']);
const label = nonEmptyWebDriverAttribute(attrs.text) ?? description;
const text = nonEmptyWebDriverAttribute(attrs.text);
const label = text ?? description;
return {
label,
...(description !== undefined && description !== label
? { contentDescription: description }
: {}),
...(label !== undefined && text === undefined ? { text: '' } : {}),
};
}

Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/android-ui-hierarchy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ test('an Android content description beside text is carried, and one that is the
assert.equal(result.nodes[3]?.contentDescription, undefined);
});

test('an Android view labelled by its content description carries an empty text, and one labelled by its text carries none', () => {
const xml = `<hierarchy>
<node class="android.widget.TextView" package="com.example.app" text="" content-desc="saved_task" bounds="[0,0][390,44]" visible-to-user="true"/>
<node class="android.widget.TextView" package="com.example.app" text="saved_task" bounds="[0,60][390,104]" visible-to-user="true"/>
<node class="android.widget.TextView" package="com.example.app" text="Release checklist" content-desc="saved_task" bounds="[0,120][390,164]" visible-to-user="true"/>
<node class="android.widget.TextView" package="com.example.app" text="" resource-id="empty" bounds="[0,180][390,224]" visible-to-user="true"/>
</hierarchy>`;

const result = parseUiHierarchy(xml, 800, { raw: true });

assert.equal(result.nodes[0]?.label, 'saved_task');
assert.equal(result.nodes[0]?.text, '');
assert.equal(result.nodes[1]?.label, 'saved_task');
assert.equal(result.nodes[1]?.text, undefined);
assert.equal(result.nodes[2]?.label, 'Release checklist');
assert.equal(result.nodes[2]?.text, undefined);
assert.equal(result.nodes[3]?.label, undefined);
assert.equal(result.nodes[3]?.text, undefined);
});

test('interactive Android snapshots keep a fixed sibling outside filtered scroll content (#1377)', () => {
const xml = `<hierarchy>
<node class="android.widget.FrameLayout" bounds="[0,0][400,800]" visible-to-user="true">
Expand Down
Loading