【问题标题】:Tap on a UITableViewCell's custom button?点击 UITableViewCell 的自定义按钮?
【发布时间】:2016-06-09 20:25:25
【问题描述】:

我正在尝试编写一个涉及点击 UITableViewCell 中的按钮的 UITest。

当我在点击单元格时尝试记录我的点击动作时,XCode 会生成以下行:

[[[[[XCUIApplication alloc] init].tables childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1].otherElements[@"Problems"] tap];

播放时,这会导致与点击单元格本身相同的操作,这不是我想要的。

有没有办法让它专门按下按钮?

【问题讨论】:

    标签: ios objective-c xcode-ui-testing


    【解决方案1】:

    在自定义按钮上设置可访问性标识符。然后就可以在test下直接访问了。

    申请代码:

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.accessoryView = CustomButton()
        cell.accessoryView.accessibilityIdentifier = "New Problem \(indexPath.row)"
    }
    

    测试代码:

    let app = XCUIApplication()
    app.buttons["New Problem 42"].tap()
    

    【讨论】:

    • 我在屏幕上有多个按钮实例。这还能用吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多