Is there a way to select or trigger didSelect from a UITest on the first cell if it exists in a collection view?
When recording it uses static text from the selected cell. If the cell is populated from the network with dynamic content and with the collection view to possibly contain no cells, this test will break.
You can select the first cell in a collection view with:
let app = XCUIApplication()
app.launch()
let firstChild = app.collectionViews.childrenMatchingType(.Any).elementBoundByIndex(0)
if firstChild.exists {
firstChild.tap()
}
Swift 3
let firstChild = app.collectionViews.children(matching:.any).element(boundBy: 0)
if firstChild.exists {
firstChild.tap()
}
On a more theoretical note, your test suite should use deterministic data. You should always know exactly how many cells, and what they contain, will be returned from the service. You can accomplish this by using a seeded development server or mocking out network requests when running your test suite.
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