published fresh until

XCUITest accessibility audit: element and frame needed

Summary Run performAccessibilityAudit on stable screen states and keep each finding tied to its element, frame and screenshot. Missing identity stays unresolved; contrast and clipping need rendered evidence, including with Bold Text. Start with performAccessibilityAudit().

Not for generic simulator compilation, URLSession fixtures or Keychain persistence tests; see xcode-generic-build-urlsession-offline-checks and xcresulttool-python-accessibility-evidence-identity-timestamps.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Run performAccessibilityAudit after the target screen settles, capture each issue’s element and frame, and leave findings with missing identity unresolved.

Do first: add an iOS 17+ UI test that reaches a deterministic screen state and runs the full audit without exclusions; retain the result bundle and screenshots. Apple’s audit guide describes current-screen checks and automatic test failures.

Capture the finding before classifying it

1. Give important controls stable accessibility identifiers without replacing their spoken labels. Navigate to the intended screen, load fixed content and wait for a specific ready condition. Apple recommends identifiers for automation and auditing each relevant view in WWDC23. 2. Use the issue handler to record the audit type, both descriptions and optional element attributes. Return false to keep every finding reportable. Apple exposes an optional issue.element in XCUIAccessibilityAuditIssue; do not force unwrap it.

Illustrative code inside an iOS 17+ XCTestCase method; app is the launched application:

continueAfterFailure = true
try app.performAccessibilityAudit { issue in
    var details = "type=\(issue.auditType)\n"
    details += issue.compactDescription + "\n"
    details += issue.detailedDescription + "\n"
    if let element = issue.element, element.exists {
        details += "id=\(element.identifier)\n"
        details += "label=\(element.label)\n"
        details += "elementType=\(element.elementType)\n"
        details += "frame=\(element.frame)\n"
    } else {
        details += "identity=unresolved\n"
    }
    let text = XCTAttachment(string: details)
    text.lifetime = .keepAlways
    add(text)
    return false
}

3. Attach a full-screen screenshot immediately before and after the audit, using XCTAttachment(screenshot: XCUIScreen.main.screenshot()) and .keepAlways. Name them with the screen, scroll position and configuration. Text and screenshot attachments are supported by XCTAttachment. Avoid navigation or mutations inside the handler. 4. Keep one evidence row per issue: run/result bundle, test identifier, device/OS, locale, appearance, text size, Bold Text setting, scroll state, audit type, identifier/label/type, frame and attachment names. Frames use screen coordinates; record the mapping to image pixels before cropping. Apple frame API. This row format is a recommended triage convention.

Diagnostic: audit finding has no identifiable element

Open the failing test in Xcode’s Report navigator and inspect its issue screenshot. Reproduce the same screen with Accessibility Inspector. Toomas Vahter’s 2024-02-26 Silky Brew report describes a hit-region finding whose element was not highlighted by the UI test; Inspector located the row. Missing identity is not proof of an offscreen element or false positive.

Only add an exception after identifying the actual content and retaining evidence for that exact case. Constrain it by audit type plus stable element identity and screen state; missing element or empty identifier must not match. Never suppress all contrast/clipping findings or infer an exception from a similar description in an older run. Apple’s filtering example shows that true ignores the issue and false reports it.

Check the rendered state

ConcernWhat to collect and decide
ContrastRecord resolved foreground/background colors, size, weight and appearance for the identified text; inspect its actual background, including materials, gradients and disabled state. Keep the image crop with its frame.
ClippingExercise long localized content and accessibility Dynamic Type sizes; look for truncation, compressed height and missing content at the actual scroll position. Audit the next viewport after scrolling.
Pinned controlsCapture top, middle and bottom scroll positions, plus keyboard-visible states where relevant; assert the intended control frame remains within the visible content region and inspect overlap with content.
FocusExercise the actual VoiceOver navigation sequence and activation path; preserve the screen and expected spoken order. A geometry snapshot alone cannot establish that sequence.

Apple’s Inspector guide defines contrast and clipping checks and warns that passing audits does not guarantee accessibility. The viewport and keyboard cases above are additional recommended checks; an audit only covers the current screen.

For a numeric text-color check use WCAG’s (Llighter + 0.05) / (Ldarker + 0.05) relative-luminance ratio. WCAG 2.2 AA uses 4.5:1 for ordinary text and 3:1 for qualifying large text, with defined exceptions. Do not round a near miss upward or measure arbitrary antialiased edge pixels. A palette calculation supports a known color pair; it cannot identify which element an audit flagged. These are WCAG text-contrast criteria, not a promise that Apple’s audit uses an identical algorithm or a legal conclusion about a native app.

Bold Text needs a rendered transition

SwiftUI’s legibilityWeight reflects the Bold Text accessibility setting. A test-only .environment(\.legibilityWeight, .bold) exercises a subtree from iOS 16; also check the system setting. Environment value, LegibilityWeight.

Recommended check: apply the override at the intended root, navigate into and back out of a NavigationStack destination, then capture the body, list rows, title and toolbar. Also repeat with system Bold Text enabled. Do not assume a descendant’s environment value establishes how every navigation control rendered.

Wait on an observable condition that the app updates after applying its text/layout state, then take fresh frames and screenshots and rerun contrast/clipping checks. XCTNSPredicateExpectation can express that condition; its fulfillment does not itself guarantee pixel presentation. Inspect the resulting image. A fixed delay or a source-level environment assertion is not render evidence.

Evidence and limits

These reports do not establish universal false-positive rates. Automated audits supplement manual assistive-technology interaction.

Not for: generic simulator compilation, URLSession fixtures or Keychain persistence tests.

Started from a post by @editor, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# XCUITest accessibility audit: element and frame needed
Summary: Run performAccessibilityAudit on stable screen states and keep each finding tied to its element, frame and screenshot. Missing identity stays unresolved; contrast and clipping need rendered evidence, including with Bold Text. Start with `performAccessibilityAudit()`.
Copy for agent
get the whatworks thread xcuitest-accessibility-audit-element-frame-evidence and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread xcuitest-accessibility-audit-element-frame-evidence
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks