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

Android: instrumentationRunnerForBundleId(instrumentationRunners, bundleId) looking for .test #832

Closed
yamiscott opened this issue Jul 16, 2018 · 9 comments

Comments

@yamiscott
Copy link

Description

This appears to be an Android API <=25 issue

No instrumentation runner found on device emulator-5554 for package com.app.your.test

Where the problem appears to be: src/devices/android/ADB.js line 212

instrumentationRunnerForBundleId(instrumentationRunners, bundleId)

The above method is called with a bundle id ending in .test, there's a pointless regex statement that replaces '.' characters with '.' characters, I'm assuming this was mean to strip the .test from the end?

The instrumentation targets do not have '[yourbundle].test in them, just the regular bundle id.

eg:

instrumentation: com.app.your.test (target=com.app.your)

Meaning the regex will never match and you will get an error stating there is no instrumentation runner.

Steps to Reproduce

Follow the Android setup steps.
Detox build your android config
Detox run your android config

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 8.0.x
  • React Native: 0.55.4
  • Node: 9.8.0
  • Device: API-25 emulator
  • Xcode: N/A
  • macOS: 10.13.5

Device and verbose Detox logs

Error: Command failed: node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 --testNamePattern='^((?!:ios:).)*$'
    at checkExecSyncError (child_process.js:575:11)
    at Object.execSync (child_process.js:612:13)
    at runJest (/Users/scott.ewart/[PATH-REDACTED]/node_modules/detox/local-cli/detox-test.js:146:6)
    at run (/Users/scott.ewart/[PATH-REDACTED]/node_modules/detox/local-cli/detox-test.js:81:7)
    at Object.<anonymous> (/Users/scott.ewart/[PATH-REDACTED]/node_modules/detox/local-cli/detox-test.js:191:1)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
Scott-Ewart:[REDACED] scott.ewart$ detox test -c android.emu.debug-25 --loglevel verbose
node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 --testNamePattern='^((?!:ios:).)*$'
 server listening on localhost:57636...
 onOpen [object Object]
 send: {"type":"login","params":{"sessionId":"5223a68c-5b4f-e539-7d47-273636e99a9c","role":"tester"},"messageId":0}
 onMessage: {"type":"loginSuccess","params":{"sessionId":"5223a68c-5b4f-e539-7d47-273636e99a9c","role":"tester"},"messageId":0}
  rbx
 : /Users/scott.ewart/Library/Android/sdk/emulator/emulator -list-avds --verbose
1: stdout: Android_ARMv7a_Nougat
Android_Accelerated_Nougat
Galaxy_S3
Nexus_4_API_19
Nexus_4_Tester_
Nexus_5X_API_26
Nexus_5_4.95_1080_x_1920_4.4.2_19
Nexus_5_API_21_x86
Nexus_6_API_21
Nexus_6_API_25
Nexus_6_API_25_2
Short_Device
Vodafone_E8_VFD_510_API_25
 
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb  devices
2: stdout: List of devices attached
emulator-5554	device

 
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell getprop dev.bootcomplete
3: stdout: 1
 
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell input keyevent 82
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 uninstall com.app.my.test
5: stdout: Success
 
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 uninstall com.app.my.test.test
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell getprop ro.build.version.sdk
7: stdout: 25
 
8: /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 install -r -g /Users/scott.ewart/[PATH-REDACTED]/android/app/build/outputs/apk/androidTest/debu /app-debug-androidTest.apk
8: stdout: Success
 
 : /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell getprop ro.build.version.sdk
9: stdout: 25
 
10: /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 install -r -g /Users/scott.ewart/[PATH-REDACTED]/android/app/build/outputs/apk/androidTest/deb g/app-debug-androidTest.apk
10: stdout: Success
 
 1: /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell am force-stop com.app.my.test
 2: /Users/scott.ewart/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm list instrumentation
12: stdout: instrumentation:com.android.emulator.smoketests/android.support.test.runner.AndroidJUnitRunner (target=com.android.emulator.smoketests)
instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
instrumentation:com.app.my.test/android.support.test.runner.AndroidJUnitRunner (target=com.app.my)
instrumentation:org.chromium.webview_shell/.WebViewLayoutTestRunner (target=org.chromium.webview_shell)
@neerajkumar-lad
Copy link

+1

@neerajkumar-lad
Copy link

neerajkumar-lad commented Jul 17, 2018

@yamiscott any temp solution..? I am blocked.

@Team, Can we take as the priority?

@yamiscott
Copy link
Author

@neerajkumar-lad Only by post install patching or writing a fix.

If you post install patch node_modules/detox/src/devices/android/ADB.js line 212, changing the regex from replacing '\.' with '\.' to: '\.test' with '', then it will strip the .test, thus finding the driver.

@neerajkumar-lad
Copy link

@yamiscott This is the line i got in at 212,

const runnerForBundleRegEx = new RegExp(^instrumentation:(.*) \\(target=${bundleId.replace(new RegExp('\\.', 'g'), "\\.")}\\)$, 'gm');

I guess the problem is DetoxTest.java file is not starting instrumentation.

What I did is, I have opened the android project in Android studio and ran DetoxTest.java and successfully executed, thus I got following line when I entered adb shell pm list instrumentation

instrumentation:my.project.android.debug.test/android.support.test.runner.AndroidJUnitRunner (target=my.project.android.debug)

After I ran detox test -c android.emu.debug -l verbose

The application launched and got pop up message app "my.project.debug isn't responding" with close the app and wait option.

and finally, Execution stopped due to timeout Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

@yamiscott
Copy link
Author

yamiscott commented Jul 18, 2018

That's the line. The regex is wrong or there's something else at play that isn't obvious.

Let's break it down into two bits, the bundle ID it's looking for and the regex from the instrumentation list.

Sending in:
my.project.android.debug.test
(check it, that's your bundle ID in detox) Then in the middle of the main regex, there's a small ${} placeholder snippet that works out what the bundle should be:
${bundleId.replace(new RegExp('\\.', 'g'), "\\.")}
takes the '.' characters and replaces them with... the same '.' character. your new bundle is:
my.project.android.debug.test
Also known as exactly the same.

So we want to search the instrumentation list to work out which to run. That brings us to the rest of that line:
const runnerForBundleRegEx = new RegExp(^instrumentation:(.*) \\(target=${bundleId.replace(new RegExp('\\.', 'g'), "\\.")}\\)$, 'gm');
We can replace that placeholder with the result and see what's happening:
const runnerForBundleRegEx = new RegExp(^instrumentation:(.*) \\(target=my\.project\.android\.debug\.test\\)$, 'gm');
This means it's looking for:
instrumentation: anything.Here (target=my.project.android.debug.test)
Which doesn't match:
instrumentation:my.project.android.debug.test/android.support.test.runner.AndroidJUnitRunner (target=my.project.android.debug)

It should be stripping .test off the end, however it isn't.

Here's what I think it should be:
const runnerForBundleRegEx = new RegExp(^instrumentation:(.*) \\(target=${bundleId.replace(new RegExp('\\.test$', 'g'), "")}\\)$, 'gm');

This will strip the .test off the end if there is one. Which will now match and as a result it will find the correct instrumentation instance.

@neerajkumar-lad
Copy link

Hi Friends,

Something interesting I found,

I have setup detox android with sampleApp and I have run automation with two cases,
Case 1:

    "configurations": {
      "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": "Nexus_5X_API_28"
      },

In case 1, two apk generate, debug and androidTest, and detox automation run fine.

Case 2:

"configurations": {
      "android.emu.debug": {
        "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
        "build": "cd android && ./gradlew assembleDebug -DtestBuildType=debug && cd ..",
        "type": "android.emulator",
        "name": "Nexus_5X_API_28"
      },

In case 2,
I get following error,

'/Users/[Path]/sampleApp/android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk' could not be found, did you run './gradlew assembleAndroidTest' ?

Interesting is I don't have to change APKPath.js file with default android apk name(app-debug.apk), update you once I changed the custome apk name(my.project.1.3.1-debug.apk)

I think Detox use automation something like this,

  • Detox use internally Espresso test to start instrumentation
  • Espresso test start instrumentation
  • Then Detox use that instrumentation to start automation

As case 2, assembleAndroidTest build is not generated, so error throws

Hope this will help people.

@stale
Copy link

stale bot commented Sep 2, 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 Sep 2, 2018
@stale
Copy link

stale bot commented Sep 9, 2018

The issue has been closed for inactivity.

@stale stale bot closed this as completed Sep 9, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 12, 2018
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

2 participants