Select the first cell in the collection view from UITest

Is there a way to select or call didSelect from a UITest in the first cell if it exists as a collection?

When recording, it uses static text from the selected cell. If a cell is filled with dynamic content from the network and with a collection view that may not contain cells, this test will fail.

+4
source share
1 answer

You can select the first cell as a collection 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()
}

. , , . , .

+18

Source: https://habr.com/ru/post/1622122/


All Articles