XCUITest - 无法使用 iOS 11 找到图像的命中点

XCUITest - Unable to find hit point for Image using iOS 11

自 iOS 11 XCUITest 不再能够找到 UIImages 的命中点,这导致无法点击图像或使用 press(forDuration:thenDragTo:) 拖动触摸到它。

点击图片有一个解决方法(在 coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)) 上使用 tap)。同样的方法不适用于 thenDragTo 方法,因为它需要一个 XCUIElement.

有没有人知道如何让 thenDragTo 方法工作(最好不必编辑生产代码)?

提前致谢

它在我的 Xcode 9.2

测试中接受 XCUICoordinate
extension XCUICoordinate {
    open func press(forDuration duration: TimeInterval, thenDragTo otherCoordinate: XCUICoordinate)
}

我可以这样使用它:

let fromCoordinate = contentElement.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
let toCoordinate = fromCoordinate.withOffset(CGVector(dx: 0, dy: 260))
fromCoordinate.press(forDuration: 0.01, thenDragTo: toCoordinate)