Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch on Android fails - DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action #908

Closed
leugimmai opened this issue Aug 29, 2018 · 23 comments

Comments

@leugimmai
Copy link

Description

Currently as it stands my app builds fine and launches like normal when running react-native run-android. It is when I try to run the detox test is that things fail. The app will launch on my device shortly there after it just hangs and eventually crashes. I did the initial set up with android, and ran the detox-cli to add the e2e folder with tests as well.

Steps to Reproduce

Running: detox test -c debug

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 8.2.3
  • React Native: 0.55
  • Node: 8.11.3
  • Device: Android - Pixel 2 -hardware device
  • Xcode: n.a
  • macOS: n.a
  • Windows: 10

Device and verbose Detox logs

package.json:
{ "name": "example", "version": "0.1.0", "private": true, "devDependencies": { "babel-preset-react-native-stage-0": "1.0.1", "jest": "22.4.3", "jest-react-native": "18.0.0", "react-test-renderer": "16.3.0-alpha.1" }, "scripts": { "start": "react-native start", "android": "react-native run-android", "ios": "react-native run-ios", "test": "jest" }, "jest": { "preset": "react-native" }, "dependencies": { "detox": "^8.2.3", "mobx": "4.3.0", "mobx-react": "5.1.2", "react": "16.4.1", "react-native": "0.55", "react-native-action-button": "2.8.4", "react-native-background-fetch": "2.4.3", "react-native-battery": "^0.1.15", "react-native-camera": "1.1.0", "react-native-device-info": "0.21.5", "react-native-dialog": "^5.1.0", "react-native-dropdownalert": "3.5.0", "react-native-elements": "0.19.1", "react-native-exception-handler": "https://[email protected]/samrenick/react-native-exception-handler.git", "react-native-geocoder": "0.5.0", "react-native-geolocation-service": "^1.1.0", "react-native-maps": "http://[email protected]/miguelquintana/react-native-maps.git", "react-native-navigation-actions": "1.0.4", "react-native-numeric-input": "1.3.1", "react-native-popup-menu": "0.13.2", "react-native-signature-capture": "https://[email protected]/cxrd/react-native-signature-capture.git", "react-native-simple-toast": "^0.0.8", "react-native-sound": "0.10.9", "react-native-sqlite-storage": "^3.3.6", "react-native-vector-icons": "4.6.0", "react-navigation": "2.6.2" }, "detox": { "configurations": { "debug": { "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk", "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..", "type": "android.attached", "name": "FA79E1A07174" }, "release": { "binaryPath": "android/app/build/outputs/apk/release/app-release.apk", "build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..", "type": "android.attached", "name": "FA79E1A07174" } }, "test-runner": "jest" } }

detox log:
`configuration="debug" loglevel="verbose" artifactsLocation="artifacts\debug.2018-08-29 20-37-01Z" node_modules.bin\jest e2e --config=e2e/config.json --maxWorkers=1 "--testNamePattern=^((?!:ios:).)$"
detox[67084] INFO: [DetoxServer.js] server listening on localhost:54130...
detox[67084] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:54130
detox[67084] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=c6ce6acb-85c4-87c1-84b1-9ebedcf6cc48
detox[67084] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=c6ce6acb-85c4-87c1-84b1-9ebedcf6cc48
detox[67084] DEBUG: [exec.js/EXEC_CMD, #0] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb devices
detox[67084] DEBUG: [exec.js/EXEC_CMD, #1] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell dumpsys power | findstr /R /C:"^[ ]m[UW].="
detox[67084] DEBUG: [exec.js/EXEC_CMD, #2] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\build-tools\28.0.0\aapt dump badging "C:\Users\miguel.quintana\Development\atether\android\app\build\outputs\apk\debug\app-debug.apk" | findstr /C:"package: name="
detox[67084] DEBUG: [exec.js/EXEC_CMD, #3] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 uninstall com.atether
detox[67084] DEBUG: [exec.js/EXEC_CMD, #4] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 uninstall com.atether.test
detox[67084] DEBUG: [exec.js/EXEC_CMD, #5] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell getprop ro.build.version.sdk
detox[67084] DEBUG: [exec.js/EXEC_CMD, #6] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 install -r -g C:\Users\miguel.quintana\Development\atether\android\app\build\outputs\apk\debug\app-debug.apk
detox[67084] DEBUG: [exec.js/EXEC_CMD, #7] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell getprop ro.build.version.sdk
detox[67084] DEBUG: [exec.js/EXEC_CMD, #8] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 install -r -g C:\Users\miguel.quintana\Development\atether\android\app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk
detox[67084] DEBUG: [exec.js/EXEC_CMD, #9] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell am force-stop com.atether
detox[67084] DEBUG: [exec.js/EXEC_CMD, #10] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell pm list instrumentation
detox[67084] DEBUG: [exec.js/SPAWN_CMD, #11] [pid=26888] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell am instrument -w -r "-e detoxServer ws://localhost:54130 -e detoxSessionId c6ce6acb-85c4-87c1-84b1-9ebedcf6cc48" -e debug false com.atether.test/android.support.test.runner.AndroidJUnitRunner
detox[67084] DEBUG: [exec.js/EXEC_CMD, #12] C:\Users\miguel.quintana\AppData\Local\Android\Sdk\platform-tools\adb -s FA79E1A07174 shell ps | findstr /R /C:"com.atether[ ]
$"
detox[67084] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=c6ce6acb-85c4-87c1-84b1-9ebedcf6cc48)

detox[44968] ERROR: [AsyncWebSocket.js/WEBSOCKET_ERROR] caught error: Error: connect ECONNREFUSED 127.0.0.1:55301
err: Error: connect ECONNREFUSED 127.0.0.1:55301
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
detox[44968] ERROR: [index.js/DETOX_INIT_ERROR]
{ Error: connect ECONNREFUSED 127.0.0.1:55301
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 55301,
type: 'error',
target:
WebSocket {
domain: null,
_events: { error: [Function: onerror] },
_eventsCount: 1,
_maxListeners: undefined,
_socket: null,
_ultron: null,
_closeReceived: false,
bytesReceived: 0,
readyState: 3,
supports: { binary: true },
extensions: null,
_binaryType: 'nodebuffer',
_isServer: false,
url: 'ws://localhost:55301',
protocolVersion: 13,
_closeTimer: null,
_closeCode: 1006 } }
(node:44968) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined
(node:44968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:44968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
child_process.js:644
throw err;
^

Error: Command failed: node_modules.bin\jest e2e --config=e2e/config.json --maxWorkers=1 "--testNamePattern=^((?!:ios:).)*$"
at checkExecSyncError (child_process.js:601:13)
at Object.execSync (child_process.js:641:13)
at runJest (C:\Users\miguel.quintana\Development\atether\node_modules\detox\local-cli\detox-test.js:154:6)
at run (C:\Users\miguel.quintana\Development\atether\node_modules\detox\local-cli\detox-test.js:85:7)
at Object. (C:\Users\miguel.quintana\Development\atether\node_modules\detox\local-cli\detox-test.js:217:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)`

@lvmtam
Copy link

lvmtam commented Sep 1, 2018

the same @leugimmai :(

@ZSeba
Copy link

ZSeba commented Sep 15, 2018

same problem here 😢 .
Detox: 9.0.1
React Native: 0.56
Node: 10.9.0
Device: iPhone 7 Plus (ios simulator)
Xcode: 9.4.1
macOS: High Sierra

@noomorph
Copy link
Collaborator

noomorph commented Sep 15, 2018

I'll take a look in the next few days, so basically you are telling that the combination of Windows 10 + hardware device + debug mode does not work on detox. I'll check that too and get back to you.

Also, could you bump your detox version to 9? Anyway AFAIR the 8th version does not support RN 0.55 on Android.

@noomorph noomorph self-assigned this Sep 15, 2018
@noomorph
Copy link
Collaborator

@leugimmai, could you submit crash details from adb logcat? @lvmtam, if you claim to have the same issue, you might send your crash log too.

@AntoineGrandchamp
Copy link

@noomorph I have the same problem.
Detox: 9.0.1
React Native: 0.56
Node: 8.11.1
Device: Pixel 2 api 27 (android virtual device)
macOS: High Sierra

Here is the crash detail from adb logcat :

E/AndroidRuntime: FATAL EXCEPTION: com.wix.detox.manager
    Process: com.classcraft.android.staging, PID: 7426
    java.lang.RuntimeException: waited a minute for the new reactContext
        at com.wix.detox.ReactNativeSupport.waitForReactNativeLoad(ReactNativeSupport.java:154)
        at com.wix.detox.ReactNativeCompat.waitForReactNativeLoad(ReactNativeCompat.java:33)
        at com.wix.detox.DetoxManager.start(DetoxManager.java:72)
        at com.wix.detox.Detox$1$1.run(Detox.java:133)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at com.wix.detox.Detox$1.run(Detox.java:136)
        at java.lang.Thread.run(Thread.java:764)

@AntoineGrandchamp
Copy link

@noomorph Do you have any update on this ?

@noomorph
Copy link
Collaborator

noomorph commented Oct 1, 2018

@AntoineGrandchamp, thanks for submitting crash details. I believe that currently, the right person to contact will be @rotemmiz. He's most familiar with this part, though even now I can say that he will ask for more details. E.g. what kind of app do you have? Is it a greenfield or brownfield app? When do you load React Native?

Maybe you should get into Java debugger and see why it does not get a new reactContext... since anyway we don't have a public repository that reproduces your problem.

@noomorph
Copy link
Collaborator

noomorph commented Oct 1, 2018

Clarification. At the moment, the reason why this issue got a label accepted/bug is that detox does not print crash details and exit, though it should, in these situations. I firmly believe that the timeout mechanism of a test runner is the last resort, not the way to go. That's what is missing right now.

@stale
Copy link

stale bot commented Nov 15, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions.

@stale stale bot added the 🏚 stale label Nov 15, 2018
@selvakumardreams
Copy link

Still the same problem

React: 16.6.1
Device: Redmi Note 4 (Android)
React-native: 0.57.5
Mocha: 5.2.0
Detox: 9.1.2
Windows: 10+

detox[43836] DEBUG: [DetoxServer.js/MESSAGE] role=tester action=isReady (sessionId=962944a2-143c-c6b1-c098-11d265255bae)
detox[43836] DEBUG: [DetoxServer.js] sendToOtherRole testee undefined { '962944a2-143c-c6b1-c098-11d265255bae':
{ tester:
WebSocket {
domain: null,
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
_socket: [Object],
_ultron: [Object],
_closeReceived: false,
bytesReceived: 168,
readyState: 1,
supports: [Object],
extensions: [Object],
_binaryType: 'nodebuffer',
protocol: undefined,
protocolVersion: 13,
upgradeReq: [Object],
_isServer: true,
maxPayload: 104857600,
_receiver: [Object],
_sender: [Object] } } } 962944a2-143c-c6b1-c098-11d265255bae
detox[43836] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=962944a2-143c-c6b1-c098-11d265255bae)

const ws = _.get(this.sessions, [sessionId, otherRole]); getting undefined.

@stale stale bot removed the 🏚 stale label Nov 20, 2018
@VincentCATILLON
Copy link

I got the same issue with API 18 on Android:

Detox: 9.0.1
React Native: 0.56.1
Node: 8.12.0 (nvm)
Device: Nexus 5X, API 18 (Google Play APIs)
Xcode: 10.1
macOS: 10.13.6

It's working on API 19, not 18 !

@stale
Copy link

stale bot commented Dec 22, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions.

@stale stale bot added the 🏚 stale label Dec 22, 2018
@rawqing
Copy link

rawqing commented Dec 25, 2018

I had the same problem with real devices, but I had no problem with emulators.
"dependencies": {
"react": "16.6.3",
"react-native": "0.57.8"
},
"devDependencies": {
"detox": "^9.1.2",
"mocha": "^4.0.1"
},

@stale stale bot removed the 🏚 stale label Dec 25, 2018
@awdhootlele
Copy link

Hi, Just curious, is your packager server running in bg? When I run detox test, it does not launch the packager server and my app crashes, but when I launch the server, my tests execute properly.

@mentormategeorgirusev
Copy link

mentormategeorgirusev commented Jan 25, 2019

Same here

Detox: 9.1.2
React Native: 0.55.3
React Native Navigation: 2.0.2571
Node: 11.7.0
Device: Android - Nexus_5X_API_27 -emulator
Xcode: n.a
macOS: Mojave 10.14.2
Windows: n.a

Here is the crash detail from adb logcat :

    --------- beginning of crash
2019-01-25 18:10:20.457 2633-2681/? E/AndroidRuntime: FATAL EXCEPTION: com.wix.detox.manager
    Process: com.trane.mobileservicetool.dev, PID: 2633
    java.lang.RuntimeException: waited a minute for the new reactContext
        at com.wix.detox.ReactNativeSupport.waitForReactNativeLoad(ReactNativeSupport.java:156)
        at com.wix.detox.ReactNativeCompat.waitForReactNativeLoad(ReactNativeCompat.java:33)
        at com.wix.detox.DetoxManager.start(DetoxManager.java:72)
        at com.wix.detox.Detox$1$1.run(Detox.java:133)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at com.wix.detox.Detox$1.run(Detox.java:136)
        at java.lang.Thread.run(Thread.java:764)

It seems there is an issue with getting the current ReactContext

@mentormategeorgirusev
Copy link

@leugimmai @lvmtam @ZSeba @AntoineGrandchamp @selvakumardreams @rawqing
Has any one of you guys, found a solution/workaround?

@mentormategeorgirusev
Copy link

@rotemmiz - I've found the exact reason - react native navigation.
As a part of the set up of the navigation, the mainActivity extend is different.
See Android step 5
react-native-navigation guide

As for Detox we have
Not working
public class MainActivity extends NavigationActivity implements PermissionAwareActivity{
Working
public class MainActivity extends ReactActivity implements PermissionAwareActivity{

I'm playing with ReactNativeSupport.java, and trying to replace the interfaces, but to no avail.
Are you planing to make any changes in order to support apps with react-native-navigation?

@rotemmiz
Copy link
Member

RNN uses Detox for its E2E suite, It is supported from the very beginning.
You need to further investigate

@mentormategeorgirusev
Copy link

@rotemmiz - that was helpful, I've played with RNN test app.
If I got it correctly, Detox will have no problems for android apps, using RectContext API
Unfortunately we are using redux, and we are not planing to migrate (we are close to release).

Is there a way to run Detox on app with redux?
If you have any test project, it will be very helpful.

@rotemmiz
Copy link
Member

Detox does not understand JavaScript at all, it only monitors threads, native modules and native UI hierarchy. Redux has nothing to do with it.

@mentormategeorgirusev
Copy link

mentormategeorgirusev commented Feb 4, 2019

@rotemmiz you are absolutely right. I've managed to run the detox for android via fix in MainApplication.java

I know it is not relevant for detox, yet I'll share it here, so anyone with similar issue could save some time
MainApplication.java

Make sure you Override the getReactNativeHost() with the host you've created

public class MainApplication extends NavigationApplication implements ReactApplication {

    protected NavigationReactNativeHost mNavigationReactNativeHost = null;

//This is what Detox is shooting for
    @Override
    public ReactNativeHost getReactNativeHost() {
        return mNavigationReactNativeHost;
    }


//When creating ReactGateway, keep the host and reuse is in getReactNativeHost()
    @Override
    protected ReactGateway createReactGateway() {
      mNavigationReactNativeHost = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
          @Override
          protected String getJSMainModuleName() {
          return "index";
          }
      };
    return new ReactGateway(this, isDebug(), mNavigationReactNativeHost);
    }
}

@stale
Copy link

stale bot commented Mar 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions.

@stale stale bot added the 🏚 stale label Mar 6, 2019
@stale
Copy link

stale bot commented Mar 13, 2019

The issue has been closed for inactivity.

@stale stale bot closed this as completed Mar 13, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests