测试人社区

Appium-ios-xctest-file-movement

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.

  1. @<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>
  2. @<app_bundle_id>/<path_to_the_file_or_folder_inside_container>
  3. <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 by ifuse -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 as com.tinyspeck.chatlyio@documents/

    • The others work as format 2
      • Only apps having the flag UIFileSharingEnabled in their info.plist can be mounted
  • path_to_the_file_or_folder_inside_container is the target to push/pull to/from them.
    • If the optional_container_type is documents, this path will be mapped to
      On My iPhone/<app name> in Files app

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

官方链接为:http://appium.io/docs/en/writing-running-appium/ios/ios-xctest-file-movement