SwiftMonkey

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)
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容