用于在 UIKit 中测试您的 VoiceOver 支持的快照策略,使用 PointFree 的 SnapshotTesting 库。
此策略使用视图层级的文本表示,仅关注与 VoiceOver 相关的信息。(相关工作:AccessibilitySnapshot 是一种用于类似用例的可视化快照测试工具。)
import SnapshotTesting
import AccessibilityTextSnapshot
assertSnapshot( // SnapshotTesting gives you this...
matching: someView,
as: .recursiveA11yDescription) // ... but AccessibilityTextSnapshot gives you this
这会生成所有与 voiceover 相关信息的递归(文本)描述,适用于快照测试。
该字符串显示
|
为前缀,为了强调它们不参与 VoiceOver它不显示 UIImageView,我们也许应该在某个时候重新考虑这一点。
示例
* UIView // non-a11y view but has a11y-relevant descendant
* UIScrollView // (same)
* UIView // (same)
* UIStackView // ...
* MDViewLayer.ElementView
* UIStackView
* MDViewModels.Label // | hanging from this view means it has a11y-relevant stuff
| -label: Relaxation exercises // a11y property
| -traits: .staticText // a11y property
* UIStackView
* MDViewLayer.MultilineButton
| -label: Yes
| -hint: Unselected option
| -traits: .button
* MDViewLayer.MultilineButton
| -label: No
| -hint: Unselected option
| -traits: .button
* MDViewLayer.ConversationListItemView // hanging | means a11y-relevant view
| -label: Only you. No messages yet // a11y property
| -hint: Open conversation // a11y property
| * UIStackView // subviews that would be a11y-relevant
| * UIStackView // BUT are not read by VoiceOver because
| * UIStackView // the parent view overrides, note leading |
| * MDViewModels.Label
| | -label: Only you
| * UIStackView
| * MDViewModels.Label
| | -label: No messages yet.
| * MDViewLayer.Button
| * UIView
| * MDViewModels.Label
| | -label: Ongoing video call
o MDViewLayer.StepValidationView // o means isHidden=true (on self or a parent)
o -label: Please correct the errors above. Actions available
o -action: Go to first error // We still show it because we want to
o * MDViewLayer.MultilineButton // be reminded that there *could* be something!
o | -label: Please correct the errors above
target 'MyAppTests' do
pod 'AccessibilityTextSnapshot'
end