0

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?

4

1 回答 1

1

弄清楚了。您可以抓住桌子,然后对它执行任何您想要的操作:

//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.")
}

由于表视图可以有 N 个用于不同目的的部分,因此 KIF 尝试提供测试助手来检查“空表”没有多大意义。

编辑:我添加了此答案中缺少的辅助函数定义

于 2015-04-03T16:37:51.433 回答