Detox run tests (e2e tesing) run issue

I built the APK with Detox build and configured my .detoxrc.js file correctly. In the e2e directory, I wrote my first test file:

describe('Example', () => {
  beforeAll(async () => {
    console.log('Starting beforeAll hook...');
    await device.launchApp({
      newInstance: true,
    });
    console.log('App should be launched now.');
  });

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

  it('this is test', async () => {
    console.log('Running the test...');
  });
});

However when i ran my tests with detox test, the app never launches and the test gets stuck at device.launchApp() , meaning the second log statement (β€œApp should be launched now.”) is never printed. Instead, it shows a timeout error (120000).

I am using:

  • β€œdetox”: β€œ^20.21.0”
  • β€œjest”: β€œ^29.7.0”

its my .detoxrc.js file:

/** @type {Detox.DetoxConfig} */
module.exports = {
  testRunner: {
    args: {
      $0: 'jest',
      config: 'e2e/jest.config.js',
    },
    jest: {
      setupTimeout: 300000,
    },
  },
  apps: {
    'android.debug': {
      type: 'android.apk',
      binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
      build: 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
      reversePorts: [8081],
      testBinaryPath: 'android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk',
    },
    'android.release': {
      type: 'android.apk',
      binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
      build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
      testBinaryPath:
        'android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk',
    },
  },
  devices: {
    emulator: {
      type: 'android.emulator',
      device: {
        avdName: 'Pixel_7a_API_30',
      },
    },
  },
  configurations: {
    'android.emu.debug': {
      device: 'emulator',
      app: 'android.debug',
    },
    'android.emu.release': {
      device: 'emulator',
      app: 'android.release',
    },
  },
}

i have tried with sdk v34 and 30 with different devices in android studio emulators

Can anyone help me resolve this issue?

Hi @aprin1991 ,
It could be the reversePorts with port 8081 that blocks the tests. Can you run Detox tests on your local machine?
Best regards,
Silvercast

hi @silvercast.nguyen
thanks for your answer
currently im running it locally on my emulator , you mean port 8081 is blocking the tests? it needs to change the url ??

Best
Hamed

You may need to add adb reverse tcp:8081 tcp:8081 before starting Detox tests. Here are similar issues related to yours and they pointed to missing setup.

Would be nice if you share the build url you had issue with support access enabled for us to look at. Enabling the Bitrise Support Access for your app - Bitrise Docs

I followed the instructions as suggested by the links and performed the following steps:

  1. Ran the Detox build command.
  2. Started the React Native packager using npx react-native start.
  3. Opened the emulator and executed adb reverse tcp:8081 tcp:8081.
  4. Ran the Detox test command.

However, I’m still encountering an issue: thrown: "Exceeded timeout of 120000 ms for a hook." The app is not launching as expected.

Thanks for your input. Can you share a build url with support access enabled? Let’s continue your issue in a support request https://support.bitrise.io/hc/en-us/requests/new to that your build and logs can be reviewed in a secure way.

1 Like