Skip to content

Commit 9ef0088

Browse files
committed
fix(ios): make the placeholder attribute optional in the bridge vocabulary, read it on text entry only
Review follow-ups. The Simulator AX bridge asked for the placeholder attribute in its required set, so a runtime whose vocabulary lacks it would have failed every capture; a mismatch now retries the mapping without the attribute and the capture serves without placeholders. The bridge trims the placeholder the way the runner does, so whitespace reads as none. The element sweeps read a live XCUIElement attribute per element inside their deadline, so they read placeholderValue on text-entry types only; the snapshot producer keeps reading it off the snapshot it already holds.
1 parent fd3ae05 commit 9ef0088

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ extension RunnerTests {
245245
return text.isEmpty ? nil : text
246246
}
247247

248+
/// The element types whose `placeholderValue` the element sweeps read. On a live `XCUIElement`
249+
/// every attribute is one more lookup inside the sweep's deadline, so only text entry pays for
250+
/// it; a snapshot-based producer reads the attribute off the snapshot it already holds.
251+
static let placeholderElementTypes: Set<XCUIElement.ElementType> = [
252+
.textField, .secureTextField, .searchField, .textView,
253+
]
254+
255+
func elementPlaceholderText(_ element: XCUIElement, type: XCUIElement.ElementType) -> String? {
256+
guard Self.placeholderElementTypes.contains(type) else { return nil }
257+
return placeholderText(element.placeholderValue)
258+
}
259+
248260
private func snapshotAppFrame(app: XCUIApplication) -> CGRect {
249261
#if os(iOS)
250262
return onScreenWindowFrame(app: app)
@@ -387,7 +399,7 @@ extension RunnerTests {
387399
let label = element.label.trimmingCharacters(in: .whitespacesAndNewlines)
388400
let identifier = element.identifier.trimmingCharacters(in: .whitespacesAndNewlines)
389401
let valueText = snapshotValueText(element)
390-
let placeholder = placeholderText(element.placeholderValue)
402+
let placeholder = elementPlaceholderText(element, type: elementType)
391403
let hasContent = !label.isEmpty || !identifier.isEmpty || valueText != nil || placeholder != nil
392404
if !hasContent { return }
393405
if sameSemanticElement(
@@ -571,7 +583,7 @@ extension RunnerTests {
571583
label: label.isEmpty ? nil : label,
572584
identifier: identifier.isEmpty ? nil : identifier,
573585
value: valueText,
574-
placeholder: placeholderText(element.placeholderValue),
586+
placeholder: elementPlaceholderText(element, type: elementType),
575587
rect: SnapshotRect(frame),
576588
enabled: enabled,
577589
focused: elementHasFocus(element) ? true : nil,

‎apple/snapshot-bridge/SnapshotBridgeRuntime.m‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ - (nullable NSDictionary *)snapshotForProcess:(pid_t)pid
339339
kAttributeChildren,
340340
];
341341
NSArray<NSNumber *> *numbers = _attributeNumbersForNames(names);
342+
if (![numbers isKindOfClass:NSArray.class] || numbers.count != names.count) {
343+
// The placeholder attribute is optional: a runtime whose vocabulary lacks it serves the capture
344+
// without placeholders rather than failing every capture over a fact no consumer depends on.
345+
NSMutableArray<NSString *> *required = [names mutableCopy];
346+
[required removeObject:kAttributePlaceholderValue];
347+
names = required;
348+
numbers = _attributeNumbersForNames(names);
349+
}
342350
if (![numbers isKindOfClass:NSArray.class] || numbers.count != names.count) {
343351
if (error) *error = failureResponse(requestId, @"reader_unavailable", @"attribute-vocabulary-mismatch", @"AX attribute vocabulary is incompatible");
344352
finishRequestWatchdog(watchdog, watchdogState);

‎packages/platform-apple/src/snapshot-source/tree.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ test('the bridge tree carries a text field placeholder and omits an empty one',
483483
assert.equal(filled?.placeholder, 'Type your name');
484484
assert.equal(filled?.value, 'Ada Lovelace', 'the value and the placeholder are separate facts');
485485
assert.equal(decode('')?.placeholder, undefined, 'no placeholder reads as none, not as ""');
486+
assert.equal(
487+
decode(' ')?.placeholder,
488+
undefined,
489+
'a whitespace placeholder is none, as on the runner',
490+
);
486491
assert.equal(decode()?.placeholder, undefined, 'an unread fact stays unknown');
487492
});
488493

‎packages/platform-apple/src/snapshot-source/tree.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ function nodeFacts(
248248
// shape the XCTest tree produces, so a `selected:` selector cannot tell the producers apart.
249249
const selected = traits === undefined || (traits & SELECTED_TRAIT) === 0n ? undefined : true;
250250
const userInteractionEnabled = optionalBoolean(value[ATTRIBUTE.userInteractionEnabled]);
251+
// Trimmed like the runner's `placeholderText`: a whitespace placeholder is no placeholder.
252+
const placeholder = optionalString(value[ATTRIBUTE.placeholder])?.trim();
251253
return {
252254
index,
253255
...(parentIndex === undefined ? {} : { parentIndex }),
@@ -262,9 +264,7 @@ function nodeFacts(
262264
...(optionalScalar(value[ATTRIBUTE.value])
263265
? { value: optionalScalar(value[ATTRIBUTE.value]) }
264266
: {}),
265-
...(optionalString(value[ATTRIBUTE.placeholder])
266-
? { placeholder: optionalString(value[ATTRIBUTE.placeholder]) }
267-
: {}),
267+
...(placeholder ? { placeholder } : {}),
268268
...(optionalString(value[ATTRIBUTE.identifier])
269269
? { identifier: optionalString(value[ATTRIBUTE.identifier]) }
270270
: {}),

0 commit comments

Comments
 (0)