Detox: Detox hangs when running android

Hi, First of all, I really like Detox, so thank you for this library!

Describe the bug I’m trying to run Detox tests on react native android device in debug mode.

The tests aren’t running, and detox trace shows "CANNOT_FORWARD:

If in different terminal I start react-native bundle and press “R” for reloading it, the tests start to run.

To Reproduce

  1. I follow the android environment setUp 2.write tests 3.run detox on android 4.the device open with the app 5.the tests hangs

Expected behavior Detox start running over the tests

Device and Verbose Detox Logs

detox[97978] DEBUG: [exec.js/EXEC_CMD, #21] "/Android/sdk/platform-tools/adb" -s emulator-17722 shell "date +\"%m-%d %T.000\""
detox[97978] DEBUG: [exec.js/EXEC_CMD, #22] "/Android/sdk/platform-tools/adb" -s emulator-17722 reverse tcp:64867 tcp:64867
detox[97978] DEBUG: [exec.js/EXEC_CMD, #23] "/Android/sdk/platform-tools/adb" -s emulator-17722 shell "pm list instrumentation"
detox[97978] DEBUG: [exec.js/SPAWN_CMD, #24] [pid=98010] /Android/sdk/platform-tools/adb -s emulator-17722 shell am instrument -w -r -e detoxServer ws://localhost:64867 -e detoxSessionId 2f0e4128-30e3-0737-4ac0-74907e3abed9 -e debug false com.aaa.myWireless.test/androidx.test.runner.AndroidJUnitRunner
detox[97978] DEBUG: [exec.js/EXEC_CMD, #25] "/Android/sdk/platform-tools/adb" -s emulator-17722 shell "ps | grep \"com\.aaa\.myWireless$\""
detox[97978] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=2f0e4128-30e3-0737-4ac0-74907e3abed9)

I tried it on this simulators:

Screen Shot 2020-10-15 at 10 11 34 Screen Shot 2020-10-15 at 14 38 21

Environment (please complete the following information):

  • Detox:“^17.10.0”
  • React Native:“0.61.5”
  • Node:v14.8.0
  • Device:“Pixel_3a_XL_API_29”
  • OS: MacOS
  • Test-runner (select one): jest-circus

I tried it too :

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 26

Most upvoted comments

In debug mode the bundle is usually loaded from the local server, as the app loads. Is it possible that it is rather big, then? In any case - as the message says, you can try to provide a longer time-out to DetoxTest.runTests() using a custom configuration. Please revisit your implementation of DetoxTest.java and lmk.

@d4vidi thanks, this tip helped me. Here is full DetoxTest.java code which solved com.wix.detox.common.DetoxErrors$DetoxRuntimeException: Waited for the new RN-context for too long! (60 seconds) for me.

import com.wix.detox.Detox;
import com.wix.detox.config.DetoxConfig;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

@RunWith(AndroidJUnit4.class)
public class DetoxTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);

    @Test
    public void runDetoxTests() {
        DetoxConfig detoxConfig = new DetoxConfig();
        detoxConfig.idlePolicyConfig.masterTimeoutSec = 500;
        detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 500;
        detoxConfig.rnContextLoadTimeoutSec = 500;
        Detox.runTests(mActivityRule, detoxConfig);
    }
}

@barak109 any updates? Something is obviously keeping the app from loading the JS code. Need to find what it is and whether it’s a problem in Detox.

@d4vidi Unfortunately no, we tried for a month to understand the problem there(figure out why the app doesn’t load the JS code) but we didn’t find any solution from our side.

+1

same here

I have the same problem, can not run tests without pressing the reload bundle

Hi guys, We found out a solution, add inside your android first activity that line:

getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();

Hi @barak109 would you mind sharing the file where you used this code? We have the same problem with Android, it just seems to hang.

Hi guys, We found out a solution, add inside your android first activity that line:

getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();

Same here