如何 UI 测试使用系统提供的控制器的工作流



我想对一个应用程序工作流进行 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似乎在录音机中不支持它,这非常烦人。

最新更新