XCUITests for Accessibility
For a while now I’ve been looking at possibilities for automated accessibility testing on iOS. Unfortunately, I’ve not found any option so far that I’m happy with. I am a big fan of Apple’s XCUI Test framework. Although it has its limitations, I believe there’s scope for creating valid accessibility tests using this framework. Over the last few months I’ve been trying things out, and here’s what I’ve come up with.
These tests are all part of an open source library I created called A11yUITests, available on GitHub. You can pull this library in using Cocoapods and use these tests in a friendly way. I document them here to help you change and adapt them for your own use. And to spark discussion on how valid these tests are, and how we can improve upon them.
In creating these tests I’ve followed WCAG guidelines and Apple’s recommendations on accessibility. For inspiration, I’ve researched Deque’s commercial iOS Accessibility testing tool WorldSpace Attest and Android’s Espresso accessibility checks library.
Any XCUITest is an Accessibility Test
XCUITests uses your app’s accessibility tree, this means any well-written XCUITest is an accessibility test. Many XCUITest suites I’ve seen make one mistake though. When you’re finding an element on screen, always use the element’s label, not the accessibility identifier. The identifier is designed to help you with XCUITests, but it doesn’t guarantee your content has been set to the element. By finding an element by its…