Important:
Ability to upload non-media files on devices is available only under Device Cloud Pro, Device Cloud Pro + Visual Cloud, Enterprise Device Cloud Pro and Enterprise Device Cloud Pro + Visual Cloud plans. For more details, please checkout our pricing page.
App Automate provides preloaded media files on BrowserStack remote devices to test scenarios that require access to files from the device.
Apart from preloaded media files, you can also upload your media or non-media files in App Automate.
Use either of the following methods to upload your media or non-media files to BrowserStack remote devices:
Android: Default gallery app. The file path is /sdcard/Pictures for images and /sdcard/Movies for videos.
iOS: Camera Roll. The file path to camera roll directory is /private/var/mobile/Media/DCIM/.
Android: Default Downloads folder of the device
iOS: App’s directory in the device. The file path is Files app → On My iPhone → Your app's directory → ‘Custom_Files’ folder created by BrowserStack.
Set the capability in test script
Set the browserstack.uploadMedia capability to the value of the media_url parameter returned in the API response as shown in the following code snippets:
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.uploadMedia", new String[]{"media://90c7a8h8dc82308108734e9a46c24d8f01de12881"});
var capabilities = {
'browserstack.uploadMedia': ['media://90c7a8h8dc82308108734e9a46c24d8f01de12881']
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.uploadMedia", new[] {"media://90c7a8h8dc82308108734e9a46c24d8f01de12881"});
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.uploadMedia", ["media://90c7a8h8dc82308108734e9a46c24d8f01de12881"]);
The number of file uploads allowed per session is 5.
Files are stored on BrowserStack servers for at most 30 days.
In the case of non-media files, ensure that your iOS app has the UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace keys set to true in the Info.plist file. This is required to make your app’s folder available in the Files app.
Appium’s push and pull file command
You can also upload files using Appium’s push and pull file command, which doesn’t use any BrowserStack capability or API to upload your files to BrowserStack remote devices during testing.
During testing, use Appium’s push file command to copy your files (media, data, text, etc.) to the device and the pull file command to retrieve the files from the device.
Note:
Appium’s push and pull file functionality is supported only for Appium version1.15.0and above.
In your test script, write commands to copy files to and retrieve files from /sdcard/Download/, /sdcard/Pictures, and /sdcard/Android/data/<your_app_package> folders on the Android device.
The following code snippets show how to use the push and pull file commands:
// Push a file
driver.pushFile("/sdcard/Download/image.jpg", new File("/Users/johndoe/Desktop/image.jpg"));
// Pull file
byte[] fileBase64 = driver.pullFile("/sdcard/Download/image.jpg");
// Push file webdriver.io example
let data = Buffer.from("Hello World").toString('base64');
driver.pushFile('/sdcard/Download/file.txt', data);
// Push file wd example
await driver.pushFileToDevice('/sdcard/Download/file.txt', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');
// Pull file webdriver.io example
let data = driver.pullFile('/sdcard/Download/file.txt');
// Pull file wd example
let data = await driver.pullFile('/sdcard/Download/file.txt');
// Push a file
driver.PushFile("/sdcard/Download/image.jpg", new FileInfo("/Users/johndoe/Desktop/image.jpg"))
// Pull file
byte[] fileBase64 = driver.PullFile("/sdcard/Download/image.jpg");
# Push a file
driver.push_file('/sdcard/Download/image.jpg', File.read('/Users/johndoe/Desktop/image.jpg'))
# Pull file
pull_file('/sdcard/Download/image.jpg')
In your test script, write commands to copy files to and retrieve files from your app’s documents folder on iOS device.
Before uploading, ensure that:
Your iOS app has UIFileSharingEnabled key set to true in the Info.plist file to enable file sharing. Files are then made available in the iTunes app. Optionally, you can set the LSSupportsOpeningDocumentsInPlace key set to true in the Info.plist file to expose your app’s folder in the Files app.
The destination path to push a file is in the following format: @<app_bundle_id>:documents/<image_name>.png
The following code snippets show how to use the push and pull file commands:
// Push an image file
driver.pushFile("@com.browserstack.Sample-iOS:documents/image.jpg", new File("/Users/johndoe/Desktop/image.jpg"));
// Pull file
byte[] fileBase64 = driver.pullFile("@com.browserstack.Sample-iOS:documents/image.jpg");
// Push file webdriver.io example
let data = Buffer.from("Hello World").toString('base64');
driver.pushFile('@com.browserstack.Sample-iOS:documents/file.txt', data);
// Push file wd example
await driver.pushFileToDevice('@com.browserstack.Sample-iOS:documents/file.txt', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');
// Pull file webdriver.io example
let data = driver.pullFile('@com.browserstack.Sample-iOS:documents/file.txt');
// Pull file wd example
let data = await driver.pullFile('@com.browserstack.Sample-iOS:documents/file.txt');
// Push an image file
driver.PushFile("@com.browserstack.Sample-iOS:documents/image.jpg", new FileInfo("/Users/johndoe/Desktop/image.jpg"))
// Pull file
byte[] fileBase64 = driver.PullFile("@com.browserstack.Sample-iOS:documents/image.jpg");