Automatic Accessibility Audits on previews part 1 (#4322)

* setup target

* accessibility tests implementation

* removed ipad check

* pr improvements

* updated project
This commit is contained in:
Mauro
2025-07-15 14:40:16 +02:00
committed by GitHub
parent 74952659e8
commit c1b94a2d9f
18 changed files with 951 additions and 8 deletions
@@ -0,0 +1,41 @@
//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import XCTest
enum Application {
static func launch(viewID: String) -> XCUIApplication {
checkEnvironments()
let app = XCUIApplication()
let launchEnvironment = [
"ACCESSIBILITY_VIEW": viewID
]
app.launchEnvironment = launchEnvironment
app.launch()
return app
}
private static func checkEnvironments() {
let requirediPhoneSimulator = "iPhone17,3" // iPhone 16
let requiredOSVersion = 18
let osVersion = ProcessInfo().operatingSystemVersion
guard osVersion.majorVersion == requiredOSVersion else {
fatalError("Switch to iOS \(requiredOSVersion) for these tests.")
}
guard let deviceModel = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] else {
fatalError("Unknown simulator.")
}
guard deviceModel == requirediPhoneSimulator else {
fatalError("Running on \(deviceModel) but we only support \(requirediPhoneSimulator)")
}
}
}
+43
View File
@@ -0,0 +1,43 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import XCTest
@MainActor
class Test: XCTestCase {
var app: XCUIApplication!
func test() async throws {
let client = try UITestsSignalling.Client(mode: .tests)
app = Application.launch(viewID: "SecureBackupLogoutConfirmationScreen_Previews")
await client.waitForApp()
defer { try? client.stop() }
try client.send(.accessibilityAudit(.nextPreview))
forLoop: for await signal in client.signals.values {
switch signal {
case .accessibilityAudit(let auditSignal):
switch auditSignal {
case .nextPreviewReady(let name):
try? app.performAccessibilityAudit { issue in
XCTFail("\(name): \(issue)")
return true
}
try? client.send(.accessibilityAudit(.nextPreview))
case .noMorePreviews:
break forLoop
default:
fatalError("Unhandled signal")
}
default:
fatalError("Unhandled signal")
}
}
app.terminate()
}
}
@@ -0,0 +1,52 @@
{
"configurations" : [
{
"id" : "EFC6A442-D3B7-4273-B349-7A923C06AF5E",
"name" : "Default",
"options" : {
}
}
],
"defaultOptions" : {
"addressSanitizer" : {
"enabled" : true
},
"codeCoverage" : {
"targets" : [
{
"containerPath" : "container:ElementX.xcodeproj",
"identifier" : "C0FAEB81CFD9776CD78CE489",
"name" : "ElementX"
}
]
},
"defaultTestExecutionTimeAllowance" : 120,
"environmentVariableEntries" : [
],
"language" : "en-US",
"locationScenario" : {
"identifier" : "San Francisco, CA, USA",
"referenceType" : "built-in"
},
"region" : "US",
"targetForVariableExpansion" : {
"containerPath" : "container:ElementX.xcodeproj",
"identifier" : "C0C687DE1D270F9895FEE186",
"name" : "AccessibilityTests"
},
"testTimeoutsEnabled" : true,
"undefinedBehaviorSanitizerEnabled" : true
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:ElementX.xcodeproj",
"identifier" : "C0C687DE1D270F9895FEE186",
"name" : "AccessibilityTests"
}
}
],
"version" : 1
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
@@ -0,0 +1,51 @@
name: AccessibilityTests
schemes:
AccessibilityTests:
analyze:
config: Debug
archive:
config: Release
build:
targets:
AccessibilityTests: all
profile:
config: Release
run:
config: Debug
disableMainThreadChecker: false
test:
config: Debug
testPlans:
- path: AccessibilityTests.xctestplan
defaultPlan: true
targets:
AccessibilityTests:
type: bundle.ui-testing
platform: iOS
dependencies:
- target: ElementX
- package: KZFileWatchers
info:
path: ../SupportingFiles/Info.plist
settings:
base:
PRODUCT_NAME: AccessibilityTests
PRODUCT_BUNDLE_IDENTIFIER: ${BASE_BUNDLE_IDENTIFIER}.accessibility.tests
configs:
# This is required to remove the $(inherited) flags
# which would prevent SnapshotTesting to be imported in UI Tests
debug:
OTHER_SWIFT_FLAGS: ["-DDEBUG"]
release:
OTHER_SWIFT_FLAGS: ["-DRELEASE"]
sources:
- path: ../Sources
- path: ../SupportingFiles
- path: ../../ElementX/Sources/UITests/UITestsSignalling.swift