Skip to main content

Upload files to physical devices

TestingBot provides a feature that allows you to specify one or more files that need to be uploaded to a physical iOS or Android device, prior to running your Appium test. This functionality allows you to run tests that require media files (photos and videos) from the iOS or Android photo gallery, or documents (PDFs, spreadsheets, any other file type) from the iOS Files app.

There are three options to use this feature, depending on your usecase. We suggest using TestingBot's custom capabilities, which place the files on the device before your session starts.

TestingBot Upload Capability

To use this functionality, you can use the uploadMedia capability, specifying an array of URLs to image files or video files. You can specify URLs to publicly downloadable media files, or you can use TestingBot Storage to upload the files to TestingBot and use the tb:// URLs.

Upload files to TestingBot

curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/storage" \
-F "file=@/path/to/app/file/media.png"

The API response will include a tb:// URL, which you can use in the uploadMedia capability.

{
  "app_url": "tb://edb4f4f3ed95a4f46714f3df"
}

Uploads to our TestingBot Storage are automatically deleted after 60 days.

Add the capability to your Appium script

Map<String, Object> tbOptions = new HashMap<>();
tbOptions.put("uploadMedia", new String[]{"tb://edb4f4f3ed95a4f46714f3df"});
options.setCapability("tb:options", tbOptions);
const capabilities = {
  'tb:options': {
    'uploadMedia': ['tb://edb4f4f3ed95a4f46714f3df']
  }
}
capabilities = {
  "tb:options" : {
    "uploadMedia" : ["tb://edb4f4f3ed95a4f46714f3df"]
  }
}
capabilities = {
  "tb:options" => {
    "uploadMedia" => ["tb://edb4f4f3ed95a4f46714f3df"]
  }
}
AppiumOptions options = new AppiumOptions();
var tbOptions = new Dictionary<string, object>();
tbOptions.Add("uploadMedia", new string[] { "tb://edb4f4f3ed95a4f46714f3df" });
options.AddAdditionalAppiumOption("tb:options", tbOptions);

TestingBot will add these files to the Android or iOS device. The metadata of the gallery on the device will be updated automatically, which means the media file will immediately appear in the device's gallery.

  • Android: the media files will be added to the Default Gallery app. /sdcard/Pictures for images and /sdcard/Movies for videos.
  • iOS: the media files will be added to the iOS Camera Roll: com.apple.mobileslideshow

Upload documents to the iOS Files app

For files that are not photos or videos, use the uploadFiles capability with an array of URLs. Any file type works: PDFs, spreadsheets, text files, archives, and so on. As with uploadMedia, the URLs can point to publicly downloadable files or to TestingBot Storage tb:// URLs.

Before your session starts, TestingBot downloads the files onto the physical iOS device. They appear in the Files app under On My iPhone (or On My iPad) in a folder named TestingBot, each file keeping the name it has in the URL. Any app that uses the standard iOS document picker can open them from there, for example to test a file upload in your app.

Map<String, Object> tbOptions = new HashMap<>();
tbOptions.put("uploadFiles", new String[]{"tb://edb4f4f3ed95a4f46714f3df", "https://example.com/contract.pdf"});
options.setCapability("tb:options", tbOptions);
const capabilities = {
  'tb:options': {
    'uploadFiles': ['tb://edb4f4f3ed95a4f46714f3df', 'https://example.com/contract.pdf']
  }
}
capabilities = {
  "tb:options" : {
    "uploadFiles" : ["tb://edb4f4f3ed95a4f46714f3df", "https://example.com/contract.pdf"]
  }
}
capabilities = {
  "tb:options" => {
    "uploadFiles" => ["tb://edb4f4f3ed95a4f46714f3df", "https://example.com/contract.pdf"]
  }
}
AppiumOptions options = new AppiumOptions();
var tbOptions = new Dictionary<string, object>();
tbOptions.Add("uploadFiles", new string[] { "tb://edb4f4f3ed95a4f46714f3df", "https://example.com/contract.pdf" });
options.AddAdditionalAppiumOption("tb:options", tbOptions);
  • Location: Files app → Browse → On My iPhone → TestingBot.
  • Availability: physical iOS and iPadOS devices. For Android, use uploadMedia or Appium's pushFile.
  • Combining: uploadMedia and uploadFiles can be used together in the same session.
  • Cleanup: the folder is removed when your session ends; nothing is left on the device.

Appium Push and Pull

Appium provides both pushFile and pullFile functionality. This is supported since Appium Version 1.15.0.

With this approach, the file is pushed when the test has already started. Pushing media files to the iOS or Android device does not guarantee the updating of the metadata in the iOS or Android gallery, which means your media file might not appear (immediately).

Android Example

Push a file to the SD Card of the Android device:

// Push a file to the sdcard
driver.pushFile("/sdcard/Download/sample.png", new File(System.getProperty("user.home") + "/sample.png"));

// Pull file from sdcard
byte[] fileBase64 = driver.pullFile("/sdcard/Download/sample.png");
// Push file - WebdriverIO syntax
const data = Buffer.from("TestingBot").toString('base64');
await driver.pushFile('/sdcard/Download/sample.txt', data);

// Pull file WebdriverIO example
const fileData = await driver.pullFile('/sdcard/Download/sample.txt');
# Push a file
dest_path = '/sdcard/Download/sample.txt'
driver.push_file(dest_path, 'TestingBot'.encode("utf-8"))

# Pull file
file_base64 = driver.pull_file(dest_path)
# Push a file
driver.push_file('/sdcard/Download/sample.png', File.read('/Users/testingbot/Desktop/sample.png'))

# Pull file
driver.pull_file('/sdcard/Download/sample.png')
// Push a file
driver.PushFile("/sdcard/Download/sample.png", new FileInfo("/Users/testingbot/Desktop/sample.png"));

// Pull file
byte[] fileBase64 = driver.PullFile("/sdcard/Download/sample.png");

iOS Example

Before using the pull and push functionality, you'll need to ensure that:

  • Your iOS app must have set the UIFileSharingEnabled key to true in the Info.plist file, which enables file sharing.

  • Alternatively, you can set the LSSupportsOpeningDocumentsInPlace key to true in the Info.plist to expose your app's folder in the Files app on the iOS device.

The destination path to push a file is in the following format: @<app_bundle_id>:documents/<image_name>.<extension>

// Push an image file
driver.pushFile("@com.testingbot.Sample-App:documents/sample.png", new File("/Users/testingbot/Desktop/sample.png"));

// Pull file
byte[] fileBase64 = driver.pullFile("@com.testingbot.Sample-App:documents/sample.png");
// Push file WebdriverIO example
const data = Buffer.from("TestingBot").toString('base64');
await driver.pushFile('@com.testingbot.Sample-App:documents/sample.txt', data);

// Pull file WebdriverIO example
const fileData = await driver.pullFile('@com.testingbot.Sample-App:documents/sample.txt');
# Push an image file
driver.push_file('@com.testingbot.Sample-App:documents/sample.png', source_path='/Users/testingbot/Desktop/sample.png')

# Push a text file
dest_path = '@com.testingbot.Sample-App:documents/sample.txt'
driver.push_file(dest_path, 'TestingBot'.encode("utf-8"))

# Pull file
file_base64 = driver.pull_file(dest_path)
# Push an image file
driver.push_file('@com.testingbot.Sample-App:documents/sample.png', File.read('/Users/testingbot/Desktop/sample.png'))

# Pull file
driver.pull_file('@com.testingbot.Sample-App:documents/image.png')
// Push an image file
driver.PushFile("@com.testingbot.Sample-App:documents/image.png", new FileInfo("/Users/testingbot/Desktop/sample.png"));

// Pull file
byte[] fileBase64 = driver.PullFile("@com.testingbot.Sample-App:documents/sample.png");
Was this page helpful?
Last updated