The React Native library for Android is currently not well setup for Espresso testing. There are two reasons for this:
- React Native doesn't provide proper test-id for Android
- Rendering React Native views is done async; React Native uses a Javascript thread and bridge. Therefore, the tests will have to wait on the views to become visible.
We use Spoon to take screenshots on each test. This achieved with the help of Spoon (link) and the spoon-gradle-plugin (link).
The examples in this repository are not for best practices, or have the purpose to test this app with Espresso, but they are only created to build a simple test set for Espresso.
To build an Espresso debug build and test app you need to execute the following
- Go to the root of this project
- Make sure you are using
yarn
version 1 - Run
yarn android.espresso
This will result in the following logs
╭─ …/Git/SwagLabsMobileApp
╰> yarn android.espresso
yarn run v1.22.4
$ yarn android.debug.build && cd android && ./gradlew assembleDebug && ./gradlew assembleAndroidTest
$ yarn react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
$ /Users/wimselles/Sauce/Git/SwagLabsMobileApp/node_modules/.bin/react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Loading dependency graph, done.
Loading dependency graph...info Writing bundle output to:, android/app/src/main/assets/index.android.bundle
info Done writing bundle output
info Copying 45 asset files
info Done copying assets
BUILD SUCCESSFUL in 42s
440 actionable tasks: 28 executed, 412 up-to-date
BUILD SUCCESSFUL in 30s
697 actionable tasks: 26 executed, 671 up-to-date
✨ Done in 80.17s.
Then you can find the debug-build in this ./android/app/build/outputs/apk/debug/
-
and the test app in this ./android/app/build/outputs/apk/androidTest/
-folder.
Follow the steps on the Sauce Labs Wiki to start running on Sauce Labs.