Upload files to devices in App Automate
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:
Use BrowserStack’s API and capability
App Automate provides a REST API request and a capability to upload your files to BrowserStack’s remote devices and access them during testing.
In this section, you’ll learn:
- Which file types and OS versions are supported
- How to upload a file to BrowserStack
- How to set the capability in test script
Supported file types and OS version
The following tab list the supported file types you can upload, and the OS version on which you can upload the files.
The following table shows the supported file types and their maximun file size allowed to upload:
File | Type | Maximum file size |
---|---|---|
Image | JPG, JPEG, PNG, GIF, BMP | 10 MB |
Video | MP4, MOV and 3GP | 50 MB |
Non-media | XLS, XLSX, DOC, DOCX, PDF, CSV, TXT | 15 MB |
Upload your file to BrowserStack
Run the following upload media cURL command to upload your file to BrowserStack servers:
curl -u "username:accesskey" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload-media" \
-F "file=@/path/to/your/file" \
-F "custom_id=SampleFile"
A sample response for the given cURL command is as follows. It returns the value of the media_url
parameter.
{
"media_url": "media://90c7a8h8dc82308108734e9a46c24d8f01de12881",
"custom_id": "SampleFile"
}
The file you uploaded will be available in the following folders on the device:
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/
.
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"});
- 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
andLSSupportsOpeningDocumentsInPlace
keys set totrue
in theInfo.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.
push
and pull
file functionality is supported only for Appium version 1.15.0
and 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");
Need some help?
If you need any help with this feature, get in touch with us.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!