How to take screenshot in aws device farm for android espresso testing

Issue

I am using aws device farm for running my android tests, and we are using espresso framework. Some of the tests are failing today, and I want to take screenshots if my test fails. I have gone through your documentation but couldn’t find anything concrete. This is what I know so far:

Documentation

You can take screenshots as part of your Android UI Automator tests.

To take a screenshot, call the takeScreenshot method (for example, takeScreenshot(“/sdcard/uiautomator-screenshots/home-screen-1234.png”);).

Note: All screenshots must be stored in the /sdcard/uiautomator-screenshots directory. You must specify the full path (including the file name) of the screenshot to be stored. The takeScreenshot method works for API Levels 17 and higher only. For API Level 16, UI Automator is supported, but screenshots are not supported.

Is there any way I can configure aws device farm to take screenshots automatically without calling the function in test? Is it supported? Also, I couldn’t find any screenshot related commands. I will really appreciate if someone could explain the steps required to screenshot. Thank you

Solution

Disclaimer: I am a developer working on AWS Device Farm.

That bit of documentation about the takeScreenshot method is for uiautomator 1.0, not uiautomator 2.0 which works in conjunction with Android Instrumentation/Espresso.

I don’t believe Espresso has added built-in functionality for capturing screenshots. However, if you take a look at the official AWS Device Farm Sample App for Android, there is a helper class ScreenShot.java that you should be able to use directly from your Espresso tests.

Hope that helps!

Best,
Andrew @ AWS Device Farm

Answered By – ahawker

Leave a Comment