Skip to content

mdeora/AccessibilitySnapshot

 
 

Repository files navigation

AccessibilitySnapshot

CI Status Version License Platform

AccessibilitySnapshots makes it simple to add regression tests for accessibility in UIKit.

Getting Started

By default, AccessibilitySnapshot uses iOSSnapshotTestCase to record snapshots and perform 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. See the Extensions section below for a list of other available snapshotting options.

CocoaPods

Install with CocoaPods by adding the following to your Podfile:

pod 'AccessibilitySnapshot'

To use only the core accessibility parser, add a dependency on the Core subspec alone.

pod 'AccessibilitySnapshot/Core'

Usage

To run a snapshot test, simply call the SnapshotVerifyAccessibility method:

func testAccessibility() {
    let view = MyView()
    // Configure the view...

    SnapshotVerifyAccessibility(view)
}

Since AccessibilitySnapshot is built on top of iOSSnapshotTestCase, it uses the same mechanism to record snapshots (setting the self.recordMode property) and supports many of the same features like device agnostic file names and specifying identifiers for each snapshot:

func testAccessibility() {
    let view = MyView()
    // Configure the view...

    SnapshotVerifyAccessibility(view, identifier: "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.
    SnapshotVerifyAccessibility(view, showActivationPoints: .always)

    // Don't show any indicators.
    SnapshotVerifyAccessibility(view, showActivationPoints: .never)
}

You can also run accessibility snapshot tests from Objective-C:

- (void)testAccessibility;
{
    UIView *view = [UIView new];
    // Configure the view...

    SnapshotVerifyAccessibility(view, @"identifier");
}

Contributing

We love our contributors! Please read our contributing guidelines prior to submitting a pull request.

Extensions

Have you written your own extension? Add it here and submit a pull request!

License

Copyright 2020 Square Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Easy regression testing for iOS accessibility

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 91.0%
  • Objective-C 7.0%
  • Ruby 1.8%
  • Other 0.2%