Skip to content

Commit c1b94a2

Browse files
authored
Automatic Accessibility Audits on previews part 1 (#4322)
* setup target * accessibility tests implementation * removed ipad check * pr improvements * updated project
1 parent 7495265 commit c1b94a2

File tree

18 files changed

+951
-8
lines changed

18 files changed

+951
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Copyright 2022-2024 New Vector Ltd.
3+
//
4+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
// Please see LICENSE files in the repository root for full details.
6+
//
7+
8+
import XCTest
9+
10+
enum Application {
11+
static func launch(viewID: String) -> XCUIApplication {
12+
checkEnvironments()
13+
14+
let app = XCUIApplication()
15+
16+
let launchEnvironment = [
17+
"ACCESSIBILITY_VIEW": viewID
18+
]
19+
20+
app.launchEnvironment = launchEnvironment
21+
app.launch()
22+
return app
23+
}
24+
25+
private static func checkEnvironments() {
26+
let requirediPhoneSimulator = "iPhone17,3" // iPhone 16
27+
let requiredOSVersion = 18
28+
29+
let osVersion = ProcessInfo().operatingSystemVersion
30+
guard osVersion.majorVersion == requiredOSVersion else {
31+
fatalError("Switch to iOS \(requiredOSVersion) for these tests.")
32+
}
33+
34+
guard let deviceModel = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] else {
35+
fatalError("Unknown simulator.")
36+
}
37+
guard deviceModel == requirediPhoneSimulator else {
38+
fatalError("Running on \(deviceModel) but we only support \(requirediPhoneSimulator)")
39+
}
40+
}
41+
}

AccessibilityTests/Sources/Test.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Copyright 2025 New Vector Ltd.
3+
//
4+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
// Please see LICENSE files in the repository root for full details.
6+
//
7+
8+
import XCTest
9+
10+
@MainActor
11+
class Test: XCTestCase {
12+
var app: XCUIApplication!
13+
14+
func test() async throws {
15+
let client = try UITestsSignalling.Client(mode: .tests)
16+
app = Application.launch(viewID: "SecureBackupLogoutConfirmationScreen_Previews")
17+
await client.waitForApp()
18+
defer { try? client.stop() }
19+
20+
try client.send(.accessibilityAudit(.nextPreview))
21+
forLoop: for await signal in client.signals.values {
22+
switch signal {
23+
case .accessibilityAudit(let auditSignal):
24+
switch auditSignal {
25+
case .nextPreviewReady(let name):
26+
try? app.performAccessibilityAudit { issue in
27+
XCTFail("\(name): \(issue)")
28+
return true
29+
}
30+
try? client.send(.accessibilityAudit(.nextPreview))
31+
case .noMorePreviews:
32+
break forLoop
33+
default:
34+
fatalError("Unhandled signal")
35+
}
36+
default:
37+
fatalError("Unhandled signal")
38+
}
39+
}
40+
41+
app.terminate()
42+
}
43+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "EFC6A442-D3B7-4273-B349-7A923C06AF5E",
5+
"name" : "Default",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"addressSanitizer" : {
13+
"enabled" : true
14+
},
15+
"codeCoverage" : {
16+
"targets" : [
17+
{
18+
"containerPath" : "container:ElementX.xcodeproj",
19+
"identifier" : "C0FAEB81CFD9776CD78CE489",
20+
"name" : "ElementX"
21+
}
22+
]
23+
},
24+
"defaultTestExecutionTimeAllowance" : 120,
25+
"environmentVariableEntries" : [
26+
27+
],
28+
"language" : "en-US",
29+
"locationScenario" : {
30+
"identifier" : "San Francisco, CA, USA",
31+
"referenceType" : "built-in"
32+
},
33+
"region" : "US",
34+
"targetForVariableExpansion" : {
35+
"containerPath" : "container:ElementX.xcodeproj",
36+
"identifier" : "C0C687DE1D270F9895FEE186",
37+
"name" : "AccessibilityTests"
38+
},
39+
"testTimeoutsEnabled" : true,
40+
"undefinedBehaviorSanitizerEnabled" : true
41+
},
42+
"testTargets" : [
43+
{
44+
"target" : {
45+
"containerPath" : "container:ElementX.xcodeproj",
46+
"identifier" : "C0C687DE1D270F9895FEE186",
47+
"name" : "AccessibilityTests"
48+
}
49+
}
50+
],
51+
"version" : 1
52+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>BNDL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: AccessibilityTests
2+
3+
schemes:
4+
AccessibilityTests:
5+
analyze:
6+
config: Debug
7+
archive:
8+
config: Release
9+
build:
10+
targets:
11+
AccessibilityTests: all
12+
profile:
13+
config: Release
14+
run:
15+
config: Debug
16+
disableMainThreadChecker: false
17+
test:
18+
config: Debug
19+
testPlans:
20+
- path: AccessibilityTests.xctestplan
21+
defaultPlan: true
22+
23+
targets:
24+
AccessibilityTests:
25+
type: bundle.ui-testing
26+
platform: iOS
27+
28+
dependencies:
29+
- target: ElementX
30+
- package: KZFileWatchers
31+
32+
info:
33+
path: ../SupportingFiles/Info.plist
34+
35+
settings:
36+
base:
37+
PRODUCT_NAME: AccessibilityTests
38+
PRODUCT_BUNDLE_IDENTIFIER: ${BASE_BUNDLE_IDENTIFIER}.accessibility.tests
39+
configs:
40+
# This is required to remove the $(inherited) flags
41+
# which would prevent SnapshotTesting to be imported in UI Tests
42+
debug:
43+
OTHER_SWIFT_FLAGS: ["-DDEBUG"]
44+
release:
45+
OTHER_SWIFT_FLAGS: ["-DRELEASE"]
46+
47+
sources:
48+
- path: ../Sources
49+
- path: ../SupportingFiles
50+
- path: ../../ElementX/Sources/UITests/UITestsSignalling.swift
51+

0 commit comments

Comments
 (0)