2017-10-18 118 views
2

我们使用此代码来模拟一个UICollectionView对Xcode的UI测试第一小区自来水:Xcode的UI测试集合视图细胞变得不hittable iOS上11

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)没有帮助。

我见过哈克解决方案

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

+0

我遇到了这个问题,它不是在屏幕上的单元格 - 它们以前是在iOS 10上运行时自动滚屏到屏幕上的。当您尝试点击它时,您的单元格是否在屏幕上? – Oletha

+0

这绝对是在屏幕上。我可以在手机上看到它,并且'targetCell.frame'在屏幕内。然而,它仍然是不可接受的。 –

回答

3

事实证明,isAccessibilityElementNO在我们的定制集合视图细胞 iOS 11(奇怪的是,它是,在iOS 10)。明确将其设置为YES解决了该问题。

0

里卡多的答案应该是公认的答案。 为了清楚起见,我们遇到了同样的问题,并在UICollectionViewCell的Class文件中解决了它。 在initWithCoder:我们刚才添加的属性isAccessibilityElement

- (id)initWithCoder:(NSCoder *)coder { 
    self = [super initWithCoder:coder]; 

    if (self != nil) { 
     self.isAccessibilityElement = YES; 
    } 

    return self; 
} 

我们现在可以运行相同的测试脚本形式的Xcode 8在Xcode 9.1和细胞被正确地挖掘出来。

感谢这个伟大的解决方案。