Running Detox on Android with detached Expokit app

Has anyone had any success with using Detox in a detached Expokit app?

  1. I created a boilerplate app with expo-cli --version: 2.10.1 on node --version: v8.15.0.
  2. I followed steps relevant to Expo blog post about Detox
  3. I followed the instructions in the Detox docs except for “Create Android Test Class” which I needed to change to be under host.exp.exponent or otherwise I got errors about “symbol cannot be found” for MainActivity.

Detox was able to successfully build the app, but when I run the tests with detox test -c android.emu.debug the app crashes, with the following error in logcat:

02-12 10:16:58.954  5299  5381 E AndroidRuntime: java.lang.ClassCastException: host.exp.exponent.MainApplication cannot be cast to com.facebook.react.ReactApplication
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.ReactNativeSupport.getInstanceManager(ReactNativeSupport.java:63)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.ReactNativeSupport.waitForReactNativeLoad(ReactNativeSupport.java:117)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.ReactNativeCompat.waitForReactNativeLoad(ReactNativeCompat.java:33)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.DetoxManager.initReactNativeIfNeeded(DetoxManager.java:226)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.DetoxManager.start(DetoxManager.java:74)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.Detox$1$1.run(Detox.java:133)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:790)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:164)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at com.wix.detox.Detox$1.run(Detox.java:136)
02-12 10:16:58.954  5299  5381 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:764)

I don’t know any Java, so I’m not sure where to go from here. The test app does not have any changes from the boilerplate ejected expokit app:

https://github.com/gmaclennan/mapeo-expo

1 Like

It’s unfortunate that expo doesn’t have a good story with end 2 end tests

is there any solution found to use Detox with React Native app with Ejected Expo

Curiously, the original Detox blog posts never mentions Android anywhere! Has anyone confirmed it works with the Expo Android client? If so, you could use the instructions for running the Expo client with the Bare workflow*** (https://docs.expo.io/versions/v36.0.0/bare/using-expo-client/), then run your detox tests in the Expo client.

*** I found to make this work with ExpoKit I also had to set "isDetached": false in app.json.

Could you provide some examples of your implementation? I’ve tried using the bare workflow with Detox and it is crashing for Android app right after bundling and start running the tests. I’ve already tried the clearTextTraffic fixes but nothing, it seems to me Detox is not able to connect to the Expo server in the detached app. Many thanks in advanced.