In my macOS app I have a SwiftUI list that starts like this:
List(selection: $selection) {
HStack {
Label("Staging", systemImage: "arrow.up.square")
Spacer()
WorkspaceStatusBadge(unstagedCount: model.statusCounts.unstaged,
stagedCount: model.statusCounts.staged)
}
(where WorkspaceStatusBadge
is a custom view that just contains a Text
)
I'm trying to set the accessibility ID of that first cell so I can find it in XCUITest. If I apply the accessibilityIdentifier()
modifier to the HStack
, it instead sets the ID of the two static text elements inside it, and the cell still has no ID.
I could find the cell based on the ID of the child staticText, but I have some other cases where this doesn't work as well.
If I use .accessibilityElement()
on the HStack, then XCUI sees a cell containing a Group element with the ID. This might be workable, but it's certainly not ideal.
So how do I set the ID of the cell itself?