Detox is a gray box end-to-end testing and automation framework for mobile apps. This PR helps to learn how to setup and use detox in simple project.
NOTE: This project is built on Expo and use jest as the test runner
There are 4 branches in this repository. You can choose based on your need.
master- Contains only the project, without detox.
- Expo managed flow
- TODO: eject from expo, run
detox init, config detox, setup android, make end-to-end test
setup- Contains project with detox and jest-circus.
- Bare workflow
- Detox runs well in ios
- TODO: setup android, make end-to-end test
setup-android- Contains project with detox and jest-circus.
- Bare workflow.
- Android detox setup is added.
- Detox runs well in android and ios
- TODO: make end-to-end test
test- Contains project with detox and jest-circus
- Detox runs well in android and ios
- Test only passed on Android (intentional)
detox101-preview.mp4
- Homebrew
- Simulator (ios) and Emulator (android)
- Node.js
- Yarn (optional, but might need to add some additional packages if you use npm)
- Detox-cli
- Expo-cli (optional if you only want to run the test, then it's fine)
Here are some commands you might need. Check the full documentation here
- Node
brew install node - Yarn
npm install -g yarn - Detox-cli
yarn global add detox-cli - Expo-cli
yarn global add expo-cli
You can follow the full instructions from react-native documentation or expo documentation
- Ensure the java version installed is jdk v 8 (1.8) or 11, as suggested in react native documentation
java --version //to check
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8 // to install jdk 8
- Add this setup in
.bask_profileor.zshenv
export ANDROID_HOME=$HOME/Library/Android/sdk
path=("$ANDROID_HOME/emulator" "$ANDROID_HOME/tools" "$ANDROID_HOME/tools/bin" "$ANDROID_HOME/platform-tools" "$path[@]")
- Open
Android Studioand create new AVD (Android Virtual Device) if you haven't.
- More options > AVD Manager > Create Virtual Device
- You can run the command below to clone the master branch
git clone https://github.com/carissacks/detox101.git
- Open the project using this command or you can open it manually
cd detox101 && code .
- Follow these instructions below to clone the other three branches
- Create new branch
git checkout -b <new-branch-name>
- Rebase from the repo
git pull origin <repo-branch-name> --rebase
- Don't forget to go back to master before cloning other branches
git checkout master
- Run this command in
detox101to install all packages needed in the project
yarn
You can choose the type of devices you want to run the end-to-end tests with.
- It is optional for the simulator, since we start with all types of devices
- However it is mandatory for the emulator, because your avd name is possible different than mine.
- Change the device type in
.detoxrc.json
"devices": {
"simulator": {
"type": "ios.simulator",
"device": {
"type": <iphone type>
}
},
"emulator": {
"type": "android.emulator",
"device": {
"avdName": <android type name>
}
}
},
NOTE: Doesn't work in master branch
- Install package for ios native code
npx pod-install
- If something went wrong, try checking the
command line toolsin xcode. xcode > preferences > locations > command line tools > should be filled with the xcode version
- Build the app for end-to-end test. -c stands for --configuration
detox build -c ios
- Run the test
detox test -c ios
- If
applesimutilsis missing, run these commands below to install. To see more, click here
brew tap wix/brew
brew install applesimutils
- Open simulator The end-to-end test might run but the simulator is not showing because it runs in headless mode. Run this command to open the simulator
open -a Simulator.app
NOTE: Doesn't work in master branch nor setup branch
- Build the app for end-to-end test. -c stands for --configuration
detox build -c android
- Run the test
detox test -c android
They said practice makes perfect! You can check the full documentations here for all the matchers, actions, and what to expect.
- Login Scene
- Empty field: Show "Tell me who you are."
- Wrong credentials or unregistered username: Show "Sorry, we have never met before"
- Right username with right credentials (name: detox101, password: 123): Navigate to Home Scene
- Home Scene
- Show "Welcome back, detox101"
- Login Scene
- Right username with right credentials:
- Could be one of the followings -format: name/password
- john/doe, rex orange/sunflower, simple/plan
- Navigate to Home Scene
- Right username with right credentials:
- Home Scene
- Show "Welcome back, {name}", depends on the username
- Find 'End of list'
- Sign out
- You need to re-run
detox buildafter changing the project code, otherwise the changes won't be updated on your test app. - Check the PRs to know more about the code and feel free to ask questions 😄