wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.2k stars 1.92k forks source link

Detox can't connect to the test app #4448

Open DanielLMA opened 6 months ago

DanielLMA commented 6 months ago

What happened?

I have followed the steps for Android Detox project setup per https://wix.github.io/Detox/docs/introduction/project-setup .

After a successful build, when I try to run detox tests, the app is not launched and tests do not run - all timeout.

iOS does not have these issues.

What was the expected behaviour?

After completing successful build running

npx detox build --configuration android.release

I expect running detox tests by

npx detox test --configuration android.release

on the Android Studio emulator to execute.

Was it tested on latest Detox?

Did your test throw out a timeout?

Help us reproduce this issue!

On react-native app

rm -rf android/

npx expo prebuild --platform android

Patch build scripts per https://wix.github.io/Detox/docs/introduction/project-setup/#41-patching-build-scripts Add auxiliary Android test per https://wix.github.io/Detox/docs/introduction/project-setup/#42-adding-an-auxiliary-android-test

npx detox build --configuration android.release

If build successful

npx detox test --configuration android.release

### In what environment did this happen? Detox version: ^20.13.5 React Native version: 0.72.10 "expo": "^49.0.22", Node version: 16.18.1 Device model: emulator (Pixel_3a_API_34_extension_level_7_x86_64) Test-runner (select one): jest ### Detox logs
Detox logs ``` 09:16:59.025 detox[121254] i Detox can't seem to connect to the test app(s)! HINT: The test app might have crashed prematurely, or has had trouble setting up the connection. Refer to our troubleshooting guide, for full details: https://wix.github.io/Detox/docs/troubleshooting/running-tests#tests-execution-hangs 09:16:59.034 detox[121254] i An error occurred while waiting for the app to become ready. Waiting for disconnection... error: Failed to run application on the device HINT: Most likely, your tests have timed out and called detox.cleanup() while it was waiting for "ready" message (over WebSocket) from the instrumentation process. 09:16:59.035 detox[121254] i The app disconnected. FAIL e2e/start.test.js (130.542 s) .... ● Start app e2e testing flow › bypasses the notification screen thrown: "Exceeded timeout of 120000 ms for a hook. Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout." ```
### Device logs
Device logs ``` paste your device.log here! ```
### More data, please! .detoxrc.js ``` module.exports = { logger: { level: process.env.CI ? 'debug' : undefined, }, testRunner: { $0: 'jest', args: { config: 'e2e/jest.config.js', _: [ 'e2e' ], }, }, artifacts: { plugins: { log: process.env.CI ? 'failing' : undefined, screenshot: 'failing', video:'failing', }, }, apps: { 'android.release': { type: 'android.apk', build: 'cd android && ./gradlew :app:assembleRelease :app:assembleAndroidTest -DtestBuildType=release && cd ..', binaryPath: 'android/app/build/outputs/apk/release/app-release.apk', }, }, devices: { emulator: { type: 'android.emulator', device: { avdName: 'Pixel_3a_API_34_extension_level_7_x86_64', }, }, }, configurations: { 'android.release': { device: 'emulator', app: 'android.release', }, }, } ``` ./e2e/start.test.js ``` describe('Start app e2e testing flow', () => { beforeAll(async () => { await device.launchApp({ newInstance: true }) }) ... tests... }) ``` ./android/app/src/androidTest/java/au/com/companyname1/companyname2/prod/DetoxTest.java ``` package au.com.companyname1.companyname2.prod; 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.filters.LargeTest; import androidx.test.rule.ActivityTestRule; @RunWith(AndroidJUnit4.class) @LargeTest public class DetoxTest { @Rule public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false); @Test public void runDetoxTests() { DetoxConfig detoxConfig = new DetoxConfig(); detoxConfig.idlePolicyConfig.masterTimeoutSec = 90; detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60; detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60); Detox.runTests(mActivityRule, detoxConfig); } } ``` Step 4.1 steps followed precisely - https://wix.github.io/Detox/docs/introduction/project-setup/#41-patching-build-scripts (v20.x) ``` kotlinVersion = '1.9.0' ``` ![kotlin](https://github.com/wix/Detox/assets/49574367/bdce9cbf-38bd-4c81-b762-b2296c5fd88c) ------------------------ I have tried running the test build itself with ` npx expo run:android` and it loads on the emulator correctly. With this, have tried running the tests against the expo url changing the ./start.test.js to ``` ... beforeAll(async () => { await device.launchApp({ newInstance: false, url: `exp+://expo-development-client/?url=${encodeURIComponent( 'http://localhost:8081', )}`, }) }) ``` The currently running app closes and results in the same cannot connect to app error. --- Have tried invalidating the cache on Android Studio and rerunning. Does not solve. --- Although detox build is successful, but there are these notes/warnings: > Task :app:lintVitalAnalyzeRelease e: .//node_modules/expo-updates/android/build/.transforms/b01950e524e0f4b4d7cbab0253ab7589/transformed/out/jars/classes.jar!/META-INF/expo-updates_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. > Task :app:compileReleaseAndroidTestJavaWithJavac Note: .//android/app/src/androidTest/java/au/com//DetoxTest.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.
Zhangronger commented 5 months ago

I'm having the same issue on iOS simulator

cleberada commented 4 months ago

Same issue, any news?

DanielLMA commented 2 months ago

Any updates from Detox dev team? TIA