ADB Commands API Referenceο
Overviewο
The ADB Commands API allows you to execute Android Debug Bridge (ADB) shell commands remotely from within your Espresso tests. This API provides direct access to the deviceβs shell environment, enabling advanced testing scenarios that require system-level interactions.
Direct Device Control: Execute shell commands on test devices
Advanced Testing: Perform system-level operations during tests
Flexible Integration: Works seamlessly with Espresso test framework
Remote Execution: Execute commands without physical device access
File System Operations: List, create, or modify files
App State Management: Clear app data or cache
System Settings: Modify device settings for testing
Network Operations: Configure network conditions
API Specificationο
HTTP Method: POST
Endpoint URL:
http://<RobusTest URL>/v3/device/shell?accesskey=<user_access_key>
Request Headers:
Content-Type: application/json
Request Payload:
{
"_id": "device_id",
"command": "<ADB SHELL COMMAND>"
}
Success Response:
{
"status": "success",
"output": "command execution result",
"exitCode": 0
}
Error Response:
{
"status": "error",
"message": "Command execution failed",
"exitCode": 1
}
Access Key:
Your access key is required as a query parameter in the URL. You can obtain your access key from:
User Profile: Navigate to User Profile β Access Keys
Project Settings: Found in Project Dashboard β Settings
Security Notes:
Keep your access key secure
Never commit access keys to version control
Rotate keys regularly for security
Parameters Referenceο
Parameter |
Type |
Description |
Example |
Required |
|---|---|---|---|---|
_id |
String |
Device ID of the target device for command execution |
|
Yes |
command |
String |
ADB shell command to execute on the device |
|
Yes |
accesskey |
String |
User access key for authentication (URL parameter) |
|
Yes |
Device ID Retrievalο
Since the Device ID is required for the API payload, you can obtain it within your Espresso test using the following Java code:
Bundle testBundle = InstrumentationRegistry.getArguments();
String deviceID = testBundle.getString("deviceID");
// Use the deviceID in your API call
System.out.println("Current Device ID: " + deviceID);
val testBundle = InstrumentationRegistry.getArguments()
val deviceID = testBundle.getString("deviceID")
// Use the deviceID in your API call
println("Current Device ID: $deviceID")
Sample Implementationο
Hereβs a complete example of how to use the ADB Commands API:
Request:
POST /v3/device/shell?accesskey=1234DFFGG24FDSD HTTP/1.1
Host: devicelab.robustest.com
Content-Type: application/json
{
"_id": "2132SDSFDSFDSF",
"command": "ls /data/local/tmp/"
}
Response:
{
"status": "success",
"output": "file1.txt\nfile2.txt\ntest_data/",
"exitCode": 0
}
Clear App Data:
{
"_id": "2132SDSFDSFDSF",
"command": "pm clear com.example.app"
}
Install APK:
{
"_id": "2132SDSFDSFDSF",
"command": "pm install /data/local/tmp/test.apk"
}
Check Battery Level:
{
"_id": "2132SDSFDSFDSF",
"command": "dumpsys battery | grep level"
}
curl -X POST \
'http://devicelab.robustest.com/v3/device/shell?accesskey=1234DFFGG24FDSD' \
-H 'Content-Type: application/json' \
-d '{
"_id": "2132SDSFDSFDSF",
"command": "ls /data/local/tmp/"
}'
Common ADB Commandsο
List Directory:
ls /path/to/directoryCreate Directory:
mkdir /path/to/new/directoryCopy File:
cp /source/file /dest/fileRemove File:
rm /path/to/fileChange Permissions:
chmod 755 /path/to/file
Clear App Data:
pm clear com.package.nameInstall APK:
pm install /path/to/app.apkCheck Processes:
ps | grep process_nameMemory Info:
dumpsys meminfoBattery Status:
dumpsys battery
Best Practicesο
Note
Security Considerations:
Only execute trusted commands
Validate command parameters to prevent injection attacks
Use appropriate error handling for failed commands
Monitor command execution for security anomalies
Tip
Performance Tips:
Keep commands lightweight to avoid test timeouts
Use specific paths rather than wildcards when possible
Cache device IDs to avoid repeated retrievals
Implement retry logic for transient failures
Error Handlingο
Common error scenarios and their solutions:
Error Type |
Description |
Solution |
|---|---|---|
Invalid Device ID |
Device ID not found or inactive |
Verify device availability and correct ID |
Command Timeout |
Command execution exceeded timeout |
Use simpler commands or increase timeout |
Permission Denied |
Insufficient permissions for command |
Use appropriate permissions or alternative commands |
Authentication Error |
Invalid access key |
Verify access key validity and permissions |
See also
Related Documentation:
Espresso Testing Hub - Espresso Hub Integration
API to switch to specific SSID - WiFi Network Switching API
Job Payload API Reference - Job Payload API Reference
Automation Reports - Understanding Test Reports