Features

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

Copy code
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.

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

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

Add the capability to your Appium script

Copy code
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("uploadMedia", new String[]{"tb://edb4f4f3ed95a4f46714f3df"});
Copy code
const capabilities = {
	'tb:options': {
		'uploadMedia': ['tb://edb4f4f3ed95a4f46714f3df']
	}
}
Copy code
capabilities = {
	"tb:options" : {
		"uploadMedia" : ["tb://edb4f4f3ed95a4f46714f3df"]
	}
}
Copy code
capabilities = {
	"tb:options" => {
			"uploadMedia" : ["tb://edb4f4f3ed95a4f46714f3df"]
	}
}
Copy code
AppiumOptions capabilities = new AppiumOptions();
HashMap<String, Object> tbOptions = new Dictionary<string, object>();
tbOptions.Add("uploadMedia", ["tb://edb4f4f3ed95a4f46714f3df"]);
capabilities.AddAdditionalCapability("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

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:

Copy code
// Push a file to the sdcard
driver.pushFile("/sdcard/Download/sample.png", new File("~/sample.png"));

// Pull file from sdcard
byte[] fileBase64 = driver.pullFile("/sdcard/Download/sample.png");
Copy code
// 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');
Copy code
# 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)
Copy code
# Push a file
driver.push_file('/sdcard/Download/sample.png', File.read('/Users/testingbot/Desktop/sample.png'))

# Pull file
pull_file('/sdcard/Download/sample.png')
Copy code
// 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 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>

Copy code
// 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");
Copy code
// 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');
Copy code
# 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)
Copy code
# Push an image file
driver.push_file('@com.testingbot.Sample-App:documents/sample.png', File.read('/Users/testingbot/Desktop/sample.png'))

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

// Pull file
byte[] fileBase64 = driver.PullFile("@com.testingbot.Sample-App:documents/sample.png");