Reputation: 10108
I want to use Xcode's UI Testing to count the number of sections in a tableview and the number of cells in each section. How can I do that?
Upvotes: 3
Views: 4522
Reputation: 726
Joe Masilotti is entirely correct in that application code cannot be accessed directly from the UI Test, though you can backchannel if you want to be out-of-style. Let's assume you don't.
Xcode's UI Testing framework has access to all of the Swift language along with the UI hierarchy of your app, but not access to the data layer; so you can do the following:
Upvotes: 2
Reputation: 31486
As of Xcode 7, table view headers show as Other
elements.
Here's what I did for a (grouped) table view in my app:
extension TableLayoutTests {
func testHasMessagesGroup() {
XCTAssert(app.tables.otherElements["MESSAGES"].exists)
}
func testHasMessageCell() {
let header = app.tables.otherElements["MESSAGES"]
let cell = app.tables.cells.elementBoundByIndex(1)
XCTAssertGreaterThanOrEqual(cell.accessibilityFrame.minY, header.accessibilityFrame.maxY)
}
func testHasOtherMessageCell() {
let header = app.tables.otherElements["MESSAGES"]
let cell = app.tables.cells.elementBoundByIndex(2)
XCTAssertGreaterThanOrEqual(cell.accessibilityFrame.minY, header.accessibilityFrame.maxY)
}
}
Upvotes: 4