Test with sample data

It’s easy to test scenarios that require the device to be set up with sample test data ( e.g., photos, videos, contacts, etc. ) so that it’s made available to your application during test execution. There are multiple ways of how you can achieve this on BrowserStack:

Use pre-loaded media files

We have uploaded some pre-set images and videos on our devices for you to test your flows involving images or videos easily. The details for these media files are as follows:

OS Pre-loaded media file path Pre-loaded media file names
Android Images:
/sdcard/Pictures

Videos:
/sdcard/Movies
Images:
Android_O.png , BrowserStack.jpg , Laptop_with_code.jpg , Test_on_Real_Devices.jpg , UC_Browser_on_iOS.png , s8-tweet.jpg

Videos:
android-oreo.mp4 , ipx.mp4 , note_8_on_app_live_tweet.mp4
iOS Images:
/private/var/mobile/Media/DCIM/

Videos:
/private/var/mobile/Media/DCIM/
Images:
IMG_0001.PNG , IMG_0002.JPG , IMG_0003.PNG , IMG_0004.JPG , IMG_0005.JPG

Videos:
IMG_0007.MOV , IMG_0008.MOV , IMG_0009.MOV


Use pre-loaded contacts

We have pre-loaded our devices with sample contacts for you to easily test scenarios that need access to contacts from the device. These sample contacts are dummy data and intended to be used exclusively for testing. You can download these sample contacts for your reference.

Upload your own media files

You can also use your own media files for testing. Before starting test execution, you first need to upload these media files using REST API. The REST API response will return a media_url for each successful file upload. Use this value to set browserstack.uploadMedia capability in your Appium test scripts. BrowserStack will fetch and download these media files to the device at the beginning of the test execution.

Capability Description Values
browserstack.uploadMedia Set this capability if you want to use your uploaded images or videos in the test. Upload your media files to BrowserStack servers using REST API. Use the media_url value returned as a result of the upload request to set this capability. The media_url returned on successful upload.
Example: ["media://hashedid", "media://hashedid"]

Example :

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.uploadMedia", new String[]{"media://21d66a8a0471097bbf5789330129e9ab97e467e3","media://4d5f6w4h6dq19fg4nl9o5e9ab97d1s1y0i9kl2d3d"});
var capabilities = {
	'browserstack.uploadMedia': ['media://21d66a8a0471097bbf5789330129e9ab97e467e3','media://4d5f6w4h6dq19fg4nl9o5e9ab97d1s1y0i9kl2d3d']
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.uploadMedia", new[] {"media://21d66a8a0471097bbf5789330129e9ab97e467e3","media://4d5f6w4h6dq19fg4nl9o5e9ab97d1s1y0i9kl2d3d"});
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.uploadMedia", ["media://21d66a8a0471097bbf5789330129e9ab97e467e3","media://4d5f6w4h6dq19fg4nl9o5e9ab97d1s1y0i9kl2d3d"]);
desired_cap = {
	'browserstack.uploadMedia': ['media://21d66a8a0471097bbf5789330129e9ab97e467e3','media://4d5f6w4h6dq19fg4nl9o5e9ab97d1s1y0i9kl2d3d']
}
desired_caps = {
    'browserstack.uploadMedia': ['media://21d66a8a0471097bbf5789330129e9ab97e467e3','media://4d5f6w4h6dq19fg4nl9o5e9ab97d1s1y0i9kl2d3d']
}

Access uploaded media files during testing

During test execution, you can access your uploaded media files as follows:

  • 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/.
Note:
  1. Only 5 media files per test are allowed.
  2. Supported format for images are JPG, JPEG, PNG, GIF, BMP and max file size allowed for images is 10MB.
  3. Supported format for videos are .mp4, .mov and .3gp and max file size allowed for videos is 50MB.
Note: Custom media feature is currently not supported on iOS 13+ devices.

Appium’s push and pull file command

During testing, you can also use Appium’s push file command to copy your own files (media, data, text,etc.) to the device and pull file command to retrieve files from the device.

During test execution, copy files to and retrieve files from /sdcard/Download/, /sdcard/Pictures and /sdcard/Android/data/<your_app_package> folders on the Android device.

Example :

// 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 a file
let data = new Buffer("Hello World").toString('base64');
driver.pushFile('/sdcard/Download/file.txt', data);

// Pull file
let data = 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->pushFile('/sdcard/Download/file.txt', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

// Pull file
$data = $driver->pullFile('/sdcard/Download/file.txt');
# Push a file
dest_path = '/sdcard/Download/file.txt'
driver.push_file(dest_path, 'Hello World'.encode("utf-8"))

# Pull file
file_base64 = driver.pull_file(dest_path)
# 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')

During test execution, copy files to your app’s documents folder on iOS device. Ensure the following:

  • Your iOS app has UIFileSharingEnabled key set to true in Info.plist
  • The destination path to push a file needs to have the following format: @<app_bundle_id>:documents/<image_name>.png

Example :

// 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");
// webdriver.io example
let data = new Buffer("Hello World").toString('base64');
driver.pushFile('@com.browserstack.Sample-iOS:documents/file.txt', data);

// Pull file
let data = 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");
$driver->pushFile('@com.browserstack.Sample-iOS:documents/foo.bar', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

// Pull file
$data = $driver->pullFile('@com.browserstack.Sample-iOS:documents/foo.bar');
# Push an image file
driver.push_file('@com.browserstack.Sample-iOS:documents/image1.png', source_path='/Users/johndoe/Desktop/image1.png')

# Push a text file
dest_path = '@com.browserstack.Sample-iOS:documents/file.txt'
driver.push_file(dest_path, 'Hello World'.encode("utf-8"))

# Pull file
file_base64 = driver.pull_file(dest_path)
# Push an image file
driver.push_file('@com.browserstack.Sample-iOS:documents/image.jpg', File.read('/Users/johndoe/Desktop/image.jpg'))

# Pull file
pull_file('@com.browserstack.Sample-iOS:documents/image.jpg')
Note: Ensure that Appium version is set to 1.15.0 or higher in your test scripts to use Appium’s push and pull file functionality

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Talk to an Expert