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.

πŸš€ Key Benefits
  • 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

πŸ”§ Common Use Cases
  • 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>"
}

Parameters Reference

API Parameters

Parameter

Type

Description

Example

Required

_id

String

Device ID of the target device for command execution

"2132SDSFDSFDSF"

Yes

command

String

ADB shell command to execute on the device

"ls /data/local/tmp/"

Yes

accesskey

String

User access key for authentication (URL parameter)

"1234DFFGG24FDSD"

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);

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
}

Common ADB Commands

πŸ“ File Operations
  • List Directory: ls /path/to/directory

  • Create Directory: mkdir /path/to/new/directory

  • Copy File: cp /source/file /dest/file

  • Remove File: rm /path/to/file

  • Change Permissions: chmod 755 /path/to/file

πŸ”§ System Operations
  • Clear App Data: pm clear com.package.name

  • Install APK: pm install /path/to/app.apk

  • Check Processes: ps | grep process_name

  • Memory Info: dumpsys meminfo

  • Battery 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:

Common Errors

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: