Upload files to physical devices
TestingBot provides a feature that allows you to specify one or more media 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.
There are two options to use this feature, depending on your usecase. We suggest using the first option, which will use TestingBot's custom uploadMedia
capability.
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
Uploads to our TestingBot Storage are automatically deleted after 62 days.
Add the capability to your Appium script
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
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 file - WebdriverIO syntax
let data = Buffer.from("TestingBot").toString('base64');
driver.pushFile('/sdcard/Download/sample.txt', data);
// Push file WD example
await driver.pushFileToDevice('/sdcard/Download/sample.txt', 'VGVzdGluZ0JvdA==');
// Pull file WebdriverIO example
let data = driver.pullFile('/sdcard/Download/sample.txt');
// Pull file WD example
let data = await driver.pullFile('/sdcard/Download/sample.txt');
iOS Example
Before using the pull and push functionality, you'll need to ensure that:
-
Your iOS app must have set the
UIFileSharingEnabled
key totrue
in theInfo.plist
file, which enables file sharing. -
Alternatively, you can set the
LSSupportsOpeningDocumentsInPlace
keytrue
in theInfo.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 file WebdriverIO example
let data = Buffer.from("TestingBot").toString('base64');
driver.pushFile('@com.testingbot.Sample-App:documents/sample.txt', data);
// Push file wd example
await driver.pushFileToDevice('@com.testingbot.Sample-App:documents/sample.txt', 'VGVzdGluZ0JvdA==');
// Pull file WebdriverIO example
let data = driver.pullFile('@com.testingbot.Sample-App:documents/sample.txt');
// Pull file wd example
let data = await driver.pullFile('@com.testingbot.Sample-App:documents/file.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)