xcode - 如何对使用系统提供的 Controller 的工作流程进行 UI 测试

标签 xcode xcode-ui-testing

我想要 UI 测试一个应用程序工作流程,除了其他之外,还调用 UIDocumentPickerViewController。我尝试在 Xcode 中记录此工作流程,但是当我到达此 Controller 时,我收到一条错误消息:

Timestamped Event Matching Error: Failed to find matching element

我有办法传递这样的 Controller 或模拟它们,在这种情况下,返回一个文件?

最佳答案

我也遇到了同样的麻烦。我的解决方法:

在 UI 测试中放置一个断点,当文件选择器位于前台时将触发该断点。

示例测试:

    func testBlah() {
        let app = XCUIApplication()
        // The next 2 lines interact with my app to cause it to pop up the file picker.
        // These will be different for your app :)
        app.navigationBars["Dashboard"].buttons["download"].tap()
        app.staticTexts["Browse"].tap()
        sleep(3) // Can place breakpoint here for example
    }

到达断点后,通过输入 po app 查看 View 的层次结构(将 app 替换为您的 XCUIApplication 的名称)对象)进入调试器的右 Pane :

(lldb) po app
    t =   193.67s Snapshot accessibility hierarchy for app with pid 941
    t =   194.22s Snapshot accessibility hierarchy for app with pid 941
Attributes: Application, pid: 941, label: 'Redacted'
Element subtree:
 →Application, 0x2814fdea0, pid: 941, label: 'Redacted'
    Window (Main), 0x2814fe4c0, {{0.0, 0.0}, {375.0, 667.0}}
      Other, 0x2814fe3e0, {{0.0, 0.0}, {375.0, 667.0}}

Cell, 0x2814f42a0, {{257.0, 131.0}, {90.0, 175.0}}, identifier: 'Waterfall Loop Trail, xml', label: 'Waterfall Loop Trail, xml, 9/16/19, 42 KB'
Cell, 0x2814f4380, {{28.0, 321.0}, {90.0, 175.0}}, identifier: 'Waterfall Loop Trail, gpx', label: 'Waterfall Loop Trail, gpx, 9/16/19, 42 KB'

由于我尝试点击Waterfall Loop Trail, gpx,我现在可以执行以下操作: app.cells["瀑布环路,gpx"].tap()

我想我可以使用类似的策略与此屏幕上的其他元素进行交互。非常烦人的是 Xcode 似乎不支持记录器。

关于xcode - 如何对使用系统提供的 Controller 的工作流程进行 UI 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51890448/

相关文章:

ios - 将 NSStrings 的 NSMutableArray 保存到磁盘

ios - 如何确保调试版本和应用商店版本相同?

objective-c - 未知类型名称 'ESTBeaconRegion' ;您的意思是 'CLBeaconRegion' 吗?

ios - 我在 SwiftUI 中创建了一个自定义选项卡栏,但是当我选择一个选项卡时,它会完全重新加载 View 。我该如何防止这种情况

ios - UICollectionViewDelegate 中的 Swift 3 警告

ios - clang : error: linker command failed with exit code 1 (use -v to see invocation); "__TMaC15PasswordManager14ViewController", 引用自:

ios - UITesting的iOS模拟器位置

ios - UITesting -> NavigationItem 的 titleView 中的 UISearchBar 返回 XCUIElement.Type other

ios - 通过 Cocoapods 包含 Xcode 7 UI 测试依赖项?

swift - 是否可以从 ui 测试中隐藏类