Detox test hanging on device.launchApp command in Release configuration android

Created on 9 Aug 2019  ·  9Comments  ·  Source: wix/Detox

Describe the bug
When I run detox test -c android.emu.release the app installs on the emulator and appears to launch when looking at the emulator but in the logs I see it gets stuck at the device.launchApp command. The test then times out. detox test -c android.emu.debug is working well.

To Reproduce

  • [x] I have tested this issue on the latest Detox release and it still reproduces

This is the first time I have tried running detox on android so is not a regression for me. I set up exactly as in provided docs. detox build -c android.emu.release is successful and I can see the required apk files in the correct folders.

      "android.emu.debug": {
        "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
        "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
        "type": "android.emulator",
        "name": "Pixel_2_API_29"
      },
      "android.emu.release": {
        "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
        "build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
        "type": "android.emulator",
        "name": "Pixel_2_API_29"
      }
  1. detox build -c android.emu.release
  2. detox test -c android.emu.release

I have tried on Pixel_2_API_29 and Nexus_6_API_28 emulators and on a real attached device.

init.js

const detox = require('detox');
const config = require('../../../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');

// Set the default timeout
jest.setTimeout(120000);
jasmine.getEnv().addReporter(adapter);

// This takes care of generating status logs on a per-spec basis. By default, jest only reports at file-level.
// This is strictly optional.
jasmine.getEnv().addReporter(specReporter);

beforeAll(async () => {
  await detox.init(config);
});

beforeEach(async () => {
  await adapter.beforeEach();
});

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

Test:

  it('should successfully sign up user with phone number', async () => {
    await device.launchApp();
  });

Expected behavior
The tests should run as they do in debug mode and on iOS.

Environment (please complete the following information):

  • Detox: 14.0.1
  • React Native: 0.59.4
  • Node: 12.6.0
  • Device: MacBook Pro
  • OS: MacOS Mojave 10.14.5

    • Jest: 24.5.0

Device and Verbose Detox Logs

detox[31936] INFO:  [DetoxServer.js] server listening on localhost:51839...
detox[31936] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:51839
detox[31936] TRACE: [AsyncWebSocket.js/WEBSOCKET_SEND] {"type":"login","params":{"sessionId":"912056cf-c6f0-7a10-b7e7-63bdcc9b734a","role":"tester"},"messageId":0}
detox[31936] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=912056cf-c6f0-7a10-b7e7-63bdcc9b734a
detox[31936] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=912056cf-c6f0-7a10-b7e7-63bdcc9b734a
detox[31936] TRACE: [AsyncWebSocket.js/WEBSOCKET_MESSAGE] {"type":"loginSuccess","params":{"sessionId":"912056cf-c6f0-7a10-b7e7-63bdcc9b734a","role":"tester"},"messageId":0}

detox[31936] DEBUG: [exec.js/EXEC_CMD, #0] /Users/lydiagolland/Library/Android/sdk/emulator/emulator -list-avds --verbose
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #0] Nexus_6_API_28
Pixel_2_API_29

detox[31936] DEBUG: [exec.js/EXEC_CMD, #1] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb  devices
detox[31936] DEBUG: [exec.js/EXEC_SUCCESS, #1] List of devices attached
FPMNW18726002003    device
emulator-5554   device
emulator-5556   device


detox[31936] TRACE: [EmulatorTelnet.js/TELNET_CONNECTING] port: 5554, host: localhost
detox[31936] TRACE: [EmulatorTelnet.js/TELNET_CONNECTING] port: 5556, host: localhost
detox[31936] DEBUG: [exec.js/EXEC_CMD, #2] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "getprop dev.bootcomplete"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #2] 1

detox[31936] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBootDevice({ coldBoot: false, deviceId: 'emulator-5556' })
detox[31936] DEBUG: [exec.js/EXEC_CMD, #3] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "getprop ro.build.version.sdk"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #3] 28

detox[31936] DEBUG: [exec.js/EXEC_CMD, #4] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "dumpsys power | grep \"^[ ]*m[UW].*=\""
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #4]   mWakefulness=Awake
  mWakefulnessChanging=false
  mWakeLockSummary=0x0
  mUserActivitySummary=0x1
  mWakeUpWhenPluggedOrUnpluggedConfig=false
  mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig=false
  mUserActivityTimeoutOverrideFromWindowManager=-1
  mUserInactiveOverrideFromWindowManager=false

detox[31936] DEBUG: [exec.js/EXEC_CMD, #5] /Users/lydiagolland/Library/Android/sdk/build-tools/29.0.1/aapt dump badging "/Users/lydiagolland/Projects/wingsy-rn-poc/packages/mobile/android/app/build/outputs/apk/release/app-release.apk" | grep -e "package: name="
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #5] package: name='com.XXX' versionCode='1' versionName='1.0.4' platformBuildVersionName='1.0.4' compileSdkVersion='28' compileSdkVersionCodename='9'

detox[31936] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeUninstallApp({ deviceId: 'emulator-5556', bundleId: 'com.XXX' })
detox[31936] DEBUG: [exec.js/EXEC_CMD, #6] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "pm list packages com.XXX"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #6] package:com.XXX.test
package:com.XXX

detox[31936] DEBUG: [exec.js/EXEC_CMD, #7] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 uninstall com.XXX
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #7] Success

detox[31936] DEBUG: [exec.js/EXEC_CMD, #8] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "pm list packages com.XXX.test"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #8] package:com.XXX.test

detox[31936] DEBUG: [exec.js/EXEC_CMD, #9] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 uninstall com.XXX.test
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #9] Success

detox[31936] DEBUG: [exec.js/EXEC_CMD, #10] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 install -r -g -t "/Users/lydiagolland/Projects/wingsy-rn-poc/packages/mobile/android/app/build/outputs/apk/release/app-release.apk"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #10] Performing Streamed Install
Success

detox[31936] DEBUG: [exec.js/EXEC_CMD, #11] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 install -r -g -t "/Users/lydiagolland/Projects/wingsy-rn-poc/packages/mobile/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #11] Performing Streamed Install
Success

detox[31936] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeTerminateApp({ deviceId: 'emulator-5556', bundleId: 'com.XXX' })
detox[31936] DEBUG: [exec.js/EXEC_CMD, #12] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "am force-stop com.XXX"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #12]
detox[31936] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeLaunchApp({ deviceId: 'emulator-5556',
  bundleId: 'com.XXX',
  launchArgs:
   { detoxServer: 'ws://localhost:51839',
     detoxSessionId: '912056cf-c6f0-7a10-b7e7-63bdcc9b734a' } })
detox[31936] DEBUG: [exec.js/EXEC_CMD, #13] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "date +\"%m-%d %T.000\""
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #13] 08-09 16:46:51.000

detox[31936] DEBUG: [exec.js/EXEC_CMD, #14] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "pm list instrumentation"
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #14] instrumentation:com.XXX.test/androidx.test.runner.AndroidJUnitRunner (target=com.XXX)
instrumentation:org.chromium.webview_shell/.WebViewLayoutTestRunner (target=org.chromium.webview_shell)

detox[31936] DEBUG: [exec.js/SPAWN_CMD, #15] [pid=31963] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell am instrument -w -r -e detoxServer ws://localhost:51839 -e detoxSessionId 912056cf-c6f0-7a10-b7e7-63bdcc9b734a -e debug ZmFsc2U= com.XXX.test/androidx.test.runner.AndroidJUnitRunner
detox[31936] TRACE: [exec.js/SPAWN_STDOUT, #15] INSTRUMENTATION_STATUS: class=com.XXX.DetoxTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.XXX.DetoxTest:
INSTRUMENTATION_STATUS: test=runDetoxTests

detox[31936] TRACE: [exec.js/SPAWN_STDOUT, #15] INSTRUMENTATION_STATUS_CODE: 1

detox[31936] DEBUG: [exec.js/EXEC_CMD, #16] /Users/lydiagolland/Library/Android/sdk/platform-tools/adb -s emulator-5556 shell "ps | grep \"com\.XXX$\""
detox[31936] TRACE: [exec.js/EXEC_SUCCESS, #16] u0_a99        7107  1791 1471508 134216 0                   0 S com.XXX

detox[7107] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onLaunchApp({ deviceId: 'emulator-5556',
  bundleId: 'com.XXX',
  launchArgs:
   { detoxServer: 'ws://localhost:51839',
     detoxSessionId: '912056cf-c6f0-7a10-b7e7-63bdcc9b734a' },
  pid: 7107 })
detox[31936] TRACE: [AsyncWebSocket.js/WEBSOCKET_SEND] {"type":"isReady","params":{},"messageId":-1000}
detox[31936] TRACE: [DetoxServer.js/MESSAGE] role=tester action=isReady (sessionId=912056cf-c6f0-7a10-b7e7-63bdcc9b734a)
detox[31936] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=912056cf-c6f0-7a10-b7e7-63bdcc9b734a)
Example: should successfully sign up user with phone number
Example: should successfully sign up user with phone number [FAIL]
Example: should successfully sign up user with facebook
Example: should successfully sign up user with facebook [FAIL]

 FAIL  packages/mobile/e2e/tests/onboarding.spec.js (121.196s)
  Example
    ✕ should successfully sign up user with phone number (18ms)
    ✕ should successfully sign up user with facebook (3ms)

  ● Example › should successfully sign up user with phone number

    Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.

      at mapper (../../../node_modules/@jest/core/node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● Example › should successfully sign up user with phone number

    TypeError: _detox.device.launchApp is not a function

      58 |
      59 |   it('should successfully sign up user with phone number', async () => {
    > 60 |     await device.launchApp();
         |                  ^

      at launchApp (tests/onboarding.spec.js:60:18)
      at tryCatch (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)
      at Generator.prototype.(anonymous function) [as next] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at tryCatch (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at invoke (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:20)
      at ../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:11
      at callInvokeWithMethodAndArg (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:16)
      at AsyncIterator.enqueue (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at Object.<anonymous>.exports.async (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:14)
      at Object._callee (tests/onboarding.spec.js:59:60)

  ● Example › should successfully sign up user with facebook

    Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.

      at mapper (../../../node_modules/@jest/core/node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● Example › should successfully sign up user with facebook

    ReferenceError: element is not defined

      50 |   };
      51 |
    > 52 |   const continueWithFacebook = async () => {
         |                                ^
      53 |     await element(by.text('Log in / Sign up')).tap();
      54 |     await element(by.text('Continue with Facebook')).tap();
      55 |     await expect(element(by.text('Welcome Lydia!'))).toBeVisible();

      at continueWithFacebook$ (tests/onboarding.spec.js:52:32)
      at tryCatch (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)
      at Generator.prototype.(anonymous function) [as next] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at tryCatch (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at invoke (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:20)
      at ../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:11
      at callInvokeWithMethodAndArg (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:16)
      at AsyncIterator.enqueue (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at Object.<anonymous>.exports.async (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:14)
      at continueWithFacebook (tests/onboarding.spec.js:52:32)
      at continueWithFacebook (tests/onboarding.spec.js:69:11)
      at tryCatch (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (../../../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
triagbug android

Most helpful comment

I am seeing app hanging on launch for both iOS and Android with RN 0.60.4

All 9 comments

I am seeing app hanging on launch for both iOS and Android with RN 0.60.4

Hi, out of interest what happens if you try downgrading to v12 as in #1545

@henrymoulton Thanks for your suggestion but sadly it doesn't work on 12.11.3 either, also my issue is only on android

Sifted through the logs and figured this out (for my app, anyway). In my case, I have a few different build configs (aside from debug and release). One is called releaseStaging, which is basically just as it sounds: A release build but with some internal configs for my organization's staging version of the app.

In AndroidManifest.xml I have:

<application
    ...
    android:usesCleartextTraffic="${uses_clear_text_traffic}"

And in app/build.gradle:

buildTypes {
    ...
    releaseStaging {
        ...
        manifestPlaceholders = [
            uses_clear_text_traffic: "true",
        ]
    }
}

Before, it was set to uses_clear_text_traffic: "true". This all makes sense because, at the end of the day, the local detox server.... needs to communicate with the app. Shaking my head at myself for taking so long to come to this conclusion, but happy to be on my way.

It's important to note that for a TRUE release build, you will definitely want uses_clear_text_traffic: "true" (unless you're being forced to make http requests or something), so I'd recommend setting up a different buildConfig for, at the very least, testing a build made for release.

Hope it helps!

Thanks for your response @wkoutre. I tried adding uses_clear_text_traffic: "true" to my main manifest and doing a build to test but no difference for me unfortunately.

me too, Anyone found the solution ? @LydGol90

@LydGol90 still running Android test in debug mode?

@henrymoulton Yeah, not really had anymore time to look into it recently. I am updating react native to 0.61.1 so then might try updating detox and having another go when I have the time

Update: No luck upgrading RN

I have managed to solve this issue. Turns out it was related to these two issues: https://github.com/wix/Detox/issues/1297, https://github.com/wix/Detox/issues/1450.

If you set the targetSdkVersion to 27 it all works fine 🤷‍♀️

Will close this issue in favour of the above

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrobber picture jrobber  ·  3Comments

kceb picture kceb  ·  4Comments

rengarima picture rengarima  ·  4Comments

brunobar79 picture brunobar79  ·  4Comments

carlosalmonte04 picture carlosalmonte04  ·  4Comments