beasone
beasone

Reputation: 1085

swift in UI test(test the num of cells in UITable View)

I am very new to UI test. I have an UITableView in my storyboard and it contains some cells. Update: I want to assert that the num of cells in UITableView when the app launches will be more than 0. But I don't know how to code this part.Using NSPredicate? Or others?

 func testCellsNum()
{
        let app = XCUIApplication()
        let tableCell = app.tableRows.count
    //Then what should I do ?
        XCTAssertGreaterThan(tableCell, 0, "should greater than 0")//this line doesn't work


}

Upvotes: 4

Views: 4626

Answers (1)

Leo
Leo

Reputation: 24714

If you only have one table:

func testExample() {
    let app = XCUIApplication()
    let tablesQuery = app.tables
    let count = tablesQuery.cells.count
    XCTAssert(count > 0)
}

If you have multi tables,using this to get first or any index you want

 tablesQuery.elementAtIndex(0).cells

Upvotes: 17

Related Questions