Custom Espresso options
Learn how to use custom Espresso options in your Espresso test executions on BrowserStack App Automate.
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:
Check out the Getting started guide for Espresso testing to learn more about running your Espresso tests on BrowserStack.
Pass custom adb parameters
You can pass custom adb parameters using the instrumentationOptions 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
Keyparameter can be eitherstring,boolean, orint. - The
Valueparameter can also be eitherstring(/^[a-zA-Z0-9<>&@,\/._-#\s]+$/),boolean,float, orint. - You can send up to five 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 instrumentationOptions as follows:
"instrumentationOptions": {"key1": "value1", "key2": "value2"}
Apart from the custom key-value pairs, you can also use the key-value pairs supported by the instrument option. Check out the various key-value pairs you can use in your test runner.
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 instrumentationOptions 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
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!