Ios 异步加载时,如何使用XUITest验证UITableView中的单元格数?
我正在编写一个UI测试,它需要异步加载数据,然后对单元格中显示的数据进行验证 在这种情况下,如果没有数据加载,测试将通过,并且不应该通过,因此我需要确保至少有一个单元已基于远程数据加载Ios 异步加载时,如何使用XUITest验证UITableView中的单元格数?,ios,swift,uitableview,xcuitest,Ios,Swift,Uitableview,Xcuitest,我正在编写一个UI测试,它需要异步加载数据,然后对单元格中显示的数据进行验证 在这种情况下,如果没有数据加载,测试将通过,并且不应该通过,因此我需要确保至少有一个单元已基于远程数据加载 func testTableViewCellDoesNotContainItem() { ...setup.... // Load data app.keyboards.buttons["Search"].tap() XCTAssert(app.tables["TableView"].cell
func testTableViewCellDoesNotContainItem() {
...setup....
// Load data
app.keyboards.buttons["Search"].tap()
XCTAssert(app.tables["TableView"].cells.count > 0)
...other check...
}
能够通过以下方式达到预期效果:
func testTableViewCellDoesNotContainItem() {
...setup....
// Prep expectation for async load ensuring that we have at least one cell and the service call worked
let loaded = NSPredicate(format: "count > 0")
expectation(for: loaded, evaluatedWith: app.tables["TableView"].cells, handler: nil)
// Load data
app.keyboards.buttons["Search"].tap()
waitForExpectations(timeout: 5, handler: nil)
...other check...
}