Take a screenshot on Android Espresso Test Failure

This tutorial will show you how to add a test rule to your Espresso Android automation, when a test fails it takes a screenshot.

  1. Create a new folder in androidTest/utility/screenshot
  2. Add these two files EspressoScreenshot.kt and ScreenshotTestRule.kt to the folder (shown below).
  3. Add write permission to Manifest, to save the screenshot file in the device.