Accessible 是一个工具,它可以让您在 iOS 上的 UITesting 体验更好。
CI | 状态 |
---|---|
主分支 | |
开发分支 |
Accessible 解析您的 .storyboard
文件,并为每个 IBOutlet
连接生成 accessibilityIdentifier。
enum Accessible {
struct Storyboard {
struct Screen {
static let rootView = "Accessible.Storyboard.Screen.rootView"
struct UIElementTpye {
static let aView = "Accessible.Storyboard.Screen.UIElementTpye.aView"
}
...
}
...
}
...
}
UITestableExtensions.swift 使为每个 UIElement 设置先前生成的 id 变得容易。如果您提供 UITestableExtensions.swift 路径,那么 Accessible 也会生成如下所示的 Swift 文件。
protocol UITestable {
func setAccessibilityIdentifiers()
}
extension ScreenViewController: UITestable {
func setAccessibilityIdentifiers() {
view.accessibilityIdentifier = Accessible.Storyboard.Screen.rootView
aView.accessibilityIdentifier = Accessible.Storyboard.Screen.UIElementTpye.aView
...
}
}
...
您应该在 UIViewController 实例的 viewDidLoad()
方法中调用 setAccessibilityIdentifiers()
。
UITapMans.swift 使编写 XCTestCase 文件比以前更有趣。
class ScreenUITests: XCTestCase {
var tapMan: ScreenTapMan!
override func setUp() {
super.setUp()
continueAfterFailure = false
tapMan = OnboardingTapMan().start()
}
func testCaseA() {
tapMan
.aView.isHittable()
.aView.tap()
}
}
下载最新的已发布的二进制文件。
使用 chmod +x accessible
使其可执行。(如果您有 .dms 扩展名,请先删除它)
将其复制到 /usr/local/bin/
。
在您的项目根目录(项目文件旁边)中创建一个 .accessible.yml
配置文件。
#enumName: Accessible
inputs:
- Path/To/Storyboards
- Path/To/OtherStoryboards
- Path/To/One/SpecificStoryboard.storyboard
outputs:
identifiersPath: Directory/Of/Generated/Files
#testableExtensionsPath: Directory/Of/Generated/Files
#tapMansPath: Directory/Of/Generated/Files
如果您想提供 Accessibiliy Identifiers 枚举的名称,请取消注释 enumName
。
如果您希望 Accessible 为您生成 UITestableExtensions.swift 文件,请取消注释 testableExtensionsPath
。
如果您希望 Accessible 为您生成 UITapMans.swift 文件,请取消注释 tapMansPath
。
accessible
,或在您的 Xcode 项目文件中设置一个新的运行脚本构建阶段。