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?
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)
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,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With