Espresso Test Recorder in Android Studio turns a short manual pass through an Android screen into an instrumented Espresso test class. It is most useful when a developer needs a quick starting point for a UI test before tightening the generated selectors, assertions, and naming.
The recorder launches the selected app on an emulator or device, logs tap and type actions, and lets you add assertions from a captured view hierarchy. When the recording is saved, Android Studio writes the test into the app module's androidTest source set and can add missing Espresso dependencies to the module build file.
Use a focused screen that already opens successfully on the test device. Turn off device animations first, keep the recorded journey short, and run the generated class immediately so brittle text, generated names, or missing assertions are found before the test is committed.
The app must already build and install on the selected emulator or device.
Related: How to configure an Android project for Espresso
Animations can change timing and view state while Espresso records or replays interactions.
Related: How to disable Android animations for Espresso tests
Run -> Record Espresso Test
Android Studio builds, installs, and launches the app before the Record Your Test window becomes interactive. If a Waiting for Debugger or Attaching Debugger dialog appears on the device, wait for it to close instead of force-closing the app.
The Record Your Test window should log actions such as taps and typed text in the order they were performed.
The Screen Capture dialog closes after Espresso Test Recorder captures the current hierarchy.
The selected view is highlighted before the assertion is saved.
Use text is for exact text checks, exists when the view should be present, and does not exist when the view should be absent.
If Missing Espresso dependencies appears, click Yes only after confirming the project should let Android Studio add the required Espresso dependencies to the module build file.
app/src/androidTest/java/com/example/shop/CheckoutRecorderTest.java
The exact package path follows the launched activity package and the project's instrumentation test root.
Right-click the test class or method, click Run, choose the deployment target, and watch the Run window for the test result.
Related: How to run Espresso tests in Android Studio
$ ./gradlew :app:connectedDebugAndroidTest Task :app:connectedDebugAndroidTest Starting 1 tests on Pixel_8_API_35 CheckoutRecorderTest.recordedCheckoutFlow[Pixel_8_API_35] PASSED BUILD SUCCESSFUL in 38s
Replace :app and Debug with the module and variant used by the project. Refine generated matchers and assertions as normal Espresso code before expanding the test suite.
Related: How to run Espresso tests locally
Related: How to stabilize selectors in Espresso tests