Is there a way to programmatically trigger a shake gesture in a Swift UI test?
Asked
Active
Viewed 376 times
1
-
Mind sharing with us what you've tried? Are you having a problem you aim to fix by triggering this manually? Could mocking solve this? – Renzo Tissoni Nov 03 '21 at 17:16
-
What usage would that have? – Cristik Nov 04 '21 at 02:05
1 Answers
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