MonkeyRunner empty results

I have android project which contain espresso test. I want to run this espresso test each time the build is success. I have created a Script step which utilize MonkeyRunner tools on android SDK. This script will install the generated APK to emulator and run the UI test. 
Based on the log, the emulator started successfully, and the script able to install the apk to the emulator. But when the script runs the instrumentation test, the result variable only containse an empty array. This is the python function to run the instrumentation test via monkeyrunner

    def perform_test(device, package_name):
        params = dict({})

        test_runner = (package_name + '.test' + '/android.support.test.runner.AndroidJUnitRunner')

        result = device.instrument(test_runner, params)
        print result

I try to run the same script locally on my machine, and the result is this array
> INSTRUMENTATION_STATUS: numtests=2
> INSTRUMENTATION_STATUS: stream=
> org.greenfroyo.bitplayground.ExampleInstrumentedTest:
> INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
> INSTRUMENTATION_STATUS: test=useAppContext
> INSTRUMENTATION_STATUS: class=org.greenfroyo.bitplayground.ExampleInstrumentedTest
> INSTRUMENTATION_STATUS: current=1
> INSTRUMENTATION_STATUS_CODE: 1
> INSTRUMENTATION_STATUS: numtests=2
> INSTRUMENTATION_STATUS: stream=.
> INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
> INSTRUMENTATION_STATUS: test=useAppContext
> INSTRUMENTATION_STATUS: class=org.greenfroyo.bitplayground.ExampleInstrumentedTest
> INSTRUMENTATION_STATUS: current=1
> INSTRUMENTATION_STATUS_CODE: 0
> INSTRUMENTATION_STATUS: numtests=2
> INSTRUMENTATION_STATUS: stream=
> org.greenfroyo.bitplayground.MainActivityTest:
> INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
> INSTRUMENTATION_STATUS: test=changeText
> INSTRUMENTATION_STATUS: class=org.greenfroyo.bitplayground.MainActivityTest
> INSTRUMENTATION_STATUS: current=2
> INSTRUMENTATION_STATUS_CODE: 1
> INSTRUMENTATION_STATUS: numtests=2
> INSTRUMENTATION_STATUS: stream=.
> INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
> INSTRUMENTATION_STATUS: test=changeText
> INSTRUMENTATION_STATUS: class=org.greenfroyo.bitplayground.MainActivityTest
> INSTRUMENTATION_STATUS: current=2
> INSTRUMENTATION_STATUS_CODE: 0
> INSTRUMENTATION_RESULT: stream=

This is the log of the builds
+------------------------------------------------------------------------------+
| (7) script@1.1.3                                                             |
+------------------------------------------------------------------------------+
| id: script                                                                   |
| version: 1.1.3                                                               |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2017-02-24T07:53:16Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
+ python --version
Python 2.7.12
+ /opt/android-sdk-linux/tools/monkeyrunner run_test.py . emulator-5554
>>>>> Start run_test.py
>> Directory : ./log/emulator-5554
>> Device Id : emulator-5554
>> SDK Path  : /opt/android-sdk-linux
>> Package   : org.greenfroyo.bitplayground
>> APK Path  : ./app/build/outputs/apk/app-debug.apk
>>>>> Starting connection to device
<<<<< Device connected
>>>>> Installing app...
[  4%] /data/local/tmp/app-debug.apk
[  9%] /data/local/tmp/app-debug.apk
[ 13%] /data/local/tmp/app-debug.apk
[ 18%] /data/local/tmp/app-debug.apk
[ 22%] /data/local/tmp/app-debug.apk
[ 27%] /data/local/tmp/app-debug.apk
[ 31%] /data/local/tmp/app-debug.apk
[ 36%] /data/local/tmp/app-debug.apk
[ 40%] /data/local/tmp/app-debug.apk
[ 45%] /data/local/tmp/app-debug.apk
[ 49%] /data/local/tmp/app-debug.apk
[ 54%] /data/local/tmp/app-debug.apk
[ 58%] /data/local/tmp/app-debug.apk
[ 63%] /data/local/tmp/app-debug.apk
[ 67%] /data/local/tmp/app-debug.apk
[ 72%] /data/local/tmp/app-debug.apk
[ 77%] /data/local/tmp/app-debug.apk
[ 81%] /data/local/tmp/app-debug.apk
[ 86%] /data/local/tmp/app-debug.apk
[ 90%] /data/local/tmp/app-debug.apk
[ 95%] /data/local/tmp/app-debug.apk
[ 99%] /data/local/tmp/app-debug.apk
[100%] /data/local/tmp/app-debug.apk
	pkg: /data/local/tmp/app-debug.apk
Success
<<<<< App installed
>>>>> Opening app...
<<<<< App opened
>>>>> Perform Test
{}
<<<<< Test Done
|                                                                              |
+---+---------------------------------------------------------------+----------+
| ✓ | script@1.1.3                                                  | 74 sec   |
+---+---------------------------------------------------------------+----------+
 

I need this output to determine if the test is success or not.

Thanks for reporting @fchristysen!

@tamaspapik pls have a look!

2 Likes

Seems like the issue is resolved by removing -no-window flag from the Start Android Emulator steps’s emulator commands field. :+1:t2:

1 Like

Awesome! Thank you @tamaspapik!

Just to be sure - @fchristysen did confirm this, right? :wink:

Yes, the problem is the emulator won’t start, and it fix it. Thanks @viktorbenei and @tamaspapik
Sorry for late reply :grin:

1 Like