我想要 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/