This tutorial will show you how to add a test rule to your Espresso Android automation, when a test fails it takes a screenshot.
- Create a new folder in androidTest/utility/screenshot
- Add these two files EspressoScreenshot.kt and ScreenshotTestRule.kt to the folder (shown below).
- Add write permission to Manifest, to save the screenshot file in the device.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />