我有以下 Xcode UI 测试代码,一周前曾通过,但现在出现错误
let cellsQuery = app.cells.matching(identifier: "identifier")
XCTAssertGreaterThan(cellsQuery.count, 0)
let cell = cellsQuery.element(boundBy: 0)
expectElementToExist(cell)
cell.tap()
final func expectElementToExist(_ element: XCUIElement, exist: Bool = true, timeout: TimeInterval = 10) {
let predicate = NSPredicate(format: "exists == \(exist)")
expectation(for: predicate, evaluatedWith: element, handler: nil)
waitForExpectations(timeout: timeout, handler: nil)
XCTAssertEqual(element.exists, exist)
}
我在 cell.tap()
中遇到的错误如下
Failure fetching attributes for element <XCAccessibilityElement: 0x604001a75240> pid: 5387, elementOrHash.elementID: 105553123110000.1888: Error Domain=XCTDaemonErrorDomain Code=13 "Error copying attributes -25202" UserInfo={NSLocalizedDescription=Error copying attributes -25202}
任何帮助将不胜感激
最佳答案
最近我在将项目(Swift 3.2)升级到 XCode 9 后也遇到了类似的问题。
问题是
cell.isHittable is returning false.
这就是为什么默认的 tap() 方法不适用于分层元素。
我刚刚执行了以下程序,效果很好。
第 1 步:创建如下扩展
extension XCUIElement {
func tryClick() {
if self.isHittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx:0.5, dy:0.5))
coordinate.doubleTap()
//coordinate.press(forDuration: 0.5)
}
}
}
第2步:使用上面创建的实例方法点击元素,而不是使用直接的tap()方法。
cell.tryClick()
注意:尝试使用
CGVector(dx:0.5, dy:0.5) or CGVector(dx:0.0, dy:0.0)
希望能解决您的问题。它对我来说就像一种魅力。
关于ios - 点击单元格时 Xcode UI 测试 XCTDaemonErrorDomain Code=13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48704514/