Zonily Jame
Zonily Jame

Reputation: 5359

Detox build successful but detox test fails

Following the setup provided by Detox on adding Android, the command below that builds detox works fine with no problems

detox build -c android.emu.debug

Now for the setup on the Package.json file, I'm sure the directories are being provided correctly

"android.emu.debug": {
  "binaryPath": "../OUR-APP-NAME/app/build/outputs/apk/androidTest/dev/debug/app-dev-debug-androidTest.apk",
  "build": "cd ../OUR-APP-NAME/ && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ../OUR-APP-NAME-TESTS",
  "type": "android.emulator",
  "name": "Pixel_2_XL_API_26"
},

For some reason running detox test doesn't work

 detox test -c android.emu.debug

It throws the error message

Error: '/Users/z/Projects/company-projects/OUR-APP-NAME/app/build/outputs/apk/androidTest/androidTest/devDebug/androidTest/app-dev-debug-androidTest-androidTest.apk' could not be found, did you run './gradlew assembleAndroidTest' ?

...... 

detox[29702] ERROR: [cli.js] Error: Command failed: node_modules/.bin/mocha --opts e2e/mocha.opts --configuration android.emu.debug --loglevel verbose --grep :ios: --invert --artifacts-location "artifacts/android.emu.debug.2019-11-20 09-54-23Z" "e2e"

I've noticed that on the first error message the directory being supplied by Detox is a mistake so I tried the following

But to no avail I haven't been able to make it work, I'm currently lost.

Notes: - I'm running Detox for a Native Android application - Our Detox setup works for our Native iOS application - We're using the Detox 14.4.1

Upvotes: 4

Views: 3297

Answers (4)

user23366752
user23366752

Reputation: 1

For Googlers using expo & facing this issue -

I faced this issue before and solved it by following the documentation here https://docs.expo.dev/build-reference/e2e-tests/

  1. Navigate to your project directory and run expo install @config-plugins/detox

  2. Add the following into app.json.

    { "expo": { // ... "plugins": ["@config-plugins/detox"] } }

This plugin will allow detox & expo to work together and resolves the path issue without needing to manually adjust the paths in the detox configs.

Upvotes: 0

Tal Biton
Tal Biton

Reputation: 21

Well, I was struggling a lot with Detox for the last 2 weeks, I think you can try firstly reinstall Detox according to the docs, and check that you can see with your eyes in the browser/finder the builds (apk) and that they have the right filename they should have I find my config a little bit different from yours so you can maybe try it:

"android": {
  "type": "android.apk",
  "binaryPath": "./android/app/build/outputs/apk/debug/app-debug.apk",
  "build": "cd android && ./gradlew app:assembleDebug app:assembleAndroidTest -DtestBuildType=debug && cd ..",
}

Upvotes: 0

Freewalker
Freewalker

Reputation: 7335

Detox "customizes" the APK name in binaryPath, so if you specify the exact path to your Detox binary, it won't work.

(This mutation of the filename happens in Detox's internal getTestApkPath function, and seems pretty nonintuitive to me).

To specify the exact path to the APK Detox should use, you can use use testBinaryPath to override the setting in binaryPath.

Edit: To clarify, Detox needs access to two APK files, the app APK and the test APK. binaryPath should point to the app APK (the normal one you run on your emulator) and, if Detox can't find your test APK based on binaryPath, testBinaryPath should point to your test APK.

Upvotes: 2

Fedir Ushakov
Fedir Ushakov

Reputation: 11

I've also faced this issue, to resolve it, remove androidTest from both path and file name of binaryPath resulting in something like android/app/build/outputs/apk/debug/app-debug.apk. Detox will add those under the hood.

Upvotes: 1

Related Questions