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 identifier -
optional_container_type
is the container type-
documents
is the only available option-
You may specify
documents
container type only for bundle ids returned byifuse -u <udid> --list-apps
-
e.g. Below On My iPhone image has Slack folder, but
com.tinyspeck.chatlyio
does not exist in the output of--list-apps
. Thus, 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
- Only apps having the flag
-
-
path_to_the_file_or_folder_inside_container
is the target to push/pull to/from them.- If the
optional_container_type
isdocuments
, this path will be mapped to
On My iPhone/<app name>
in Files app
- If the
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/'
.
// webdriver.io
let data = driver.pullFolder('@io.appium.example:documents/');
await fs.writeFile('documents.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 }
- 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 identifier -
optional_container_type
is the container type-
app
,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