Skip to content

Getting started with e2e tests

Dmitry Usik edited this page Apr 3, 2022 · 8 revisions

Introduction

Detox is an end-to-end framework for mobile apps developed by Wix, one of the top contributors to the React Native community.

Detox setup

To start with Detox you need to configure its ecosystem. This is well documented in the Step 1: Environment Setup section.

Detox setup - iOS

The next step is to configure the native platforms. Let's start with the iOS platform. This is also well documented on the official page. Please, follow the instructions step by step.

Detox setup - Android

If you would like to run the e2e tests on the Android platform too, then you need to configure it following the official page. These instructions are pretty long, but you might not need to follow each step.

Config file

Let's overview the config.json file:

{
  "ios": {
    "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/ReactNativeBaseProject.app",
    "build": "xcodebuild -workspace ios/ReactNativeBaseProject.xcworkspace -scheme ReactNativeBaseProject -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
    "device": {
      "type": "iPhone 13",
      "UDID": "4B5D647D-5972-413A-AE44-F45F422F39C0"
    }
  },
  "android": {
    "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
    "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug",
    "device": {
      "avdName": "Pixel_4_API_30_1"
    }
  }
}
  • ios.binaryPath - the path of the local artifact.
  • ios.build - the command to build the local artifact.
  • ios.device.type - the name of the simulator the tests will be run on.
  • ios.device.UDID - the UDID of the simulator that will be opened before the tests are run.
  • android.binaryPath - the path of the local artifact.
  • android.build - the command to build the local artifact.
  • android.device.avdName - the name of the emulator the tests will be run on.

How to check the UDID of the iOS simulator

  1. Open XCode.
  2. Go to Window -> Devices and Simulators.
Screenshot 2022-02-21 at 17 34 58
  1. Select the simulator you would like to open and copy its UDID.
Screenshot 2022-02-21 at 17 35 13

How to check the name of the Android emulator

  1. Open Android Studio.
  2. Go to Tools -> AVD Manager.
Screenshot 2022-02-21 at 17 36 49
  1. Check the name of the emulator you would like to open (or create a new one). Note: When you set the name of the emulator you should change all the spaces with the bottom dashes. For instance, Pixel 4 API 30 -> Pixel_4_API_30.
Screenshot 2022-02-21 at 17 37 08

Local

You can configure different options when you're building the artifacts locally:

  • shouldRebuildApp (no by default) - the option that decides whether the application will be re-built or not. You have to rebuild the artifacts only if you change some parts of the code.
  • shouldOpenSimulator (yes by default) - relevant only for the iOS platform. The option that decides if the simulator will be opened. It's possible to run the tests without the opened simulator on the iOS platform.
Screenshot 2022-04-03 at 16 03 46

CI

There is also a bunch of scripts specifically for the CI environment. They don't interact with the user and use the remote build system.

Scripts

Script Description
e2e:ios Runs the e2e tests on the iOS platform with the interaction.
e2e:android Runs the e2e tests on the Android platform with the interaction.
e2e Runs the e2e tests on both platforms with the interaction.
e2e:ios:ci Runs the e2e tests on the iOS platform without the interaction.
e2e:android:ci Runs the e2e tests on the Android platform without the interaction.
e2e:ci Runs the e2e tests on both platforms without the interaction.

Clone this wiki locally