DetoxRuntimeError: Detox can't seem to connect to the test app(s)! - Android only

Viewed 172

I use Detox automation tool for bare React Native project. Everything works perfectly on iOS, but when I run tests on Android I get following errors:

DetoxRuntimeError: Detox can't seem to connect to the test app(s)! HINT: Have you forgotten to call 'device.launchApp()' in the beginning of your test? Refer to our troubleshooting guide, for full details: https://wix.github.io/Detox/docs/troubleshooting/running-tests#tests-execution-hangs

and

DetoxRuntimeError: The pending request #9 ("invoke") has been rejected due to the following error: The app has unexpectedly disconnected from Detox server.

Some tests have green status. Tests are run in parallel on multiple emulators.


Below is my configuration for detox:

/detoxrc.json

{
 "testRunner": "jest",
 "runnerConfig": "e2e/config.js",
 "skipLegacyWorkersInjection": true,
 "apps": {
  "ios": {
    "type": "ios.app",
    "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/ProjectName.app",
    "build": "RN_SRC_EXT=e2e.js xcodebuild -workspace ios/ProjectName.xcworkspace -scheme ProjectName -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -UseModernBuildSystem=YES -destination 'platform=iOS Simulator,name=iPhone 11'"
  },
  "android": {
    "type": "android.apk",
    "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
    "testBinaryPath": "android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
    "build": "cd android && RN_SRC_EXT=e2e.js ./gradlew clean assembleRelease assembleAndroidTest -DtestBuildType=release && cd .."
  }
},
"devices": {
  "simulator": {
    "type": "ios.simulator",
    "device": {
      "type": "iPhone 11"
    }
  },
  "emulator": {
    "type": "android.emulator",
    "device": {
      "avdName": "Pixel_XL"
    }
  }
},
"configurations": {
  "ios": {
    "device": "simulator",
    "app": "ios"
  },
  "android": {
    "device": "emulator",
    "app": "android"
  }
 }
}

/e2e/config.js

module.exports = {
preset: 'react-native',
setupFilesAfterEnv: ["./init.js"],
setupFiles: [
  "<rootDir>/../node_modules/react-native/jest/setup.js",
],
testPathIgnorePatterns: ["/node_modules/"],
testMatch: [
  "<rootDir>/*.e2e.js"
],
transformIgnorePatterns: [
  'node_modules/(?!(jest-)?@react-native|react-native|@react-native-community|@react-navigation)'
  ],
 };

/e2e/init.js - File which is run after environment setup

import detox from 'detox';
import packageFile from '../package.json';
const detoxConfig = packageFile.detox;

jest.setTimeout(120000);

beforeAll(async () => {
   await detox.init(detoxConfig, { launchApp: false });
   await device.launchApp();
});

afterAll(async () => {
   await detox.cleanup();
});

beforeEach(async () => {
   await device.reloadReactNative();
});

and test files looks like similar to this one:

describe('some-screen-description', () => {
    beforeEach(async () => {
        await logInPage.tapLogInButton();
    });

   it('description', async () => {
        await nextScreen.performAction();
   });

});

/package.json

"detox": {
    "test-runner": "jest",
    "runner-config": "e2e/config.js"
  }

I use following version of detox: "detox": "^19.6.9".

I use Macbook Pro with M1 processor. Any hints recommended.

Can anyone confirm that it can be problem with installing both APK and test APK ? I don't know how check that both are installed.

1 Answers

in your init.js inside your beforeAll hook, what's the first line doing? Did you try removing that line?

Regarding your apks being installed, if they weren't installed properly, you'd get a different error message(something like the apks couldn't be found, did you run detox build beofre it?). And also looking at your config file + detox build command I'm sure that the apks were built and they're in the right place. To double check you can go to your android's build output directory(see the paths mentioned in binaryPath and testBinaryPath inside your detox config)

Related