Updating my code to use .toolbar (with ToolbarItem) rather than .navigationBarItems I've run into a problem with the accessibilityIdentifiers. They no longer seem to show up in the view hierarchy, and so all UI tests are breaking.
Anyone know how to fix this? (I would like to avoid having to change all UI tests to search for button label, since the use of accessibilityIdentifiers generally gives more stable UI-tests)
struct SwiftUIView: View {
let myFunction: () -> Void
let myOtherFunction: () -> Void
var body: some View {
Form {
Text("Hello World!")
}
.navigationBarTitle("My Title", displayMode: .inline)
//VERSION 1: navigationBar-version (works, but deprecated)
.navigationBarItems(leading: cancelButton,
trailing: addButton)
//VERSION 2: toolbar-version (.accessibilityIdentifiers do not work)
.toolbar {
ToolbarItem(placement: .cancellationAction) { cancelButton }
ToolbarItem(placement: .confirmationAction) { addButton }
}
}
var cancelButton: some View {
Button(action: myFunction,
label: { Text("Cancel") })
.accessibilityIdentifier("MyTitleView_CancelButton") }
var addButton: some View {
Button(action: myOtherFunction,
label: { Text("Add") })
.accessibilityIdentifier("MyTitleView_AddButton") }
}