cashapp / AccessibilitySnapshot

Easy regression testing for iOS accessibility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Started

LostStudent opened this issue · comments

Hey Id love to give this a try but im having trouble using the accessibilityImage .

when I use SnapshotTesting's assert:

 func testExample() throws {
        assertSnapshot(of: ContentView(), as: .image)
}

that takes a snapshot.

But when I try to use the accessibilityImage strategy :

func testExample() throws {
        assertSnapshot(of: ContentView(), as: .accessibilityImage)
        
    }

I get compile error:
"Type of expression is ambiguous without a type annotation"
is this trying to use SnapshotTesting's assert rather than AccessibilitySnapshot's?

Hey @LostStudent, that error means the compiler can't resolve the method signature. The assertSnapshot method is defined by SnapshotTesting, while the accessibilityImage strategy is defined by AccessibilitySnapshot.

  1. How are you installing the frameworks? (What package manager, and what configuration options within that package manager)
  2. Are you importing both frameworks in this test class file? What is the import statement for AccessibilitySnapshot?

ah adding a hosting controller works.

func testExample() throws {
        
        let host = UIHostingController(rootView: ContentView())
        host.view.frame = .init(x: 0, y: 0, width: 100, height: 100)
        assertSnapshot(
            matching: host,
            as: .accessibilityImage(showActivationPoints: .always,
                                    drawHierarchyInKeyWindow: true),
            named: "shot"
        )
        
    }

should the previous usage have worked?
My test project imports AccessibilitySnapshot using swift package manager in xcode.
AccessibilitySnapshot is added as a dependency of the test target
the imports in my test file are:

import XCTest
import SnapshotTesting
@testable import accessSnaps
import SwiftUI
import AccessibilitySnapshot

Ahh, that's expected. Try updating to version 0.7. Prior versions didn't support snapshotting SwiftUI views directly, requiring a hosting controller instead.