.accessilityIdentifier not working for buttons in .toolbar

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") }

}

Hi, thanks for bringing this to our attention. Do you have a feedback number on this? Have you tried it with recents betas of iOS 15?

.accessilityIdentifier not working for buttons in .toolbar
 
 
Q