UI测试框架
SwiftMonkey
主体,依赖于 XCUITest, 调用了一些私有方法去发起操作事件
SwiftMonkeyPaws
负责呈现操作事件的视觉效果, 运行时的手掌就是 SwiftMonkeyPaws 制造出来的, 需要直接接入到 app 里面
使用
#if DEBUG
if CommandLine.arguments.contains("--MonkeyPaws") {
paws = MonkeyPaws(view:window!)
}
#endif
Appdelegate 中初始化 SwiftMonkeyPaws,添加视觉效果
CommandLine.argments.contains(“—MonkeyPaws”) 区分开 app 是否跑在测试模式下
在UITests 中初始化
let app = XCUIApplication()
app.launchArguments.append("--MonkeyPaws")
app.launch()
添加用例
func testMonkey() {
let application = XCUIApplication()
// Workaround for bug in Xcode 7.3. Snapshots are not properly updated
// when you initially call app.frame, resulting in a zero-sized rect.
// Doing a random query seems to update everything properly.
// TODO: Remove this when the Xcode bug is fixed!
_ = application.descendants(matching: .any).element(boundBy: 0).frame
let monkey = Monkey(frame: application.frame)
monkey.addXCTestTapAction(weight: 25)
monkey.addXCTestDragAction(weight: 200)
monkey.addXCTestTapAction(weight: 100)
monkey.addXCTestDragAction(weight: 30)
monkey.monkeyAround(iterations: 360000)
}