提问人:Shawn Frank 提问时间:11/9/2023 更新时间:11/9/2023 访问量:23
iOS UITest 在本地通过,但在 Bitrise 上失败
iOS UITest passes locally but fails on Bitrise
问:
我有一个据说很简单的 UITest 我想写。
我有一个集合视图,我想滚动到集合视图的末尾。
在此过程中,我想计算作为广告单元格的特定元素/单元格。
在本地(在 XCode 和 Fastlane 上),此测试通过,但是,在 Bitrise 上,此测试失败。
当我查看 Bitrise 上测试结束位置的快照时,我注意到由于 Bitrise 上的某种原因,测试过早结束并且没有滚动到集合视图的末尾,这可能是它没有按预期计算 2 个广告的原因。
这是 Bitrise 上的失败消息:XCTAssertEqual failed: ("1") is not equal to ("2") - Expected 2 adverts, but found 1.
这是我测试的代码
func testAdverts() {
var previousMaxIndexPath: IndexPath = IndexPath(row: 0, section: 0)
var advertIdentifiers = Set<String>()
var noNewIndexSwipeCount = 0
while true {
app.swipeUp()
if let currentMax = currentMaxIndexPath, currentMax > previousMaxIndexPath {
previousMaxIndexPath = currentMax
advertIdentifiers.formUnion(visibleAdvertIdentifiers)
noNewIndexSwipeCount = 0
} else if noNewIndexSwipeCount >= 2 {
break
} else {
noNewIndexSwipeCount += 1
}
}
XCTAssertEqual(advertIdentifiers.count, 2, "Expected 2 adverts, but found \(advertIdentifiers.count).")
}
下面是在测试中调用的其他一些函数,以获取更多上下文。
var visibleCellIdentifiers: [String] {
return elementQuery(type: .cell).allElementsBoundByIndex.map { $0.identifier }
}
var currentMaxIndexPath: IndexPath? {
return visibleCellIdentifiers.compactMap { extractIndexPath(from: $0) }.max()
}
var visibleAdvertIdentifiers: [String] {
return visibleCellIdentifiers.filter { $0.contains("AdvertStoryTileCollectionViewCell") }
}
func extractIndexPath(from identifier: String) -> IndexPath? {
guard let range = identifier.range(of: "indexPath_\\d+_\\d+", options: .regularExpression) else {
return nil
}
let matchedSubstring = identifier[range]
let components = matchedSubstring.split(separator: "_")
guard let section = Int(components[1]), let row = Int(components[2]) else {
return nil
}
return IndexPath(row: row, section: section)
}
正如我之前提到的,测试似乎在 XCode 和 FastLane 上本地通过。
我还尝试了其他方法滚动到集合视图的末尾,例如这种方法,但这对我不起作用,因为我有重复的单元格。
答: 暂无答案
评论