Check your iOS app's accessibility automatically in CI
Apple’s performAccessibilityAudit finds accessibility issues from a UI test. Call it in your UI test after navigating to each screen you want to audit.
This post shows the Apple call first. Then you audit every screen a UI check visits without test code, and get a failed check in CI when the audit finds an issue.
Audit one screen with XCTest
performAccessibilityAudit(for:_:) is a method on XCUIApplication, in Apple’s XCUIAutomation framework. Apple’s documentation lists it for iOS 17 and later. In WWDC23’s session, Apple says it audits the current view the way the Inspector does, and that a test fails when it finds an issue, with no assertion needed:
func testAccessibility() throws { let app = XCUIApplication() app.launch() try app.performAccessibilityAudit()}The first parameter is an option set of audit types. Apple’s XCUIAccessibilityAuditType lists action, contrast, dynamicType, elementDetection, hitRegion, parentChild, sufficientElementDescription, textClipped, trait and all. The second parameter is a closure called for every issue. Return true to ignore an issue. By default nothing is ignored:
try app.performAccessibilityAudit(for: [.dynamicType, .contrast]) { issue in // ignore a contrast issue on one label if let element = issue.element, element.label == "My Label", issue.auditType == .contrast { return true } return false}That filter is the pattern from the session. An issue carries its auditType, element, compactDescription and detailedDescription.
Two limits come from Apple. The audit covers only the elements on screen, so “in order to provide complete coverage,” in Apple’s words, you add an audit test for each view. And audits “shouldn’t substitute real testing with assistive technologies,” which means a pass with VoiceOver and Dynamic Type turned on.
You maintain the navigation and audit calls as the app changes.
Audit every screen a check visits with Mobster
Mobster reads accessibility trees to check text and element assertions. mobster test --audit a11y audits those same trees. The audit calls no model and sends nothing off your Mac. A screen it has seen is audited once.
mobster test --audit a11y # a finding fails its checkTurn on the audit in a check’s file with audit: a11y. Use --audit a11y to apply the audit to every check.
# .mobster/ checks/ checkout.yamlversion: 1name: Checkout reaches the confirmation screenapp: bundle: com.yourname.yourappaudit: a11ysteps: - Add the first item to the cart and tap Checkout.expect: - text: Order confirmedThe audit rides on the steps you already wrote. A check that visits six screens audits six screens. It adds one tree read per step, about a second on a simulator. It cost 0.8 to 1.6 s a screen on an iOS Simulator.
The rules
You get 4 rules in the Mobster audit, with the rule name in each finding:
control-no-label: A button, switch, link, slider, stepper or text field with no label. A placeholder counts as a label for a text field. An identifier doesn’t, because VoiceOver doesn’t read itimage-no-label: An image with no label that isn’t inside a labelled controltarget-too-small: A button, link or switch under 44 by 44 pttext-clipped: Only when the check setsconditions.content_sizetoextra-largeor larger: text whose frame crosses the screen’s side edges or leaves its container
The two lists don’t match one to one. Run both if the difference matters to you.
Fail CI on a finding
You get a failed check with reason.class of finding and exit code 1 when the audit finds an issue. In CI, write the JUnit file too:
mobster test --audit a11y --junit build/ junit.xmlThe next release adds four things. mobster test --a11y reports findings as warnings while your checks still pass. mobster test --a11y --update-a11y-baseline records findings in .mobster/. --a11y=strict fails checks only on findings outside that file. And 3 more rules: duplicate-label, label-unhelpful and unreachable-element.
What your CI reads
junit.xml: You get 1 extra<testcase>per finding, named<check>: <rule>, <element>, with a<failure type="accessibility">. You also get a failure for the check’s own case, so you see both in the CI summary.results.json: each device result’sfindingslists the rule, the guideline, the element with itsrole,label,identifierandrectin points, and the frame of the screen.- The HTML report: You see each check’s findings on its page.
Run iOS UI checks in CI without a device farm builds the workflow around this. The audit works the same on simulators and on a real iPhone with --device. Put audit: a11y in the checks you run with mobster test pr because that command doesn’t apply --audit.
What an automated audit leaves out
- Contrast. Mobster doesn’t audit it. The accessibility tree has no colours, and the pixels under translucent bars, images and gradients don’t give a foreground and background you can trust. XCTest’s
.contrastaudit covers it. - VoiceOver. Mobster reads the tree. It doesn’t drive VoiceOver or listen to what it says.
- Dynamic Type in pixels.
text-clippedreads frames. Text that truncates inside a frame of the right size isn’t found, so a clean run isn’t proof that Dynamic Type works. - A person. An audit finds a missing label. It doesn’t tell you whether the label, read aloud in order, makes sense. Run VoiceOver through your main flows before each release.
Get Mobster for Mac and add audit: a11y to a check. The checks and the audit run on simulators and on your iPhone: free on any number of iPhones (AI runs on a supported AI plan, an API key or a model on your Mac).
Testing lists the flags, and CI shows the JUnit file in GitHub Actions and GitLab. Test your iOS app on a real iPhone with an AI agent covers writing the checks themselves.
Questions
What does performAccessibilityAudit check?
It runs Apple's accessibility audit on the screen in front, the same categories as Xcode's Accessibility Inspector. The audit types are action, contrast, dynamicType, elementDetection, hitRegion, parentChild, sufficientElementDescription, textClipped and trait. It needs iOS 17 or later.
Can I run an iOS accessibility audit in CI without writing test code?
Yes. Use mobster test --audit a11y to audit each screen your saved checks visit and fail a check on a finding. It reads the accessibility tree, so you write no audit calls.
How do I stop an accessibility audit from failing on old problems?
In Mobster 0.4.0, fix the element or leave the audit off that check because every finding fails its check. In the next release, you record findings in .mobster/a11y-baseline.json with mobster test --a11y --update-a11y-baseline and use strict mode to fail checks only on findings outside that file.
Does an automated audit replace testing with VoiceOver?
No. Apple says audits shouldn't substitute for testing with assistive technologies like VoiceOver. An audit finds missing labels and small targets, and a person finds the screen that is confusing to hear.



