1

Is there a way to programmatically trigger a shake gesture in a Swift UI test?

shim
  • 9,289
  • 12
  • 69
  • 108
Preethi
  • 11
  • 1

1 Answers1

0

This is not presently supported in XCUITest, but has been a common request over the years. This will not work headless, but AFAIK there isn't a way to run an iOS simulator in headless mode (maybe CI does it?), using AppleScript to trigger the menu item is the only way:

tell application "Simulator" to activate
tell application "System Events"
  keystroke "z" using {control down, command down}
end tell

You could also have your script select the specific menu items rather than using a keyboard shortcut, but I think this might be more error prone:

tell application "Simulator" to activate
tell application "System Events"
  tell process "Simulator"
    click menu item "Shake" of menu "Device" of menu bar 1
  end tell
end tell

Can you execute an Applescript script from a Swift Application explains how to execute AppleScript in Swift.

Mike Collins
  • 4,108
  • 1
  • 21
  • 28