UI測試框架
SwiftMonkey
主體,依賴于 XCUITest, 調(diào)用了一些私有方法去發(fā)起操作事件
SwiftMonkeyPaws
負(fù)責(zé)呈現(xiàn)操作事件的視覺效果, 運(yùn)行時(shí)的手掌就是 SwiftMonkeyPaws 制造出來的, 需要直接接入到 app 里面
使用
#if DEBUG
if CommandLine.arguments.contains("--MonkeyPaws") {
paws = MonkeyPaws(view:window!)
}
#endif
Appdelegate 中初始化 SwiftMonkeyPaws捐顷,添加視覺效果
CommandLine.argments.contains(“—MonkeyPaws”) 區(qū)分開 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)
}