Post

Replies

Boosts

Views

Activity

Make popover visible in accessibility tree in MacOS
I’m on macOS Monterey 12.4, XCode 13.3.1. Building a MacOS app in SwiftUI. I have a popover that displays when clicking on a button (for an example, open up the Apple Reminders app on Mac, click Add List and click on one of the Icon: images on the right. Notice the popup with many icons to choose from). However, I cannot figure out how to make the popover part of the Accessibility Tree so I can emulate a click on it using UI Testing. What am I missing? Here’s a simplified version of my code, which shows the issue: private struct AStruct: Identifiable { let name: String var id: String { name } } private let someStructs: [AStruct] = [ AStruct(name: "A"), AStruct(name: "B"), AStruct(name: "C"), AStruct(name: "D"), AStruct(name: "E") ] struct ContentView: View { @State private var showingPopover = false var body: some View { HStack { Button { showingPopover = true } label: { Text ("Show Popup") } .accessibilityIdentifier("clickhere") .popover(isPresented: $showingPopover, arrowEdge: .bottom) { PopupMenu() } .padding() } } } struct PopupMenu: View { var body: some View { VStack(alignment: .leading, spacing: 0) { HStack(alignment: .top, spacing: 0) { ForEach(someStructs) { aStruct in Button(action: { print(aStruct.name) }, label: { Image(systemName: "circlebadge.fill") .padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 8)) .font(.title3) }) .buttonStyle(PlainButtonStyle()) } } } .padding() } } Here is the test case: class Tests_macOS: XCTestCase { func test_ShowTree() throws { let app = XCUIApplication() app.launch() app.windows.buttons.element(matching: .button, identifier: "clickhere").click() print(app.debugDescription) } } And here is what the tree shows (menus omitted for brevity): Element subtree: →Application, 0x10a704500, pid: 72192, title: 'TestPopupAccessibility', Disabled Window (Main), 0x10a705090, {{1126.0, 346.0}, {124.0, 80.0}}, identifier: 'TestPopupAccessibility.ContentView-1-AppWindow-1', title: 'TestPopupAccessibility', Keyboard Focused, Disabled Button, 0x10a7056e0, {{1142.0, 390.0}, {92.0, 20.0}}, identifier: 'clickhere', title: 'Show Popup' Button, 0x10a705810, {{1133.0, 352.0}, {14.0, 16.0}}, identifier: '_XCUI:CloseWindow' Button, 0x10a706ba0, {{1173.0, 352.0}, {14.0, 16.0}}, identifier: '_XCUI:FullScreenWindow' Button, 0x10a706cd0, {{1153.0, 352.0}, {14.0, 16.0}}, identifier: '_XCUI:MinimizeWindow' StaticText, 0x10a706e00, {{1193.0, 351.0}, {51.0, 16.0}}, value: TestPopupAccessibi... I've tried modifying the accessibilityChildren, but I'm not even sure this is the right approach. The things i can find online are very sparse.
0
1
577
Oct ’22