gpt4 book ai didi

ios - 异步加载时如何使用 XCUITest 验证 UITableView 中的单元格数量?

转载 作者:行者123 更新时间:2023-11-28 15:16:47 25 4
gpt4 key购买 nike

我正在编写一个 UI 测试,它需要异步加载数据,然后对单元格中显示的数据进行一些验证。

在这种情况下,如果没有数据加载,则测试通过但不应该通过,所以我需要确保至少有一个单元格已根据远程数据加载。

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...
}

关于ios - 异步加载时如何使用 XCUITest 验证 UITableView 中的单元格数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46713584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com