Screenshots

You can capture screenshots at key steps during test execution using the Spoon library. They can help detect the exact step where the failure occurred. They also help identify any layout or design related issues in your application. Its easy to integrate Spoon into your project and enable screenshot capturing for your Espresso test execution.

Step 1: Add Spoon library to your project

Follow instructions on Spoon project’s webpage to add required dependencies to your project. Also, ensure that your app has WRITE_EXTERNAL_STORAGE permissions to save screenshots. A sample reference for the AndroidManifest.xml file is shown below:

<manifest>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
</manifest>

Step 2: Update your tests to take screenshots

Call the Spoon.screenshot(activityName, tag) method to capture screenshots from your Espresso tests. Example:

@Test
public void ensureAdditionWorks() {
    onView(withId(R.id.buttonOne)).perform(click());
    onView(withId(R.id.buttonTwo)).perform(click());
    onView(withId(R.id.buttonAdd)).perform(click());
    onView(withId(R.id.editText)).check(matches(withText("33")));
    Spoon.screenshot(mainActivity, "post_addition");
}

Step 3: Enable screenshots while testing on BrowserStack

Screenshots are disabled by default for Espresso tests on BrowserStack. To enable screenshots, you need to pass the enableSpoonFramework parameter in the REST API request to start Espresso test execution. An example cURL request to enable device logs is shown below :

REST API endpoint:

POST /app-automate/espresso/v2/build
Parameter Description Values
enableSpoonFramework Capture screenshots during Espresso test execution using the Spoon library. true, false
Default: false

Example cURL request:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"enableSpoonFramework": true, "devices": ["Google Pixel-7.1"], "app": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4", "testSuite": "bs://e994db8333e32a5863938666c3c3491e778352ff"}' \
-H "Content-Type: application/json"
Note: You can also reference our Sample Espresso project that has integrated Spoon library to capture screenshots in the tests.

Step 4: View screenshots for your test execution

On the test details page of App Automate dashboard, you can view screenshots for each executed test case :

View screenshots for your test execution on dashboard

The name of screenshot will be set to the human readable tag value that was passed inside Spoon.screenshot(activityName, tag) method.

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
Talk to an Expert