Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy
No Result Found

Custom Espresso Options

BrowserStack enables you to use adb custom parameters for your Espresso testing on a wide range of real Android devices. Android Debug Bridge (adb) is a robust command-line tool that allows you to communicate with a connected Android device.

In this guide, you’ll learn how to:

Note: Check out the Getting started guide for Espresso Testing to learn more about the running your Espresso test on BrowserStack.

Pass Custom adb parameters

You can pass custom adb parameters using the instrumentationsOptions capability in our Build API.

Use the following cURL command to send custom parameters to the adb shell via the BrowserStack Build API:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"app": "<app-id>" , 
 "testSuite": "<test-suite-id>",
 "instrumentationOptions": {"key1": "value1", "key2": "value2"},
 "devices": ["Samsung Galaxy S9 Plus-9.0"]}' \
-H "Content-Type: application/json"
  • The Key parameter can be either string, boolean, or int.
  • The Value parameter can also be either string (/^[a-zA-Z0-9<>&@,\/._-#\s]+$/), boolean, float, or int.
  • You can send up to 5 Key-Value pairs to the adb shell using the curl request. The corresponding value gets executed when a given condition (or test environment) is true.

The Key-Value parameters are passed to the instrumentationsOptions as follows:

"instrumentationOptions": {"key1": "value1", "key2": "value2"}

Apart from the custom key-value pairs, you can also use the key-value pairs support by the instrument option. Check out the various Key-Value pairs you can use in your test runner.

Note: Check out the app-id and test-suite sections to know more about passing the app and test-suite parameters.

Sample Code

You can send custom key-value parameters to the adb shell via the BrowserStack Build API:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"app": "bs://j3c874f21852ea50957a3fdc33f47514288c4ba4", 
"testSuite": "bs://f7c874f21852ba57957a3fde31f47514288c4ba4",
 "instrumentationOptions": {"foo": "Log.d ( "FOO", extras.getString ( "foo" ))"},
"devices": ["Samsung Galaxy S9 Plus-9.0"]}' \
-H "Content-Type: application/json"

After sending the parameters to the BrowserStack Build API, you can use the following sample code snippet to execute instrumentationsOptions in your script:

Bundle extras = this.getIntent ( ).getExtras ( );
 if ( extras.containsKey ( "foo" ) ) {
 Log.d ( "FOO", extras.getString ( "foo" ) );
 } else {
 Log.d ( "FOO", "no foo here" );
 }

The given code contains the test key foo that executes the test method Log.d ( "FOO", extras.getString ( "foo" )). When the given test condition extras.containsKey ( "foo" ) is true, and the value parameter gets executed.

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
Download Copy Check Circle