XCUITest Drag cross multiple elements

Viewed 30

I want to test gesture pattern

It's need drag and hold cross multiple elements

But when I use press(forDuration: Int, thenDragTo: XCUIElement)

it would drop touch when drag to element

Is there any way to test this case?

The scenario that I want to do is:

  1. Press and hold element 1
  2. hold and drag cross element 2 -> element 3 -> ....
  3. drop
1 Answers

You have the right function, but you need to add the thenHoldForDuration parameter. See press(forDuration:thenDragTo:withVelocity:thenHoldForDuration:).

The problem you might face is XCUITest is synchronous. If you need to assert something while the press is held, you're out of luck; the code will not proceed until the duration is reached and the press is released.

Related