SwiftMonkey

作者: PIANG要做TimeTrav | 来源:发表于2017-03-27 11:24 被阅读608次

swiftMonkey git地址

UI测试框架

Paste_Image.png
SwiftMonkey

主体,依赖于 XCUITest, 调用了一些私有方法去发起操作事件

SwiftMonkeyPaws

负责呈现操作事件的视觉效果, 运行时的手掌就是 SwiftMonkeyPaws 制造出来的, 需要直接接入到 app 里面

Paste_Image.png

使用

    #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)
}

相关文章

网友评论

  • JBright_Lee:如果跑monkey之后如何把对应的crash日志给导出来呢?或者说发生crash之后能够再次运行,类似于crashMonkey4iOS那种可以有对应的crashlog记录呢?
    AlanFIGHTTUNG:楼主是否找到了目前更好的ios monkey,CrashMonkey4IOS 不支持iOS10以上,也很久没更新了,这个SwiftMonkey似乎必须源码刷进入设备测试

本文标题:SwiftMonkey

本文链接:https://www.haomeiwen.com/subject/qrnlottx.html