File Transfer
The XCUITest driver provides several extension commands for file transfer:
This documentation aims to help to understand how they work on iOS.
Formats¶
All commands require a parameter with a path to the file/folder on the target device. There are 3 possible formats this path can take:
Format 1¶
- @<app-bundle-id>is the application bundle identifier
- <container-type>is the container type- On simulators, common values are app,data,groups, but a custom one can also be provided
- On real devices, the only accepted value is documents. All others are treated as Format 2- This value can only be specified for apps that have the UIFileSharingEnabledflag set totrue. You can use themobile: listAppsextension to identify such apps.
 
- This value can only be specified for apps that have the 
 
- On simulators, common values are 
- <path-to-file-or-folder>is the target file or folder- On real devices, if <container-type>is set todocuments, this path will be mapped toOn My iPhone/<app name>in the Files app
 
- On real devices, if 
Format 2¶
- On simulators, the implicit <container-type>is set toapp.
- On real device, only apps with the UIFileSharingEnabledflag set totruein theirinfo.plistcan be mounted. You can use themobile: listAppsextension to identify such apps.
Format 3¶
This format is only supported on simulators. The implicit <container-type> is set to app.
Eventually the whole simulator file system is
available
directly from the macOS Finder, so you may pull any file from there by providing a path to it
relatively to the simulator's file system root.
Examples¶
pullFile¶
This example pulls a file present in Files -> On My iPhone -> Keynote:
| Top | On My iPhone | Keynote | 
|---|---|---|
|  |  |  | 
If the file is in deeper place like Keynote/Dir1/Dir2, then the path changes:
Example for a simulator using Format 3:
// Java
// Get AddressBook.sqlitedb in test app package ('app' container)
byte[] fileContent = driver.pullFile("Library/AddressBook/AddressBook.sqlitedb");
Path dstPath = Paths.get(new File("/local/path/AddressBook.sqlitedb"));
Files.write(dstPath, fileContent);
pullFolder¶
You can pull folders similarly to files, but the path must end with a forward slash (/).
pushFile¶
References¶
- https://stackoverflow.com/questions/1108076/where-does-the-iphone-simulator-store-its-data
- https://stackoverflow.com/questions/48884248/how-can-i-add-files-to-the-ios-simulator
- https://apple.stackexchange.com/questions/299413/how-to-allow-the-files-app-to-save-to-on-my-iphone-or-to-on-my-ipad-in-ios/299565#299565