0

When a test fails, I would like to take a screenshot and have it as part of my test report. Espresso auto generates a HTML report, and it would be nice if my screenshots would be stored there. I am currently able to use the UiAutomator library to save a screenshot to the Android device, but that's not very helpful because pulling files off a device is a pain. Is there better way to do this? Does Espresso have a built in function for this?

My UiAutomator screenshot code looks like this, and I call it in my after test teardown:

File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/screenshots/" + getTargetContext().getPackageName());
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
String filename = "junk" + ".png";
device.takeScreenshot(new File(path, filename));

If this is totally wrong and I should be going about it another way, please let me know.

Zeek Aran
  • 523
  • 4
  • 18
  • There is [a beta Espresso screenshot API](https://stackoverflow.com/a/49009120/115145), but it also stores the screenshots on the device. AFAIK you need an external tool, such as Spoon, to automate pulling down the screenshots. – CommonsWare May 02 '18 at 18:45
  • That's unfortunate. I wanted to avoid Spoon. Where have you seen that Spoon saves screenshots for the Espresso report? – Zeek Aran May 02 '18 at 19:10
  • Spoon [saves screenshots when you ask for them](https://github.com/square/spoon#screenshots) -- it's not tied to Espresso specifically. – CommonsWare May 02 '18 at 19:16

0 Answers0