本文介绍了Xcode UI 测试:UITableViewCell 上的辅助功能查询失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Xcode UI 测试,我无法查询 UITableView 中的单元格
Using Xcode UI test, I can not query the cells in a UITableView
UITableView 包含 3 个单元格:
The UITableView contains 3 cells :
import UIKit
@objc class DumpTable: UITableViewController {
var objects: [NSDate] = [NSDate]()
override func viewDidLoad() {
super.viewDidLoad()
objects.append(NSDate())
objects.append(NSDate())
objects.append(NSDate())
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objects.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let object = objects[indexPath.row]
cell.textLabel!.text = object.description
cell.isAccessibilityElement = true
cell.accessibilityLabel = "Thecell"
cell.accessibilityIdentifier = "Thecell"
return cell
}
}
测试
测试非常简单.
给定一个包含 3 个单元格的 UITableView,我试图断言有任何可用的单元格:
Given a UITableView with 3 cells, I'm trying to assert there are any cells available :
XCTAssertTrue(XCUIApplication().tables["Thetable"].exists)
XCTAssertTrue(XCUIApplication().tables["Thetable"].cells.count > 0)
然后它会在 2 个断言上失败:
It will then fail on the 2 assertions :
Assertion Failure: XCTAssertTrue failed -
/Users/damiengavard/Desktop/Table/TableUITests/TableUITests.swift:33: error: -[TableUITests.TableUITests testExample] : XCTAssertTrue failed -
如何复制
https://github.com/dagio/TableCellAccessibility
只需执行 Cmd+U
推荐答案
我在这里找到了答案.为了使 UITableViewCell
可访问,包含的 UITableView
本身不能访问.
I found the answer here. In order to make the UITableViewCell
accessible, the containing UITableView
cannot be accessible itself.
所以,你只需要删除这些行:
So, you just need to remove these lines:
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
这篇关于Xcode UI 测试:UITableViewCell 上的辅助功能查询失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!