4

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

Sascha
  • 93
  • 6

1 Answers1

1

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)
VoidLess
  • 1,382
  • 11
  • 11
  • Oh sure. I used the `press(_:thenDragTo:)` method on an object of type XCUIElement, which then only offers dragging to another XCUIElement (which makes sense I guess). Calling the `press(_:thenDragTo)` on a XCUICoordinate I am able to drag to another coordinate... thanks. – Sascha Jan 17 '18 at 10:13