I'm using the KIF test framework. Currently, I'm able to detect that a table is not empty by the following line:
tester().waitForCellAtIndexPath(NSIndexPath(forRow: 0, inSection: 0),
inTableViewWithAccessibilityIdentifier: "My Table")
However, I need to be able to test if a table is completely empty. What is the best way to accomplish this using KIF?
Figured it out. You can grab the table and then perform any action you want against it:
//Helper function
extension KIFUITestActor {
func waitForViewWithAccessibilityIdentifier(accessibilityIdentifier: String) -> UIView? {
var view: UIView?
self.waitForAccessibilityElement(nil, view: &view, withIdentifier: accessibilityIdentifier, tappable: false)
return view
}
}
if let myTable = tester().waitForViewWithAccessibilityIdentifier("My Table") as? UITableView {
XCTAssertNil(myTable.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 1)), "My Table should have been empty.")
}
Since table views can have N number of sections that serve different purposes, it doesn't make much sense for KIF to try to provide a test helper to check for an "empty table".
Edit: I added the helper function definition that was missing from this answer