I'm trying to run MonkeyRunner Android test tool from Eclipse (4.2). I installed Eclipse PyDev plugin, as well as Jython 2.5.1. My PyDev interpreter is set to Jython / 2.5.
I created a Jython project in Eclipse with a simple jython file:
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
Now when I launch it from Eclipse (project > run as JythonProject), I'me getting the following exception:
Traceback (most recent call last):
File "C:\svnrepository\trunk\JythonProject\src\main.py", line 10, in <module>
device = MonkeyRunner.waitForConnection()
at com.android.monkeyrunner.MonkeyRunner.waitForConnection(MonkeyRunner.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NullPointerException: java.lang.NullPointerException
Any idea what can be wrong?
There is a post of Diego Torres Milano how to configure PyDev to use it with monkeyrunner. I followed his steps and in my case everything works fine.
In brief, at first you need to change your Android installation. You need to rename your monkeyrunner tool to something monkeyrunner-original. Then you need to write in the same folder shell script (name it monkeyrunner) that will invoke monkeyrunner-original in the specific manner.
Script for Linux:
# /bin/bash
if [ "$1" = '-u' ]
then
shift
fi
exec /opt/android-sdk-linux_86/tools/monkeyrunner-original "$@"
Script for Windows:
REM
@echo off if("%1")==("-u") shift "C:\Program Files\Android\android-sdk\tools"/monkeyrunner-original %1 %2 %3 %4 %5 %6 %7 %8
Then in Eclipse, you should define new Python interpreter (not Jython) and point it to the created script.