【发布时间】:2018-08-17 07:33:31
【问题描述】:
我想通过 UI 测试一个应用工作流程,该工作流程除其他外调用 UIDocumentPickerViewController。我试图在 Xcode 中记录这个工作流,但是当我到达这个控制器时,我收到一条错误消息说
时间戳事件匹配错误:未能找到匹配元素
我有办法传递这样的控制器或模拟它们,在这种情况下,返回一个文件?
【问题讨论】:
我想通过 UI 测试一个应用工作流程,该工作流程除其他外调用 UIDocumentPickerViewController。我试图在 Xcode 中记录这个工作流,但是当我到达这个控制器时,我收到一条错误消息说
时间戳事件匹配错误:未能找到匹配元素
我有办法传递这样的控制器或模拟它们,在这种情况下,返回一个文件?
【问题讨论】:
我遇到了同样的麻烦。我的解决方法:
在您的 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(将 app 替换为您的 XCUIApplication 对象的名称)来查看视图层次结构:
(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["Waterfall Loop Trail, gpx"].tap()
我想我可以使用类似的策略与屏幕上的其他元素进行交互。超级烦人,Xcode 似乎在刻录机中不支持它。
【讨论】:
app.cells.matching(identifier: "your identifier found with po app").element(boundBy: 1).forceTapElement()