ios - 自定义 UIView 的子视图未出现在 UI 测试中
问题描述
我有UIView
一个UITableView
作为子视图的自定义。我已经为 和 设置了accessibilityLabel 和UIView
accessibilityIdentifier UITableView
。但是,我只能UIView
在我的 UITests 上查询,并且表格视图根本不会出现。我也设置isAccessibilityElement
为true
.
public lazy var tableView: UITableView = {
let tableView = UITableView()
tableView.dataSource = self
tableView.delegate = self
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
return tableView
}()
// MARK: - Initialization
override init(frame: CGRect) {
super.init(frame: .zero)
commonInit()
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
// MARK: - Private Methods
private func commonInit() {
isAccessibilityElement = true
accessibilityLabel = "Filter View"
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Filter View Table"
tableView.accessibilityIdentifier = "Filter View Table"
addSubview(tableView)
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[tableView]-0-|", options: .alignAllLeft, metrics: nil, views: [ "tableView": tableView ]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[tableView]-0-|", options: .alignAllLeft, metrics: nil, views: [ "tableView": tableView ]))
}
我正在访问我的 UITests 中的控件,例如:
let filterView = app.otherElements["Filter View"] // Custom View
XCTAssertTrue(filterView.exists)
let filterTableView = filterView.otherElements["Filter View Table"] // Table View as Custom View's subview
XCTAssertTrue(filterTableView.exists)
解决方案
您是否尝试过使用filterView.tables
而不是filterView.otherElements
?
let filterTableView = filterView.tables["Filter View Table"] // Table View as Custom View's subview
推荐阅读
- javascript - 创建没有元素的 Stripe 令牌
- php - 在执行编辑或删除功能后通过消息重定向到 Laravel 中的主要操作路线的最佳方式
- nativescript - NativeScript index in the list of Repeater items
- sql - 如何在 SQL 中连接具有多个列的两个表
- python - Text Scraping (from EDGAR 10K Amazon) code not working
- r - ggplot:使用cut()时如何在直方图条顶部添加计数
- python - How to loop through a list to a class
- c# - PostSharp 接口方法属性
- python - 关于魔术 8 球程序的问题以及来自 Automate the Boring Stuff with Python 的列表
- google-cloud-dataflow - Beam:使用 DataflowRunner 将事件与 SideInput 一起放入流式管道