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

Detox can't connect to the test app #4448

Open
2 tasks done
DanielLMA opened this issue Apr 11, 2024 · 1 comment
Open
2 tasks done

Detox can't connect to the test app #4448

DanielLMA opened this issue Apr 11, 2024 · 1 comment

Comments

@DanielLMA
Copy link

DanielLMA commented Apr 11, 2024

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?

  • I have tested this issue on the latest Detox release and it still reproduces.

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<MainActivity> 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


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+<name-here>://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
Copy link

I'm having the same issue on iOS simulator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants