How to use accessibility identifiers in Swift Testing

Oscar de la Hera Gomez
Three flowers that represent Swift, Swift Testing and XCode side by side. Beneath them sits the text "Accessibility Identifiers".

Accessibility identifiers allow for effective automated UI testing. To use them on any view, add the .accessibilityIdentifier modifier.

The following tutorial shows how we found temporary files from our upcoming app Object Capture Pro. If you wish to be updated on the progress and release of this app, please subscribe using the link below.

Step One: Add an Accessibility Identifier

A screenshot of XCode showing the struct that holds all our accessibility identifiers.

We recommend that you create a struct that holds all the identifiers and then apply them using the .accessibilityIdentifier modifier.

A screenshot showing how we added an accessibility identifier to our MainView.

Step Two: Use the Identifier in a UITest

A screenshot showing code that returns a view that has an accessibility identifier within an app.

In a UITest, use the identifier to find the view.

You can either do by searching the app for any view or to target specific types of views like buttons.

For the code found above, consult the post below.

A screenshot showing how we search for a specific button within the navigation bar using an accessibility identifier.

For more information consult the documentation below.

Looking to debug accessibility identifiers?

Consult our guide below to learn how to debug accessibility identifiers.

Looking to make nested accessibility identifiers work?

To learn how to use accessibility identifiers within views that use accessibility identifiers, consult the post below.

Looking to learn more about SwiftUI, Swift, Swift Testing, Design and Technology?

Search our blog to learn more about Swift, SwiftUI, Swift Testing, design and technology.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details