⚠️ Moved to cashapp/AccessibilitySnapshot ⚠️
This repository is no longer maintained as the code has been merged into the official AccessibilitySnapshot snapshot and is being regularly maintained by the core team (and myself). We recommend you update all references to the new version.
Accessibility snapshots makes it simple to add regreession tests for accessibility in UIKit.
This library is an extension to AccessibilitySnapshot by CashApp and adds support for Pointfree's SnapshotTesting library which reports and performs comparisons.
Before setting up accessibility snapshot tests, make sure your project is set up for standard snapshot testing. Accessibility snapshot tests require that the test target has a host application.
Install with CocoaPods by adding the following to your Podfile
:
pod 'AccessibilitySnapshot+SnapshotTesting'
To run a snapshot test, simply call the assertSnapshot
method with the accessibilityImage
type:
func testAccessibility() {
let view = MyView()
// Configure the view...
assertSnapshot(matching: view, as: .accessibilityImage)
}
Since AccessibilitySnapshotPointfree is built on top of Pointfree's SnapshotTesting, it uses the same mechanism to record snapshots (setting the self.record
property) and supports many of the same features like specifying identifiers for each snapshot:
func testAccessibility() {
let view = MyView()
// Configure the view...
assertSnapshot(matching: view, as: .accessibilityImage, named: "identifier")
}
Snapshots can also optionally include indicators for the accessibility activation point of each element. By default, these indicators are shown when the activation point is different than the default activation point for that view. You can override this behavior for each snapshot:
func testAccessibility() {
let view = MyView()
// Configure the view...
// Show indicators for every element.
assertSnapshot(matching: view, as: .accessibilityImage(showActivationPoints: .always))
// Don't show any indicators.
assertSnapshot(matching: view, as: .accessibilityImage(showActivationPoints: .never))
}
Synced with CashApp's AccessibilitySnapshot version 0.3.1