App/UITests/AccessibilityAuditTests.swift
50 lines · 1809 bytes
1import XCTest
2
3/// Runs Xcode's accessibility audit on each main screen and prints every issue.
4/// Issues are recorded, not failed, so one run reports everything.
5final class AccessibilityAuditTests: XCTestCase {
6 var app: XCUIApplication!
7 var issues: [String] = []
8
9 override func setUp() {
10 continueAfterFailure = true
11 app = XCUIApplication()
12 app.launchArguments += ["-onboarded", "YES", "-locationMode", "city", "-nightMode", "off"]
13 app.launch()
14 }
15
16 private func audit(_ screen: String, _ types: XCUIAccessibilityAuditType = .all) {
17 try? app.performAccessibilityAudit(for: types) { issue in
18 let label = issue.element?.label ?? ""
19 let id = issue.element?.identifier ?? ""
20 let line = "[\(screen)] \(issue.auditType): \(issue.compactDescription) — element: '\(label)' \(id)"
21 self.issues.append(line)
22 print("A11Y " + line)
23 return true
24 }
25 }
26
27 private func tab(_ name: String) {
28 app.tabBars.buttons[name].firstMatch.tap()
29 sleep(3)
30 }
31
32 func testAuditAllScreens() {
33 sleep(3)
34 audit("Sky")
35 app.buttons["Explore"].tap()
36 app.buttons["Settings"].tap(); sleep(1)
37 audit("Settings")
38 app.buttons["Done"].tap(); sleep(1)
39 tab("System"); audit("System")
40 tab("Sun"); audit("Sun")
41 tab("News & launches"); audit("News & launches")
42 tab("Library"); audit("Library")
43 app.buttons["See all Planets"].firstMatch.tap(); sleep(1)
44 app.staticTexts["Saturn"].firstMatch.tap(); sleep(2)
45 audit("Library page: Saturn")
46 print("ACCESSIBILITY-AUDIT-BEGIN")
47 issues.forEach { print($0) }
48 print("ACCESSIBILITY-AUDIT-END \(issues.count) issues")
49 }
50}