Jason Hocker
Jason Hocker

Reputation: 7067

Xcode UI Testing - Multiple UITableView

If we have multiple UITableViews, how do we specify which one in our XCUITests?

XCUIApplication().tables.cells.count

returns all the cells. How can we choose which table to limit the count?

Upvotes: 2

Views: 424

Answers (1)

Joe Masilotti
Joe Masilotti

Reputation: 17008

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.

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

Upvotes: 3

Related Questions