我正在尝试添加用于刷新控制的uitest,但由于无法使用可访问性标识符(refreshControl.accessibilityIdentifier = "refreshControlList")访问刷新控制,所以我无法这样做。
launchAppWithArgs(json: OrdersResultJSON.ok, xcuiApp: app)
let table = app.tables["agendaTable"]
DispatchQueue.main.async {
table.otherElements["sectionHeader0"].press(forDuration: 2, thenDragTo: table.otherElements["sectionHeader2"])
}
if !table.otherElements[""].waitForExistence(timeout: 6) {
print("XXX")
}有什么建议来测试吗?
发布于 2018-07-17 14:02:59
要执行“拉”以刷新,只需获取第一个单元格并将其向下拖动:
let firstCell = app.tables["agendaTable"].cells.firstMatch
let start = firstCell.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0))
let finish = firstCell.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 10))
start.press(forDuration: 0, thenDragTo: finish)希望这能有所帮助!
发布于 2019-07-26 13:55:47
您可以获取UIRefreshControl的标题标签并在其上添加一个标识符,如下所示:
func setSubviewAccessibility(for tableView: UITableView) {
guard let titleLabel = tableView.refreshControl?.subviews.first?.subviews.last as? UILabel else {
return
}
titleLabel.isAccessibilityElement = true
titleLabel.accessibilityIdentifier = "refresh_control_label"
}调用此方法,传递已为其设置UIRefreshControl的表视图,您应该做得很好。
然后,在试验方面:
let refreshControl = XCUIApplication().staticTexts["refresh_control_label"]
guard refreshControl.waitForExistence(timeout: 5) else {
return XCTFail("Refresh control label not found.")
}剩下的唯一问题是,您可能需要加载列表才能花费更长的时间,这样您的测试就不会错过UIRefreshControl。使用waitForExistence总是很好的。
https://stackoverflow.com/questions/51262158
复制相似问题