Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I verify existence of text inside a table view row given its index in an XCTest UI Test?

I am using XCTest UI Test framework to check rows in a table view. In my test I need to verify the existence of text in a table view row given its index.

I was thinking of using tableRows.elementBoundByIndex method, but it did not return anything. The number of rows returned by calling tableRows.count is zero. The table is present and filled because I can query the text inside the rows successfully:

XCTAssertEqual(app.tables.staticTexts["Cute Alpaca"].exists)

How can I verify existence of a text in a row given its index in an XCTest UI test?

like image 909
Evgenii Avatar asked Sep 03 '15 00:09

Evgenii


2 Answers

It turns out that tableRows doesn't actually detect rows in the UITableView. Use cells instead.

I have a feeling that tableRows and tableColumns are used to do testing on Mac OS X where you have actual tables while on iOS we have UITableViewCell and UICollectionViewCell. Or this could be a bug as we are still in the beta period.

let table = app.tables.element
XCTAssertTrue(table.exists)

let cell = table.cells.elementBoundByIndex(2)
XCTAssertTrue(cell.exists)
let indexedText = cell.staticTexts.element
XCTAssertTrue(indexedText.exists)

or the one liner

XCTAssertTrue(app.tables.element.cells.elementBoundByIndex(2).exists)
like image 75
Kevin Avatar answered Oct 20 '22 18:10

Kevin


For your case, I think this code will help you.

let tableCellContainer = app.tables["HomeTableView"].cells.element(boundBy: 1) // Get the first Cell
let cell = tableCellContainer.staticTexts["Brazil"]
XCTAssert(cell.exists)

Regards,

like image 42
Canh Tran Avatar answered Oct 20 '22 17:10

Canh Tran