How can I check for text inside a table view row, given its index in the XCTest UI test?

I am using the XCTest UI Test framework to check rows in a table. In my test, I need to check for the presence of text in the row of the table view, taking into account its index.

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

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

How to check for text in a string based on its index in the XCTest UI test?

+5
source share
2 answers

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

I have the feeling that tableRows and tableColumns are used for testing on Mac OS X, where you have actual tables, and on iOS UITableViewCell and UICollectionViewCell . Or this may be a mistake, 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 one liner

 XCTAssertTrue(app.tables.element.cells.elementBoundByIndex(2).exists) 
+13
source

In 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) 

Hi,

0
source

All Articles