I would like to include a UI test in my project that exercises its interaction with UIDocumentPickerViewController
. The test will need to run on a CI machine, which needs to be able to wipe the simulator before each build, and operate without a human driving the GUI (either on the machine or the simulator).
There are a number of answered questions around how to add files to the iOS simulator, but they seem to all require manual interaction with the simulator UI. What I've tried so far:
- Using
xcrun simctl openurl file:///path/to/my%20file.pdf
, but that just presents a sheet in the files app that would need manual intervention to actually save to the simulator. - Using
xcrun simctl addmedia
, but the media need to be images or videos and they end up inPHPickerViewController
and notUIDocumentPickerViewController
. - Using the
openurl
command above before the test kicks off and then adding a button in my app to open theshareddocuments://
URL to present the Files app, and using the UI test runner to click the "On My Phone" and "Save" buttons. This looks promising but also promises to be flaky.
What I haven't tried yet:
- Set up a sockpuppet iCloud account and log the simulator into that account on every test run in order to use iCloud Drive. This seems like yet another credential to manage that will randomly break when it needs to agree to some new terms and conditions.
- Replace my test app with a document-based app and figure out how to save a file from the bundle to its file storage without manual interaction. I'd love a guide on how to do this but it feels like I could easily spend a week getting up to speed on document-based apps to get it working.
The code I'm testing is a framework, so the app under test is free to have features that would make no sense to an actual user and is also free to do non-app-store-safe things. But it seems like other developers might appreciate a more general solution if you have one.