OGeek|极客世界-中国程序员成长平台

标题: ios - Xcode UI 测试 Collection View 单元格在 iOS 11 上变得不可点击 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 13:53
标题: ios - Xcode UI 测试 Collection View 单元格在 iOS 11 上变得不可点击

我们在 Xcode UI 测试中使用这段代码来模拟点击 UICollectionView 的第一个单元格:

XCUIElementQuery *query = [application descendantsMatchingType:XCUIElementTypeAny];
XCUIElement *collectionView = [query objectForKeyedSubscript:collectionViewAccessibilityIdentifier];
XCUIElement *targetCell = [lensesCollectionView.cells elementBoundByIndex:cellIndex];
if (targetCell.hittable) {
    [targetCell tap];
}

这在 iOS 10 上运行良好,但在 iOS 11 上停止运行。无论如何,targetCell 永远不会hittable。在 XCUIElement *targetCell = [lensesCollectionView.cells elementBoundByIndex:lensIndex] 之前添加 sleep(10) 没有帮助。

我见过其他地方提到的 hacky 解决方案,例如

func forceTapElement() {   
    if self.isHittable {   
        self.tap()   
    } else {   
        var coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))   
        coordinate.tap()   
    }  
}

但这看起来不是很干净。实现这一目标的最简洁方法是什么?


更新:如果我在不检查hittable 的情况下尝试点击它,我会收到此错误:

error: Error -25204 performing AXAction 2003 on element pid: 43616, elementOrHash.elementID: 4882574576.240



Best Answer-推荐答案


事实证明,在 iOS 11 上,isAccessibilityElement 在我们自定义的 collection view cells 上是NO(奇怪的是,在 iOS 10 上是 YES)。将其显式设置为 YES 解决了这个问题。

关于ios - Xcode UI 测试 Collection View 单元格在 iOS 11 上变得不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46819807/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4