diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m b/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m index b2c46d0a0e..0cd60ad954 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m @@ -221,7 +221,8 @@ - (void)viewDidLoad { } @end -@interface AgentDeviceRunnerFixtureViewController () +@interface AgentDeviceRunnerFixtureViewController () + // Held for the app's lifetime: a window nobody retained would be gone before the test queried it. @property(nonatomic, strong) UIWindow *secondWindow; @property(nonatomic, strong) UILabel *navigationBackStatus; @@ -392,6 +393,19 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField { @implementation AgentDeviceRunnerFixtureViewController +// The picker-wheel fixture's content: one component, so the screen holds exactly one wheel. +- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { + return 1; +} + +- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { + return 4; +} + +- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { + return @[@"First", @"Second", @"Third", @"Fourth"][row]; +} + // `--hide-status-bar` stands in for a landscape iPhone, full-screen video, or an RN screen that hides // its status bar. - (BOOL)prefersStatusBarHidden { @@ -1489,6 +1503,16 @@ - (void)viewDidLoad { } } + // A real picker wheel: UIKit reports each wheel of a UIPickerView as its own element type, which + // is the node #4657 saw named `Element(39)` by one producer and `PickerWheel` by the other. + if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-picker-wheel"]) { + UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 300, 390, 216)]; + picker.dataSource = self; + picker.delegate = self; + picker.accessibilityIdentifier = @"agent-device-picker-wheel"; + [self.view addSubview:picker]; + } + if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-collapsed-tab-bar"]) { UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(20, 20, 360, 60)]; tabBar.items = @[ diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift index 1541954fb3..930372c1bd 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift @@ -49,11 +49,11 @@ extension RunnerTests { return Date() < deadline ? observation : .deadlineExceeded } - /// The tree the alert rules read. Snapshot output has no names for alerts and sheets, so the - /// rules name them here. + /// The tree the alert rules read. The shared element-type table names an alert and a sheet, so the + /// rules read the same name a snapshot publishes for the same node (#4657). func alertSurfaceNode(_ snapshot: XCUIElementSnapshot) -> AlertSurfaceNode { AlertSurfaceNode( - type: alertSurfaceTypeName(snapshot.elementType), + type: elementTypeName(snapshot.elementType), identifier: snapshot.identifier, label: snapshot.label, frame: snapshot.frame, @@ -61,14 +61,6 @@ extension RunnerTests { ) } - func alertSurfaceTypeName(_ type: XCUIElement.ElementType) -> String { - switch type { - case .alert: return "Alert" - case .sheet: return "Sheet" - default: return elementTypeName(type) - } - } - func alertVerificationResponse( _ verification: RunnerAlertVerification, action: String, diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift index e8fb2100b5..3a76a3d8fc 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift @@ -76,42 +76,110 @@ extension RunnerTests { // MARK: - Snapshot Entry - /// One raw-value table covers public XCTest cases and the SDK-hidden Keyboard/Key values. - static let elementTypeNamesByRawValue = [ + /** + * Every element-type name a capture can carry, keyed by the raw value the SDK numbers it with. The + * golden table `contracts/fixtures/ios-element-type-names.json` holds the same rows, and the + * Simulator AX bridge mirrors them by index in `ELEMENT_TYPE_NAMES` + * (`packages/platform-apple/src/snapshot-source/tree.ts`), so one node carries one `type` whichever + * producer served it (#4657). `RunnerTests+ElementTypeNamesTests` reads that table through this + * dictionary and fails when a row names a raw value differently here. + * + * One table serves every runner platform, so a macOS, tvOS, visionOS or watchOS capture publishes + * these names too: the numbers and the names come from the same SDK header on all of them. The + * presented-surface rule still reads the raw-value spelling, so a consumer of a capture from an + * older runner keeps working. + * + * A row keyed by an SDK case cannot drift from the number: the case names the number. The two rows + * keyed by a bare number cover the SDK-hidden Keyboard and Key values, whose numbers the table owns. + */ + static let elementTypeNamesByRawValue: [UInt: String] = [ + XCUIElement.ElementType.any.rawValue: "Other", + XCUIElement.ElementType.other.rawValue: "Other", XCUIElement.ElementType.application.rawValue: "Application", + XCUIElement.ElementType.group.rawValue: "Group", XCUIElement.ElementType.window.rawValue: "Window", + XCUIElement.ElementType.sheet.rawValue: "Sheet", + XCUIElement.ElementType.drawer.rawValue: "Drawer", + XCUIElement.ElementType.alert.rawValue: "Alert", + XCUIElement.ElementType.dialog.rawValue: "Dialog", XCUIElement.ElementType.button.rawValue: "Button", - XCUIElement.ElementType.cell.rawValue: "Cell", - XCUIElement.ElementType.staticText.rawValue: "StaticText", - XCUIElement.ElementType.textField.rawValue: "TextField", - XCUIElement.ElementType.textView.rawValue: "TextView", - XCUIElement.ElementType.secureTextField.rawValue: "SecureTextField", - XCUIElement.ElementType.switch.rawValue: "Switch", - XCUIElement.ElementType.slider.rawValue: "Slider", - XCUIElement.ElementType.link.rawValue: "Link", - XCUIElement.ElementType.image.rawValue: "Image", + XCUIElement.ElementType.radioButton.rawValue: "RadioButton", + XCUIElement.ElementType.radioGroup.rawValue: "RadioGroup", + XCUIElement.ElementType.checkBox.rawValue: "CheckBox", + XCUIElement.ElementType.disclosureTriangle.rawValue: "DisclosureTriangle", + XCUIElement.ElementType.popUpButton.rawValue: "PopUpButton", + XCUIElement.ElementType.comboBox.rawValue: "ComboBox", + XCUIElement.ElementType.menuButton.rawValue: "MenuButton", + XCUIElement.ElementType.toolbarButton.rawValue: "ToolbarButton", + XCUIElement.ElementType.popover.rawValue: "Popover", + 19: "Keyboard", + 20: "Key", XCUIElement.ElementType.navigationBar.rawValue: "NavigationBar", XCUIElement.ElementType.tabBar.rawValue: "TabBar", - XCUIElement.ElementType.collectionView.rawValue: "CollectionView", - XCUIElement.ElementType.table.rawValue: "Table", - XCUIElement.ElementType.scrollView.rawValue: "ScrollView", + XCUIElement.ElementType.tabGroup.rawValue: "TabGroup", XCUIElement.ElementType.toolbar.rawValue: "Toolbar", - XCUIElement.ElementType.searchField.rawValue: "SearchField", + XCUIElement.ElementType.statusBar.rawValue: "StatusBar", + XCUIElement.ElementType.table.rawValue: "Table", + XCUIElement.ElementType.tableRow.rawValue: "TableRow", + XCUIElement.ElementType.tableColumn.rawValue: "TableColumn", + XCUIElement.ElementType.outline.rawValue: "Outline", + XCUIElement.ElementType.outlineRow.rawValue: "OutlineRow", + XCUIElement.ElementType.browser.rawValue: "Browser", + XCUIElement.ElementType.collectionView.rawValue: "CollectionView", + XCUIElement.ElementType.slider.rawValue: "Slider", + XCUIElement.ElementType.pageIndicator.rawValue: "PageIndicator", + XCUIElement.ElementType.progressIndicator.rawValue: "ProgressIndicator", + XCUIElement.ElementType.activityIndicator.rawValue: "ActivityIndicator", XCUIElement.ElementType.segmentedControl.rawValue: "SegmentedControl", - XCUIElement.ElementType.stepper.rawValue: "Stepper", XCUIElement.ElementType.picker.rawValue: "Picker", - XCUIElement.ElementType.activityIndicator.rawValue: "ActivityIndicator", - XCUIElement.ElementType.progressIndicator.rawValue: "ProgressIndicator", - XCUIElement.ElementType.checkBox.rawValue: "CheckBox", - XCUIElement.ElementType.radioButton.rawValue: "RadioButton", + XCUIElement.ElementType.pickerWheel.rawValue: "PickerWheel", + XCUIElement.ElementType.switch.rawValue: "Switch", XCUIElement.ElementType.toggle.rawValue: "Toggle", + XCUIElement.ElementType.link.rawValue: "Link", + XCUIElement.ElementType.image.rawValue: "Image", + XCUIElement.ElementType.icon.rawValue: "Icon", + XCUIElement.ElementType.searchField.rawValue: "SearchField", + XCUIElement.ElementType.scrollView.rawValue: "ScrollView", + XCUIElement.ElementType.scrollBar.rawValue: "ScrollBar", + XCUIElement.ElementType.staticText.rawValue: "StaticText", + XCUIElement.ElementType.textField.rawValue: "TextField", + XCUIElement.ElementType.secureTextField.rawValue: "SecureTextField", + XCUIElement.ElementType.datePicker.rawValue: "DatePicker", + XCUIElement.ElementType.textView.rawValue: "TextView", + XCUIElement.ElementType.menu.rawValue: "Menu", XCUIElement.ElementType.menuItem.rawValue: "MenuItem", + XCUIElement.ElementType.menuBar.rawValue: "MenuBar", + XCUIElement.ElementType.menuBarItem.rawValue: "MenuBarItem", + XCUIElement.ElementType.map.rawValue: "Map", XCUIElement.ElementType.webView.rawValue: "WebView", - XCUIElement.ElementType.other.rawValue: "Other", - 19: "Keyboard", - 20: "Key" + XCUIElement.ElementType.incrementArrow.rawValue: "IncrementArrow", + XCUIElement.ElementType.decrementArrow.rawValue: "DecrementArrow", + XCUIElement.ElementType.timeline.rawValue: "Timeline", + XCUIElement.ElementType.ratingIndicator.rawValue: "RatingIndicator", + XCUIElement.ElementType.valueIndicator.rawValue: "ValueIndicator", + XCUIElement.ElementType.splitGroup.rawValue: "SplitGroup", + XCUIElement.ElementType.splitter.rawValue: "Splitter", + XCUIElement.ElementType.relevanceIndicator.rawValue: "RelevanceIndicator", + XCUIElement.ElementType.colorWell.rawValue: "ColorWell", + XCUIElement.ElementType.helpTag.rawValue: "HelpTag", + XCUIElement.ElementType.matte.rawValue: "Matte", + XCUIElement.ElementType.dockItem.rawValue: "DockItem", + XCUIElement.ElementType.ruler.rawValue: "Ruler", + XCUIElement.ElementType.rulerMarker.rawValue: "RulerMarker", + XCUIElement.ElementType.grid.rawValue: "Grid", + XCUIElement.ElementType.levelIndicator.rawValue: "LevelIndicator", + XCUIElement.ElementType.cell.rawValue: "Cell", + XCUIElement.ElementType.layoutArea.rawValue: "LayoutArea", + XCUIElement.ElementType.layoutItem.rawValue: "LayoutItem", + XCUIElement.ElementType.handle.rawValue: "Handle", + XCUIElement.ElementType.stepper.rawValue: "Stepper", + XCUIElement.ElementType.tab.rawValue: "Tab", + XCUIElement.ElementType.touchBar.rawValue: "TouchBar", + XCUIElement.ElementType.statusItem.rawValue: "StatusItem" ] + /// The name this producer publishes for an element type, and the raw-value spelling for one no row + /// names — which stays the only way an unseen number reaches a snapshot. func elementTypeName(_ type: XCUIElement.ElementType) -> String { Self.elementTypeNamesByRawValue[type.rawValue] ?? "Element(\(type.rawValue))" } diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertSurfaceTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertSurfaceTests.swift index 26dbd0f697..6e7c19630f 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertSurfaceTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertSurfaceTests.swift @@ -70,7 +70,7 @@ extension RunnerTests { index: index, parentIndex: node.parentIndex < 0 ? nil : node.parentIndex, element: node.element, - type: alertSurfaceTypeName(XCUIElement.ElementType(rawValue: UInt(node.elementType)) ?? .any), + type: elementTypeName(XCUIElement.ElementType(rawValue: UInt(node.elementType)) ?? .any), identifier: node.identifier, label: node.label, rect: RecordedAlertSurfaceRect(frame: node.frame), diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+ElementTypeNamesTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+ElementTypeNamesTests.swift new file mode 100644 index 0000000000..8e4a411e9c --- /dev/null +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+ElementTypeNamesTests.swift @@ -0,0 +1,231 @@ +import XCTest + +#if AGENT_DEVICE_RUNNER_UNIT_TESTS +/// Runner-side tie for the golden table `contracts/fixtures/ios-element-type-names.json` — the one +/// list of element-type names both iOS producers read (#4657). The Simulator AX bridge is tied to the +/// same table by `tree.test.ts`; the two ties together are what makes one node carry one `type` +/// whichever producer served it. +/// +/// Each row is read back through the production `elementTypeName`, so the table cannot name a type +/// this producer publishes differently. A row that names an SDK case is also compared with that +/// case's own raw value, so an SDK that renumbers a case fails here against the SDK rather than +/// against a second handwritten list, the way `RunnerTests+ApplicationStateRawValueTests` does for +/// application states. +private struct ElementTypeNamesTable: Decodable { + let unnamedTypeSpelling: String + let types: [Row] + + struct Row: Decodable { + let rawValue: Int + let sdkCase: String? + let name: String + } +} + +private func loadElementTypeNamesTable() throws -> ElementTypeNamesTable { + let fixtureURL = URL(fileURLWithPath: #filePath) + .deletingLastPathComponent() // UnitTests + .deletingLastPathComponent() // AgentDeviceRunnerUITests + .deletingLastPathComponent() // AgentDeviceRunner + .deletingLastPathComponent() // runner + .deletingLastPathComponent() // apple + .deletingLastPathComponent() // repo root + .appendingPathComponent("contracts/fixtures/ios-element-type-names.json") + return try JSONDecoder().decode( + ElementTypeNamesTable.self, + from: Data(contentsOf: fixtureURL) + ) +} + +extension RunnerTests { + /// Every row of the shared table publishes its name through this producer's own lookup, and every + /// row this producer pins is in the table. Fails at the base table, which named 32 rows: a row it + /// lacked reaches a snapshot as `Element()` where the bridge reports the name (#4657). + func testElementTypeNamesTablePublishesEveryRowThroughTheRunnerLookup() throws { + let table = try loadElementTypeNamesTable() + var pinned = Set() + assertNamedRow(table, "any", .any, &pinned) + assertNamedRow(table, "other", .other, &pinned) + assertNamedRow(table, "application", .application, &pinned) + assertNamedRow(table, "group", .group, &pinned) + assertNamedRow(table, "window", .window, &pinned) + assertNamedRow(table, "sheet", .sheet, &pinned) + assertNamedRow(table, "drawer", .drawer, &pinned) + assertNamedRow(table, "alert", .alert, &pinned) + assertNamedRow(table, "dialog", .dialog, &pinned) + assertNamedRow(table, "button", .button, &pinned) + assertNamedRow(table, "radioButton", .radioButton, &pinned) + assertNamedRow(table, "radioGroup", .radioGroup, &pinned) + assertNamedRow(table, "checkBox", .checkBox, &pinned) + assertNamedRow(table, "disclosureTriangle", .disclosureTriangle, &pinned) + assertNamedRow(table, "popUpButton", .popUpButton, &pinned) + assertNamedRow(table, "comboBox", .comboBox, &pinned) + assertNamedRow(table, "menuButton", .menuButton, &pinned) + assertNamedRow(table, "toolbarButton", .toolbarButton, &pinned) + assertNamedRow(table, "popover", .popover, &pinned) + assertNamedRow(table, "navigationBar", .navigationBar, &pinned) + assertNamedRow(table, "tabBar", .tabBar, &pinned) + assertNamedRow(table, "tabGroup", .tabGroup, &pinned) + assertNamedRow(table, "toolbar", .toolbar, &pinned) + assertNamedRow(table, "statusBar", .statusBar, &pinned) + assertNamedRow(table, "table", .table, &pinned) + assertNamedRow(table, "tableRow", .tableRow, &pinned) + assertNamedRow(table, "tableColumn", .tableColumn, &pinned) + assertNamedRow(table, "outline", .outline, &pinned) + assertNamedRow(table, "outlineRow", .outlineRow, &pinned) + assertNamedRow(table, "browser", .browser, &pinned) + assertNamedRow(table, "collectionView", .collectionView, &pinned) + assertNamedRow(table, "slider", .slider, &pinned) + assertNamedRow(table, "pageIndicator", .pageIndicator, &pinned) + assertNamedRow(table, "progressIndicator", .progressIndicator, &pinned) + assertNamedRow(table, "activityIndicator", .activityIndicator, &pinned) + assertNamedRow(table, "segmentedControl", .segmentedControl, &pinned) + assertNamedRow(table, "picker", .picker, &pinned) + assertNamedRow(table, "pickerWheel", .pickerWheel, &pinned) + assertNamedRow(table, "switch", .switch, &pinned) + assertNamedRow(table, "toggle", .toggle, &pinned) + assertNamedRow(table, "link", .link, &pinned) + assertNamedRow(table, "image", .image, &pinned) + assertNamedRow(table, "icon", .icon, &pinned) + assertNamedRow(table, "searchField", .searchField, &pinned) + assertNamedRow(table, "scrollView", .scrollView, &pinned) + assertNamedRow(table, "scrollBar", .scrollBar, &pinned) + assertNamedRow(table, "staticText", .staticText, &pinned) + assertNamedRow(table, "textField", .textField, &pinned) + assertNamedRow(table, "secureTextField", .secureTextField, &pinned) + assertNamedRow(table, "datePicker", .datePicker, &pinned) + assertNamedRow(table, "textView", .textView, &pinned) + assertNamedRow(table, "menu", .menu, &pinned) + assertNamedRow(table, "menuItem", .menuItem, &pinned) + assertNamedRow(table, "menuBar", .menuBar, &pinned) + assertNamedRow(table, "menuBarItem", .menuBarItem, &pinned) + assertNamedRow(table, "map", .map, &pinned) + assertNamedRow(table, "webView", .webView, &pinned) + assertNamedRow(table, "incrementArrow", .incrementArrow, &pinned) + assertNamedRow(table, "decrementArrow", .decrementArrow, &pinned) + assertNamedRow(table, "timeline", .timeline, &pinned) + assertNamedRow(table, "ratingIndicator", .ratingIndicator, &pinned) + assertNamedRow(table, "valueIndicator", .valueIndicator, &pinned) + assertNamedRow(table, "splitGroup", .splitGroup, &pinned) + assertNamedRow(table, "splitter", .splitter, &pinned) + assertNamedRow(table, "relevanceIndicator", .relevanceIndicator, &pinned) + assertNamedRow(table, "colorWell", .colorWell, &pinned) + assertNamedRow(table, "helpTag", .helpTag, &pinned) + assertNamedRow(table, "matte", .matte, &pinned) + assertNamedRow(table, "dockItem", .dockItem, &pinned) + assertNamedRow(table, "ruler", .ruler, &pinned) + assertNamedRow(table, "rulerMarker", .rulerMarker, &pinned) + assertNamedRow(table, "grid", .grid, &pinned) + assertNamedRow(table, "levelIndicator", .levelIndicator, &pinned) + assertNamedRow(table, "cell", .cell, &pinned) + assertNamedRow(table, "layoutArea", .layoutArea, &pinned) + assertNamedRow(table, "layoutItem", .layoutItem, &pinned) + assertNamedRow(table, "handle", .handle, &pinned) + assertNamedRow(table, "stepper", .stepper, &pinned) + assertNamedRow(table, "tab", .tab, &pinned) + assertNamedRow(table, "touchBar", .touchBar, &pinned) + assertNamedRow(table, "statusItem", .statusItem, &pinned) + // Two names the table keys by number alone: the SDK hides these cases from Swift on some + // platforms, which is why this producer's table spells their raw values. + assertNumberedRow(table, 19, &pinned) + assertNumberedRow(table, 20, &pinned) + + XCTAssertEqual( + pinned, + Set(table.types.compactMap { $0.sdkCase ?? "raw:\($0.rawValue)" }), + "the runner's pinned rows and the shared table's rows differ" + ) + XCTAssertEqual( + Self.elementTypeNamesByRawValue.count, + table.types.count, + "the runner names an element type the shared table does not carry" + ) + } + + /// Every raw value the shared table leaves unnamed still reaches a snapshot as the raw-value + /// spelling, which is what the presented-surface rule reads for a producer that names nothing + /// (#3565). + func testElementTypeNamesFallBackToTheRawValueSpellingTheTableDeclares() throws { + let table = try loadElementTypeNamesTable() + XCTAssertEqual( + table.unnamedTypeSpelling, + "Element()", + "the shared table declares the fallback spelling both producers must keep" + ) + let unnamed = try XCTUnwrap(table.types.map(\.rawValue).max()) + 1 + let unnamedType = try XCTUnwrap( + XCUIElement.ElementType(rawValue: UInt(unnamed)), + "the runner reads raw value \(unnamed) as an element type" + ) + XCTAssertEqual( + elementTypeName(unnamedType), + "Element(\(unnamed))", + "the runner must spell an unnamed raw value the way the shared table declares" + ) + } + + /// Pins one table row: the SDK case still carries the raw value the table maps its name to, and + /// this producer publishes that name for the case. + private func assertNamedRow( + _ table: ElementTypeNamesTable, + _ sdkCase: String, + _ type: XCUIElement.ElementType, + _ pinned: inout Set, + file: StaticString = #filePath, + line: UInt = #line + ) { + guard let row = table.types.first(where: { $0.sdkCase == sdkCase }) else { + XCTFail("the shared table carries no row for SDK case \(sdkCase)", file: file, line: line) + return + } + XCTAssertEqual( + row.rawValue, + Int(type.rawValue), + "XCUIElement.ElementType.\(sdkCase) no longer carries the raw value the shared table maps to \"\(row.name)\"", + file: file, + line: line + ) + XCTAssertEqual( + elementTypeName(type), + row.name, + "raw value \(row.rawValue) (\(row.name)) is named differently by the runner and by the shared table", + file: file, + line: line + ) + pinned.insert(sdkCase) + } + + /// Pins one table row the SDK gives no Swift case for: the number alone decides the name, on both + /// producers. + private func assertNumberedRow( + _ table: ElementTypeNamesTable, + _ rawValue: Int, + _ pinned: inout Set, + file: StaticString = #filePath, + line: UInt = #line + ) { + guard let row = table.types.first(where: { $0.rawValue == rawValue }) else { + XCTFail("the shared table carries no row for raw value \(rawValue)", file: file, line: line) + return + } + XCTAssertNil( + row.sdkCase, + "raw value \(rawValue) is named \"\(row.name)\" with no SDK case; this producer keys it by number", + file: file, + line: line + ) + guard let raw = UInt(exactly: rawValue), let type = XCUIElement.ElementType(rawValue: raw) else { + XCTFail("the runner reads raw value \(rawValue) as an element type", file: file, line: line) + return + } + XCTAssertEqual( + elementTypeName(type), + row.name, + "raw value \(rawValue) is named differently by the runner and by the shared table", + file: file, + line: line + ) + pinned.insert("raw:\(rawValue)") + } +} +#endif diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SnapshotTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SnapshotTests.swift index e71ab44527..215660e594 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SnapshotTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SnapshotTests.swift @@ -441,6 +441,48 @@ extension RunnerTests { XCTAssertEqual(capture.outcome, .completed) XCTAssertFalse(capture.acquisition.truncated) } + + /// A picker wheel's own element type reaches a snapshot by name, the way the Simulator AX bridge + /// names it. Before the shared element-type table, this node arrived as `Element(39)` (#4657). + @MainActor + func testPickerWheelScreenPublishesTheNamedElementType() throws { + app.launchArguments = ["--agent-device-picker-wheel"] + app.launch() + defer { + invalidateCachedTarget(reason: "unit_test_cleanup") + app.terminate() + } + // UIKit puts the identifier on the UIPickerView itself; the wheel is its component child. + XCTAssertTrue( + app.pickerWheels.element.waitForExistence(timeout: appExistenceTimeout), + "the fixture must show a picker wheel" + ) + let hint = CaptureHint( + projection: .regular, + depth: nil, + regularPresentedDepth: nil, + interactiveOnly: false, + customActions: false + ) + let context = try XCTUnwrap(makeSnapshotTraversalContext(app: app, hint: hint)) + let wheel = try XCTUnwrap( + Self.snapshotDescendants(of: context.rootSnapshot).first { $0.elementType == .pickerWheel }, + "the fixture's picker wheel must answer the element-type query" + ) + let capture = try recursiveTreeSnapshotAcquisition( + context: context, + hint: hint, + processingDeadline: Date().addingTimeInterval(treeCaptureSliceBudget) + ) + let nodes = capture.acquisition.nodes + XCTAssertEqual(capture.outcome, .completed) + XCTAssertEqual(elementTypeName(wheel.elementType), "PickerWheel") + XCTAssertEqual(nodes.filter { $0.type == "PickerWheel" }.count, 1) + XCTAssertFalse( + nodes.contains { $0.type == "Element(\(XCUIElement.ElementType.pickerWheel.rawValue))" }, + "the runner must not name a type the shared table covers by its raw value" + ) + } #endif } #endif diff --git a/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentedSurface.swift b/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentedSurface.swift index 5e2f21ad88..2131b7a832 100644 --- a/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentedSurface.swift +++ b/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentedSurface.swift @@ -8,6 +8,7 @@ import Foundation public enum SnapshotPresentedSurface { /// Element types that name a presentation, keyed by the element-type numbering every iOS producer /// reads. A producer whose name table stops short publishes `Element()` for the same node. + /// `contracts/fixtures/ios-element-type-names.json` names these four rows and the numbers they carry. public static let presentingElementTypes: [String: Int] = [ "Sheet": 5, "Drawer": 6, diff --git a/contracts/fixtures/ios-element-type-names.json b/contracts/fixtures/ios-element-type-names.json new file mode 100644 index 0000000000..4bbfa150a8 --- /dev/null +++ b/contracts/fixtures/ios-element-type-names.json @@ -0,0 +1,89 @@ +{ + "description": "The one table that turns an `XCUIElement.ElementType` raw value into the `type` name an iOS snapshot publishes (issue #4657). Both iOS producers read it: the Simulator AX bridge names every entry by index in `ELEMENT_TYPE_NAMES` in packages/platform-apple/src/snapshot-source/tree.ts, and the XCTest runner mirrors every entry by raw value in `elementTypeNamesByRawValue` in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift. One node captured twice, once per producer, must carry one name: a consumer that keys on `type` cannot know which producer served a capture, because the backend is chosen per capture. `sdkCase` names the SDK case that carries a row's `rawValue`, so the runner's parity test compares the row with that case and an SDK renumbering fails against the SDK; a null `sdkCase` names a value the SDK hides from Swift, which both producers still publish. A row reaches a snapshot by its name on both producers. What a producer does with a raw value no row names is its own: the runner spells it `unnamedTypeSpelling` and the bridge reports `Other`, and the presented-surface rule reads either spelling by number (#3565).", + "unnamedTypeSpelling": "Element()", + "types": [ + { "rawValue": 0, "sdkCase": "any", "name": "Other" }, + { "rawValue": 1, "sdkCase": "other", "name": "Other" }, + { "rawValue": 2, "sdkCase": "application", "name": "Application" }, + { "rawValue": 3, "sdkCase": "group", "name": "Group" }, + { "rawValue": 4, "sdkCase": "window", "name": "Window" }, + { "rawValue": 5, "sdkCase": "sheet", "name": "Sheet" }, + { "rawValue": 6, "sdkCase": "drawer", "name": "Drawer" }, + { "rawValue": 7, "sdkCase": "alert", "name": "Alert" }, + { "rawValue": 8, "sdkCase": "dialog", "name": "Dialog" }, + { "rawValue": 9, "sdkCase": "button", "name": "Button" }, + { "rawValue": 10, "sdkCase": "radioButton", "name": "RadioButton" }, + { "rawValue": 11, "sdkCase": "radioGroup", "name": "RadioGroup" }, + { "rawValue": 12, "sdkCase": "checkBox", "name": "CheckBox" }, + { "rawValue": 13, "sdkCase": "disclosureTriangle", "name": "DisclosureTriangle" }, + { "rawValue": 14, "sdkCase": "popUpButton", "name": "PopUpButton" }, + { "rawValue": 15, "sdkCase": "comboBox", "name": "ComboBox" }, + { "rawValue": 16, "sdkCase": "menuButton", "name": "MenuButton" }, + { "rawValue": 17, "sdkCase": "toolbarButton", "name": "ToolbarButton" }, + { "rawValue": 18, "sdkCase": "popover", "name": "Popover" }, + { "rawValue": 19, "sdkCase": null, "name": "Keyboard" }, + { "rawValue": 20, "sdkCase": null, "name": "Key" }, + { "rawValue": 21, "sdkCase": "navigationBar", "name": "NavigationBar" }, + { "rawValue": 22, "sdkCase": "tabBar", "name": "TabBar" }, + { "rawValue": 23, "sdkCase": "tabGroup", "name": "TabGroup" }, + { "rawValue": 24, "sdkCase": "toolbar", "name": "Toolbar" }, + { "rawValue": 25, "sdkCase": "statusBar", "name": "StatusBar" }, + { "rawValue": 26, "sdkCase": "table", "name": "Table" }, + { "rawValue": 27, "sdkCase": "tableRow", "name": "TableRow" }, + { "rawValue": 28, "sdkCase": "tableColumn", "name": "TableColumn" }, + { "rawValue": 29, "sdkCase": "outline", "name": "Outline" }, + { "rawValue": 30, "sdkCase": "outlineRow", "name": "OutlineRow" }, + { "rawValue": 31, "sdkCase": "browser", "name": "Browser" }, + { "rawValue": 32, "sdkCase": "collectionView", "name": "CollectionView" }, + { "rawValue": 33, "sdkCase": "slider", "name": "Slider" }, + { "rawValue": 34, "sdkCase": "pageIndicator", "name": "PageIndicator" }, + { "rawValue": 35, "sdkCase": "progressIndicator", "name": "ProgressIndicator" }, + { "rawValue": 36, "sdkCase": "activityIndicator", "name": "ActivityIndicator" }, + { "rawValue": 37, "sdkCase": "segmentedControl", "name": "SegmentedControl" }, + { "rawValue": 38, "sdkCase": "picker", "name": "Picker" }, + { "rawValue": 39, "sdkCase": "pickerWheel", "name": "PickerWheel" }, + { "rawValue": 40, "sdkCase": "switch", "name": "Switch" }, + { "rawValue": 41, "sdkCase": "toggle", "name": "Toggle" }, + { "rawValue": 42, "sdkCase": "link", "name": "Link" }, + { "rawValue": 43, "sdkCase": "image", "name": "Image" }, + { "rawValue": 44, "sdkCase": "icon", "name": "Icon" }, + { "rawValue": 45, "sdkCase": "searchField", "name": "SearchField" }, + { "rawValue": 46, "sdkCase": "scrollView", "name": "ScrollView" }, + { "rawValue": 47, "sdkCase": "scrollBar", "name": "ScrollBar" }, + { "rawValue": 48, "sdkCase": "staticText", "name": "StaticText" }, + { "rawValue": 49, "sdkCase": "textField", "name": "TextField" }, + { "rawValue": 50, "sdkCase": "secureTextField", "name": "SecureTextField" }, + { "rawValue": 51, "sdkCase": "datePicker", "name": "DatePicker" }, + { "rawValue": 52, "sdkCase": "textView", "name": "TextView" }, + { "rawValue": 53, "sdkCase": "menu", "name": "Menu" }, + { "rawValue": 54, "sdkCase": "menuItem", "name": "MenuItem" }, + { "rawValue": 55, "sdkCase": "menuBar", "name": "MenuBar" }, + { "rawValue": 56, "sdkCase": "menuBarItem", "name": "MenuBarItem" }, + { "rawValue": 57, "sdkCase": "map", "name": "Map" }, + { "rawValue": 58, "sdkCase": "webView", "name": "WebView" }, + { "rawValue": 59, "sdkCase": "incrementArrow", "name": "IncrementArrow" }, + { "rawValue": 60, "sdkCase": "decrementArrow", "name": "DecrementArrow" }, + { "rawValue": 61, "sdkCase": "timeline", "name": "Timeline" }, + { "rawValue": 62, "sdkCase": "ratingIndicator", "name": "RatingIndicator" }, + { "rawValue": 63, "sdkCase": "valueIndicator", "name": "ValueIndicator" }, + { "rawValue": 64, "sdkCase": "splitGroup", "name": "SplitGroup" }, + { "rawValue": 65, "sdkCase": "splitter", "name": "Splitter" }, + { "rawValue": 66, "sdkCase": "relevanceIndicator", "name": "RelevanceIndicator" }, + { "rawValue": 67, "sdkCase": "colorWell", "name": "ColorWell" }, + { "rawValue": 68, "sdkCase": "helpTag", "name": "HelpTag" }, + { "rawValue": 69, "sdkCase": "matte", "name": "Matte" }, + { "rawValue": 70, "sdkCase": "dockItem", "name": "DockItem" }, + { "rawValue": 71, "sdkCase": "ruler", "name": "Ruler" }, + { "rawValue": 72, "sdkCase": "rulerMarker", "name": "RulerMarker" }, + { "rawValue": 73, "sdkCase": "grid", "name": "Grid" }, + { "rawValue": 74, "sdkCase": "levelIndicator", "name": "LevelIndicator" }, + { "rawValue": 75, "sdkCase": "cell", "name": "Cell" }, + { "rawValue": 76, "sdkCase": "layoutArea", "name": "LayoutArea" }, + { "rawValue": 77, "sdkCase": "layoutItem", "name": "LayoutItem" }, + { "rawValue": 78, "sdkCase": "handle", "name": "Handle" }, + { "rawValue": 79, "sdkCase": "stepper", "name": "Stepper" }, + { "rawValue": 80, "sdkCase": "tab", "name": "Tab" }, + { "rawValue": 81, "sdkCase": "touchBar", "name": "TouchBar" }, + { "rawValue": 82, "sdkCase": "statusItem", "name": "StatusItem" } + ] +} diff --git a/packages/capture-kit/src/ios-snapshot-engine/geometry-policy.ts b/packages/capture-kit/src/ios-snapshot-engine/geometry-policy.ts index cb0b61251c..c865558b99 100644 --- a/packages/capture-kit/src/ios-snapshot-engine/geometry-policy.ts +++ b/packages/capture-kit/src/ios-snapshot-engine/geometry-policy.ts @@ -53,11 +53,11 @@ export const SYSTEM_WINDOW_CLASSES: ReadonlySet = new Set([ * `Element()` for the same node, so both spellings count; the raw-value spelling is derived from * these numbers rather than listed beside them (#3565). * - * The numbers belong to `ELEMENT_TYPE_NAMES` in `packages/platform-apple/src/snapshot-source/tree.ts`, - * which is the table that turns an accessibility raw value into one of these names, and nothing imports - * across that boundary — capture-kit sits below platform-apple. The golden table's vocabulary is the tie - * that keeps the two in agreement: its parity test is read both by that package's own test, which - * re-derives each name's index from the owner's table, and by both classifier parity tests. + * The numbers belong to `contracts/fixtures/ios-element-type-names.json`, the shared element-type table + * that names this rule's `Sheet`, `Drawer`, `Alert` and `Dialog` rows, and nothing imports across that + * boundary — capture-kit sits below platform-apple. The golden table's vocabulary is the tie that keeps + * this rule in agreement with both producers: its parity test is read both by the bridge test, which + * re-derives each name's index from `ELEMENT_TYPE_NAMES`, and by both classifier parity tests. */ export const PRESENTING_ELEMENT_TYPES: ReadonlyMap = new Map([ ['Sheet', 5], diff --git a/packages/capture-kit/src/snapshot-occlusion.ts b/packages/capture-kit/src/snapshot-occlusion.ts index 8d96938c7d..e8d3343bf6 100644 --- a/packages/capture-kit/src/snapshot-occlusion.ts +++ b/packages/capture-kit/src/snapshot-occlusion.ts @@ -38,7 +38,6 @@ const VIEWPORT_CHROME_TOP_INSET_PT = 4; const TOOLBAR_HOST_KIND_FRAGMENTS = ['toolbar']; const TAB_BAR_KIND_FRAGMENTS = ['tabbar']; const NAVIGATION_BAR_KIND_FRAGMENTS = ['navigationbar']; -const SCROLL_INDICATOR_KIND_FRAGMENTS = ['scrollbar', 'scrollindicator']; const SEMANTIC_TOUCH_KIND_FRAGMENTS = [ 'button', 'link', @@ -621,11 +620,12 @@ function isNavigationBarAround(bar: RawSnapshotNode, rect: Rect): boolean { ); } -/** A bar or a scroll container inside `rect`; a scroll indicator is not a container. */ +/** + * A bar or a scroll container inside `rect`. {@link isScrollableNodeLike} answers no for a scroll + * indicator, whose class names scrolling while it holds nothing to scroll. + */ function isEnclosedHostedRegion(rect: Rect, node: RawSnapshotNode): boolean { - const isHostedRegion = - isViewportChromeBarNode(node) || - (isScrollableNodeLike(node) && !nodeKindIncludesAny(node, SCROLL_INDICATOR_KIND_FRAGMENTS)); + const isHostedRegion = isViewportChromeBarNode(node) || isScrollableNodeLike(node); const nodeRect = positiveRect(node.rect); return Boolean(isHostedRegion && nodeRect && rectContains(rect, nodeRect)); } diff --git a/packages/capture-kit/src/snapshot/snapshot-lines.ts b/packages/capture-kit/src/snapshot/snapshot-lines.ts index da3582ee08..b607222117 100644 --- a/packages/capture-kit/src/snapshot/snapshot-lines.ts +++ b/packages/capture-kit/src/snapshot/snapshot-lines.ts @@ -1,4 +1,5 @@ import { isSystemScrollIndicatorLabel } from '@agent-device/kernel/scroll-indicator'; +import { isScrollIndicatorNode } from '@agent-device/contracts/snapshot'; import { formatRole } from '@agent-device/kernel/snapshot'; import type { SnapshotNode } from '@agent-device/kernel/snapshot'; import type { ElementMatchCandidateDetails } from '@agent-device/kernel/errors'; @@ -259,6 +260,9 @@ function looksScrollable(node: SnapshotNode, type: string): boolean { if (type === 'scroll-area') { return true; } + if (isScrollIndicatorNode(node)) { + return false; + } const rawType = (node.type ?? '').toLowerCase(); const rawRole = `${node.role ?? ''} ${node.subrole ?? ''}`.toLowerCase(); return rawType.includes('scroll') || rawRole.includes('scroll'); diff --git a/packages/contracts/src/facades/snapshot.ts b/packages/contracts/src/facades/snapshot.ts index ce0fc1b87a..990c33b6cc 100644 --- a/packages/contracts/src/facades/snapshot.ts +++ b/packages/contracts/src/facades/snapshot.ts @@ -1,4 +1,8 @@ -export { isScrollableNodeLike, isScrollableType } from '../snapshot-scroll.ts'; +export { + isScrollIndicatorNode, + isScrollableNodeLike, + isScrollableType, +} from '../snapshot-scroll.ts'; export { findSnapshotScopeRange, matchesSnapshotScope, diff --git a/packages/contracts/src/snapshot-scroll.test.ts b/packages/contracts/src/snapshot-scroll.test.ts index 88205ee891..09db5480e5 100644 --- a/packages/contracts/src/snapshot-scroll.test.ts +++ b/packages/contracts/src/snapshot-scroll.test.ts @@ -15,5 +15,40 @@ test('snapshot scroll semantics classify scrollable types and node-like roles', assert.equal(isScrollableType('collection'), true); assert.equal(isScrollableType('collectionitem'), false); assert.equal(isScrollableNodeLike(scrollView), true); - assert.equal(isScrollableNodeLike({ role: 'scrollbar' }), true); +}); + +/** + * The names the iOS producers publish for an element type. A scroll bar names the indicator riding + * beside scrollable content, so it holds no content a scroll moves: the runner publishes the name + * now, and the fragment match below read the 3pt bar as its own container (#4657). The check is the + * same one a bridge or Linux capture already met, because both spellings — the producer's `ScrollBar` + * and UIKit's `_UIScrollViewScrollIndicator` — name the indicator. + */ +test.for(['ScrollBar', 'scrollindicator', 'AXScrollBar', 'collectionitem', 'Element(47)', 'Other'])( + 'the scroll indicator %s is not a scroll container', + (type) => { + assert.equal(isScrollableType(type), false); + }, +); + +test.for([ + { type: 'ScrollBar', role: 'ScrollBar' }, + { type: 'Other', role: 'UIScrollViewScrollIndicator' }, + { type: 'Other', role: 'AXScrollBar' }, + { type: 'Other', role: '', subrole: 'AXScrollBar' }, +])('the scroll indicator node %j is not a scroll container', (node) => { + assert.equal(isScrollableNodeLike(node), false); +}); + +test.for([ + 'ScrollView', + 'ScrollArea', + 'Table', + 'CollectionView', + 'android.widget.ScrollView', + 'androidx.recyclerview.widget.RecyclerView', + 'com.facebook.react.views.scroll.ReactScrollView', +])('the scroll container %s stays scrollable', (type) => { + assert.equal(isScrollableType(type), true); + assert.equal(isScrollableNodeLike({ type }), true); }); diff --git a/packages/contracts/src/snapshot-scroll.ts b/packages/contracts/src/snapshot-scroll.ts index 166f1f4fbd..802fd48b32 100644 --- a/packages/contracts/src/snapshot-scroll.ts +++ b/packages/contracts/src/snapshot-scroll.ts @@ -1,24 +1,57 @@ +import type { RawSnapshotNode } from '@agent-device/kernel/snapshot'; +import { normalizeType, snapshotNodeKindIncludesAny } from './snapshot-text.ts'; + +/** + * The scroll indicator's own names, spaced and unspaced: a producer spells it `ScrollBar` or + * `UIScrollViewScrollIndicator`, and a web role carries the space. A fragment cannot tell these from + * the containers they ride beside — `ScrollBar` carries the "scroll" fragment — so a caller that + * would scroll, swipe inside, or clip by a node has to rule the indicator out by name first: a + * command aimed at a scroll bar lands on a 3pt bar. The runner publishes the name now, which is what + * surfaced the trap (#4657). + */ +const SCROLL_INDICATOR_KIND_FRAGMENTS = [ + 'scrollbar', + 'scroll bar', + 'scrollindicator', + 'scroll indicator', +]; + export function isScrollableType(type: string | null | undefined): boolean { - const value = `${type ?? ''}`.toLowerCase(); + // An Android helper node publishes null for a type it could not read; nothing scrolls there. + const value = type ?? ''; + if (!value || isScrollIndicatorNode({ type: value })) { + return false; + } + const normalized = normalizeType(value); return ( - value.includes('scroll') || - value.includes('recyclerview') || - value.includes('listview') || - value.includes('gridview') || - value.includes('collectionview') || - value === 'collection' || - value === 'table' + normalized.includes('scroll') || + normalized.includes('recyclerview') || + normalized.includes('listview') || + normalized.includes('gridview') || + normalized.includes('collectionview') || + normalized === 'collection' || + normalized === 'table' ); } -export function isScrollableNodeLike(node: { - type?: string | null; - role?: string | null; - subrole?: string | null; -}): boolean { +/** Whether a node names a scroll indicator — the bar or knob, not the content beside it. */ +export function isScrollIndicatorNode( + node: Pick, +): boolean { + return snapshotNodeKindIncludesAny(node, SCROLL_INDICATOR_KIND_FRAGMENTS); +} + +export function isScrollableNodeLike( + node: Pick, +): boolean { + if (isScrollIndicatorNode(node)) { + return false; + } if (isScrollableType(node.type)) { return true; } + // A producer that states the fact in its class rather than its type answers here, which is why the + // indicator is ruled out first: `_UIScrollViewScrollIndicator` says "scroll" and holds nothing. const role = `${node.role ?? ''} ${node.subrole ?? ''}`.toLowerCase(); return role.includes('scroll'); } diff --git a/packages/platform-apple/src/snapshot-source/tree.test.ts b/packages/platform-apple/src/snapshot-source/tree.test.ts index b6eaefcaa2..aa588767a5 100644 --- a/packages/platform-apple/src/snapshot-source/tree.test.ts +++ b/packages/platform-apple/src/snapshot-source/tree.test.ts @@ -772,6 +772,46 @@ test('the element-type names the presented-surface rule reads are the ones this } }); +/** + * The shared element-type table `contracts/fixtures/ios-element-type-names.json` is what both iOS + * producers read for a node's `type` (#4657). This is the bridge's half of that tie: it decodes every + * raw value the way a real capture does and holds the published name against the table. The runner's + * half is `RunnerTests+ElementTypeNamesTests`, so a rename that reaches one producer and not the + * other fails on the side that moved. + */ +test('the bridge names every raw value the shared element-type table names', () => { + const table = JSON.parse( + fs.readFileSync( + path.resolve( + import.meta.dirname, + '..', + '..', + '..', + '..', + 'contracts', + 'fixtures', + 'ios-element-type-names.json', + ), + 'utf8', + ), + ) as { types: Array<{ rawValue: number; name: string }> }; + assert.ok(table.types.length > 0); + + for (const { rawValue, name } of table.types) { + const decoded = decodeSnapshotBridgeTree( + { + [application]: 'Application', + [frame]: { X: 0, Y: 0, Width: 390, Height: 844 }, + [children]: [{ [automationType]: rawValue, [children]: [] }], + }, + { truncated: false }, + limits, + ); + + assert.equal(decoded.nodes[1]?.type, name, `raw element type ${rawValue}`); + } +}); + const traitClassification = JSON.parse( fs.readFileSync( new URL('../../../../contracts/fixtures/ios-trait-classification.json', import.meta.url), diff --git a/packages/platform-apple/src/snapshot-source/tree.ts b/packages/platform-apple/src/snapshot-source/tree.ts index bac1e96393..0fb8e7bdb0 100644 --- a/packages/platform-apple/src/snapshot-source/tree.ts +++ b/packages/platform-apple/src/snapshot-source/tree.ts @@ -26,6 +26,14 @@ const ATTRIBUTE = Object.freeze({ children: 'XC_kAXXCAttributeChildren', }); +/** + * The bridge's half of the element-type names both iOS producers publish, indexed by the raw value the + * SDK numbers each type with. `contracts/fixtures/ios-element-type-names.json` holds the same rows, and + * the XCTest runner mirrors them in `elementTypeNamesByRawValue` + * (`apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift`), so one node + * carries one `type` whichever producer served it (#4657). `tree.test.ts` re-derives every index from + * this array against that table. + */ const ELEMENT_TYPE_NAMES: readonly string[] = [ 'Other', 'Other', diff --git a/packages/selectors/src/node-touch-point.ts b/packages/selectors/src/node-touch-point.ts index dfc0285e08..2da6a2a23a 100644 --- a/packages/selectors/src/node-touch-point.ts +++ b/packages/selectors/src/node-touch-point.ts @@ -126,19 +126,12 @@ function findPrecedingScrollContainer( candidate.parentIndex === node.parentIndex && candidate.index < node.index && hasUsableRect(candidate) && - isScrollableNodeLike(candidate) && - !isScrollIndicator(candidate), + isScrollableNodeLike(candidate), ) .at(-1) ?? null ); } -/** A scroll bar's kind also says "scroll", and it is not what the target scrolled out of. */ -function isScrollIndicator(node: SnapshotNode): boolean { - const kind = `${node.type ?? ''} ${node.role ?? ''} ${node.subrole ?? ''}`.toLowerCase(); - return /scroll\s?(bar|indicator)/.test(kind); -} - /** * The recovery for a target with no usable frame beside a scroll container. The frame that * refuses the touch point is also the one that would have named the direction, so the hint names