Select 来自 UITest 的集合视图中的第一个单元格
Select first cell in collection view from UITest
如果第一个单元格存在于集合视图中,是否有办法select或从第一个单元格上的 UITest 触发 didSelect?
录制时,它使用 selected 单元格中的静态文本。如果单元格是从具有动态内容的网络填充的,并且集合视图可能不包含单元格,则此测试将中断。
您可以 select 集合视图中的第一个单元格:
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()
}
从理论上讲,您的测试套件应该使用确定性数据。您应该始终确切地知道服务将返回多少个单元格以及它们包含什么。您可以通过使用种子开发服务器或在 运行 您的测试套件时模拟网络请求来完成此操作。
如果第一个单元格存在于集合视图中,是否有办法select或从第一个单元格上的 UITest 触发 didSelect?
录制时,它使用 selected 单元格中的静态文本。如果单元格是从具有动态内容的网络填充的,并且集合视图可能不包含单元格,则此测试将中断。
您可以 select 集合视图中的第一个单元格:
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()
}
从理论上讲,您的测试套件应该使用确定性数据。您应该始终确切地知道服务将返回多少个单元格以及它们包含什么。您可以通过使用种子开发服务器或在 运行 您的测试套件时模拟网络请求来完成此操作。