Xcode UI 测试 - 多个 UITableView

Xcode UI Testing - Multiple UITableView

如果我们有多个 UITableView,我们如何在 XCUITest 中指定哪一个?

XCUIApplication().tables.cells.count

returns 所有单元格。我们如何选择table来限制计数?

使用可访问性标识符区分您的 table 视图。

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

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

然后您可以在 UI 测试中直接引用 table 之一。

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