简体   繁体   English

Xcode UI测试-多个UITableView

[英]Xcode UI Testing - Multiple UITableView

If we have multiple UITableViews, how do we specify which one in our XCUITests? 如果我们有多个UITableView,我们如何在XCUITests中指定哪个?

XCUIApplication().tables.cells.count

returns all the cells. 返回所有单元格。 How can we choose which table to limit the count? 我们如何选择哪个表来限制计数?

Differentiate your table views with an accessibility identifier. 用可访问性标识符区分表视图。

class ViewController: UIViewController {
    let firstTableView: UITableView!
    let secondTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        firstTableView.accessibilityIdentifier = "First Table"
        secondTableView.accessibilityIdentifier = "Second Table"
    }
}

Then you can reference one of the tables directly in your UI tests. 然后,您可以直接在UI测试中引用其中一个表。

XCUIApplication().tables["First Table"].cells.count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM