Giter Site home page Giter Site logo

jieun-wadiz / accessibilitysnapshot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cashapp/accessibilitysnapshot

0.0 0.0 0.0 35.69 MB

Easy regression testing for iOS accessibility

License: Apache License 2.0

Shell 0.12% Ruby 0.86% C 0.90% Objective-C 8.15% Swift 89.97%

accessibilitysnapshot's Introduction

AccessibilitySnapshot

CI Status Version License Platform

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

Getting Started

By default, AccessibilitySnapshot uses SnapshotTesting to record snapshots and perform comparisons. The framework also includes support for using iOSSnapshotTestCase as the snapshotting engine instead. 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'

Alternatively, if you wish to use iOSSnapshotTestCase to perform image comparisons, you can add a dependency on the iOSSnapshotTestCase subspec instead (or in addition - you can use both in the same project):

pod 'AccessibilitySnapshot/iOSSnapshotTestCase'

Swift Package Manager

Install with Swift Package Manager by adding the following to your Package.swift:

dependencies: [
    .package(name: "AccessibilitySnapshot", url: "https://github.com/cashapp/AccessibilitySnapshot.git", from: "0.4.1"),
]

Next, add AccessibilitySnapshot as a dependency to your test target:

targets: [
    .target(name: "MyApp"),
    .testTarget(name: "MyAppTests", dependencies: ["MyApp", "AccessibilitySnapshot"])
]

To use only the core accessibility parser, add a dependency on the Core library alone:

targets: [
    .target(name: "MyApp"),
    .testTarget(name: "MyAppTests", dependencies: ["MyApp", "AccessibilitySnapshotCore"])
]

To use iOSSnapshotTestCase to perform image comparisons, add a dependency on FBSnapshotTestCase+Accessibility for Swift testing or FBSnapshotTestCase+Accessibility-ObjC for Objective-C.

targets: [
    .target(name: "MyApp"),
    .testTarget(name: "MyAppTests", dependencies: ["MyApp", "FBSnapshotTestCase+Accessibility"])
]

Usage

AccessibilitySnapshot builds on top of existing snapshot frameworks to add support for snapshotting your app's accessibility. By default it uses the SnapshotTesting framework for snapshotting, but can be switched over to iOSSnapshotTestCase as well.

Getting Started with SnapshotTesting

AccessibilitySnapshot provides an .accessibilityImage snapshotting strategy that can be used with SnapshotTesting's snapshot assertions.

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

    assertSnapshot(matching: view, as: .accessibilityImage)
}

Snapshots can also be customized in a few ways, for example controlling when to 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))
}

Getting Started with iOSSnapshotTestCase

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");
}

Requirements

  • Xcode 12.0 or later
  • iOS 13.0 or later

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.

accessibilitysnapshot's People

Contributors

nickentin avatar eliperkins avatar n8chur avatar sherlouk avatar actions-user avatar fbernutz avatar dependabot[bot] avatar jhneves avatar fruitcoder avatar luispadron avatar akaduality avatar ra1028 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.