ios - 如何通过 Xcode 中 UITests 下的标识符访问详细信息披露按钮?

标签 ios xcode swift uitableview xcode-ui-testing

let app = XCUIApplication()
let studentsTable = app.tables["studentsTable"]
let detailButton = studentsTable.buttons["More Info, TestName, TestUserName, 2"]

它有效,但我很确定,还有更优雅的方法。

enter image description here

最佳答案

您可以通过设置可访问性标识符直接访问该按钮。在您的表格示例中,您可以在表格 View 的数据源中这样做。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(Cell.Identifier, forIndexPath: indexPath)
    cell.accessoryView = UIButton() // your custom button
    cell.accessoryView?.accessibilityIdentifier = "Cell \(indexPath.row + 1) Button"
    return cell
}

然后您可以在 UI 测试中单独点击每个按钮。

let app = XCUIApplication()
let firstAccessoryButton = app.buttons["Cell 1 Button"]
firstAccessoryButton.tap()

关于ios - 如何通过 Xcode 中 UITests 下的标识符访问详细信息披露按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37875479/

相关文章:

ios - 填写所有 UITextField 后,UIButton 未启用

ios - Xcode 4.2 (Snow Leopard) 生成警告 "Missing File"

ios - 当应用程序在没有 Xcode 的情况下运行时,IB 中的 GLKView 会导致崩溃

ios - 从 NIB 加载 View ,IBOutletCollection 为 nil,即使其他 IBOutlet 工作正常

SwiftUI:检测到约束模糊地建议 TableView 单元格的内容 View 的高度为零的情况

ios - Interface Builder 中的原型(prototype) ≠ UITableView 标题单元格的运行时结果

ios - iOS5.1 中的位置服务无法正常工作

ios - 如何使用 objective-c 在应用程序中包含文件轮换

ios - Oauth1 iOS 从 API 获取数据

ios - 冗余约束 'Self' : 'AnyObject'