Pushing/Pulling Files
Appium provides Pull Folder, Pull File and Push File to move files. This documentation aims to help to understand how they work for iOS.
Format
Below is the basic format.
@<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>
@<app_bundle_id>/<path_to_the_file_or_folder_inside_container>
<path_to_the_file_or_folder_inside_container>
Real device
Format
The format of method argument should be the following:
@<app_bundle_id>
is the application bundle identifieroptional_container_type
is the container typedocuments
is the only available option- You may specify
documents
container type only for bundle ids that exists in the device- Since appium-xcuitest-driver v3.55.0, mobile: listApps provides a list of available applications. Applications which have
UIFileSharingEnabled
attribute astrue
can be specified.
- Since appium-xcuitest-driver v3.55.0, mobile: listApps provides a list of available applications. Applications which have
-
e.g. Below On My iPhone image has Slack folder, but
com.tinyspeck.chatlyio
does not exist in installed bundle ids. Then, we cannot mount it ascom.tinyspeck.chatlyio@documents/
- The others work as format 2 - Only apps having the flag
UIFileSharingEnabled
in theirinfo.plist
can be mounted -path_to_the_file_or_folder_inside_container
is the target to push/pull to/from them. - If theoptional_container_type
isdocuments
, this path will be mapped toOn My iPhone/<app name>
in Files app
- You may specify
format 3 is not allowed for real devices.
Example
If you would like to pull Presentation.key form Keynote app, you can get it as below.
- Pull file
// webdriver.io
let data = driver.pullFile('@io.appium.example:documents/Presentation.key');
await fs.writeFile('presentation.key', Buffer.from(data, 'base64'), 'binary');
# ruby_lib_core
file = @driver.pull_file '@com.apple.Keynote:documents/Presentation.key'
File.open('presentation.key', 'wb') { |f| f<< file }
The file is in On My iPhone/Keynote of Files app.
Top | On My iPhone | Keynote |
---|---|---|
If the file is in deeper place like On My iPhone/Keynote/Dir1/Dir2, then the Ruby command should be:
// webdriver.io
let data = driver.pullFile('@io.appium.example:documents/Dir1/Dir2/Presentation.key');
await fs.writeFile('presentation.key', Buffer.from(data, 'base64'), 'binary');
# ruby_lib_core
file = @driver.pull_file '@com.apple.Keynote:documents/Dir1/Dir2/Presentation.key'
File.open('presentation.key', 'wb') { |f| f<< file }
- Pull folder
You can pull documents root of On My iPhone/Keynote as @driver.pull_folder '@com.apple.Keynote:documents/'
.
@driver.pull_folder '@com.apple.Keynote:documents/Keynote'
is to get files in the Keynote folder. Then, Keynote is the documentation root to get.
// webdriver.io
let data = driver.pullFolder('@io.appium.example:documents/');
await fs.writeFile('documents.zip', Buffer.from(data, 'base64'), 'binary');
let data = driver.pullFolder('@io.appium.example:documents/Keynote');
await fs.writeFile('keynote.zip', Buffer.from(data, 'base64'), 'binary');
# ruby_lib_core
file = @driver.pull_folder '@com.apple.Keynote:documents/'
File.open('documents.zip', 'wb') { |f| f<< file }
file = @driver.pull_folder '@com.apple.Keynote:documents/Keynote'
File.open('keynote.zip', 'wb') { |f| f<< file }
- Push file
Same as pull:
// webdriver.io
driver.pushFile('@com.apple.Keynote:documents/text.txt', new Buffer("Hello World").toString('base64'));
# ruby_lib_core
@driver.push_file '@com.apple.Keynote:documents/text.txt', (File.read 'path/to/file')
Simulator
Format
The format of method argument should be the following:
@<app_bundle_id>
is the application bundle identifieroptional_container_type
is the container typeapp
,data
,groups
or<A specific App Group container>
- format 2 case is handled as
app
container
path_to_the_file_or_folder_inside_container
is the target to push/pull to/from them
format 3 format handles as app
container
Example
// 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);
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