Search code examples
iosimageios11xcuitest

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


Since iOS 11 XCUITest is not able anymore to find hitpoints for UIImages anymore, which results in not being able to tap an image or drag a touch to it by using press(forDuration:thenDragTo:).

There is a workaround for tapping an image which works (using tap on coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0))). The same approach does not work for the thenDragTo method, because it expects a XCUIElement.

Does anyone have an idea how to get the thenDragTo method to work (preferably without having to edit production code)?

Thanks in advance


Solution

  • It accepts XCUICoordinate in my tests in Xcode 9.2

    extension XCUICoordinate {
        open func press(forDuration duration: TimeInterval, thenDragTo otherCoordinate: XCUICoordinate)
    }
    

    I am able to use it like this:

    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)