0

I need to take a screenshot in the middle of zoom/pan/rotate, i.e. I expect some code like this:

element.startPressAndHold(.twoTouches)
// at this point my app renders differently, so I capture a screenshot
// for snapshot testing
let shot = element.screenshot()
element.stopPressAndHold()

XCUIElement in fact has something similar for keys:

XCUIElement.perform(withKeyModifiers: .command) {
    let shot = element.screenshot()
}

but I can not find something similar for mouse/touches/gestures.

Is there a trick to achieve this?

Paulius Liekis
  • 1,676
  • 3
  • 18
  • 26
  • `press(forDuration:)` is all there is and as you’re finding, you won’t be able to take a screenshot until after that has completed. If there is a solution it’d be spawning that command in a separate thread from the main one, but I don’t know how to do that off the top of my head and XCUITest might not handle multiple threads of execution. You’d need to account for the timer in your main thread as well. – Mike Collins Sep 16 '21 at 15:18
  • Maybe something like this? https://stackoverflow.com/a/62082625/2533443 – Mike Collins Sep 16 '21 at 15:23

0 Answers0