Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

uitest

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


}
like image 537
beasone Avatar asked Dec 05 '22 19:12

beasone


1 Answers

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
like image 179
Leo Avatar answered Dec 27 '22 14:12

Leo