Using Android monkeyrunner from Eclipse, both in Windows and Linux!

Standard

This time I want to use English to make this article useful for all others in the world:)

As you know, Android MonkeyRunner is a good testing tool, but we could only develop monkeyrunner under a text editor like Vim, emacs, etc.

Diego Torres Milano wrote a blog to make Monkeyrunner running on Eclipse, he had done that on Linux. But according to his article, he mislead guys thinking that his solution also works on Windows. But after serveral tries by myself and others’ comments, it does not work in Windows at all.

Here I found a solution which also works on Windows(I have tried it by myself). And I believe that it also works on Linux, as the solution does not include any platform independent mechanism. Here we go :)

      1. Install/Update latest PyDev (2.2.4 at present, I think it does not relate to the PyDev version) by Eclipse Marketplace or direct install link, see guide here
      2. Extract Lib folder in ANDROID_SDK\tools\lib\jython.jar using 7-Zip/WinRAR  to ANDROID_SDK\tools\lib folder, which would be like ANDROID_SDK\tools\lib\Lib
      3. Add a Jython Interpreter under Window>Preferences>PyDev>Interpreter – Jython. Using the jython.jar from Android SDK\tools\lib folder.
      4. Please notice that adding Android SDK\tools\lib and monkeyrunner.jar in Libraries. See snapshot below: Monkeyrunner in Eclipse
      5. Click “Apply” and wait it finish. Press “OK”
      6. Now you can use this new MonkeyRunner Interpreter to set up a PyDev project. But please make sure to choose “Jython” and using Grammar version “2.5″ as Jython itself is not catching up with Python. The latest Jython is 2.5.2, but Android SDK uses 2.5.0. It’s OK to replace the old one with the latest one. That’s another story. Snapshot of project setup:

Now you could write MonkeyRunner script with convenient features like auto-completion, grammmer error notice etc. Have fun:)

Notice: you cannot click the Run button to execute monkeyrunner script, it will not use monkeyrunner.bat to execute.

About these ads

12 thoughts on “Using Android monkeyrunner from Eclipse, both in Windows and Linux!

    • Indigo没问题呀,我就是用Indigo试的;另外建议你升级PyDev到最新版。
      你确定从python.jar里面解压Lib文件夹出来了?

  1. Tiago Farias

    Hi Sean,

    I used this approach and it seems to work so far. The problem is that when I try to run a script clicking the ‘run’ button in Eclipse I get NullPointerExceptions. In your post you mention we cannot use the ‘run’ in Eclipse. But I’m using Windows and I dont know other way to run this script. What do you suggest?

    Regards.

      • Miguel

        Thanks for the guide. I am also using Windows and was not able to get this running using DTM’s blog.

        I followed your steps but I get this error when I run the file:

        ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment

        I’m new to Eclipse and Monkeyrunner and would appreciate any help with resolving this error.

  2. Leo

    Dear Sir,

    I ran MonkeyRunner on Win7 OS as your post, but always met the problem: ‘adb rejected adb port forwarding command cannot bind socket’.

    I just installed Android SDK, python2.7, Eclipse, PyDev.
    Then use the sample code in Android developer web site.

    Could you show me how to fix the problem?
    Many thanks.

    • Try command ‘adb kill-server’ and ‘adb start-server’ to restart the adb. It could be found under your android sdk directory, subfolder platform-tools.

      • Leo

        Hi, Seganw

        I tried the command, but it cannot work too. I do not know if any unknown setting in Win7 or AD problem. Still trying…

  3. Hi Sean. I don’t know you are still watching this, but it’s worth a shot.

    I did all your steps, the only difference is that the Interpreter option under Grammar version does not show MR, only default and the path to the jython.jar

    I’m getting the following error: java.lang.NoClassDefFoundError: Could not initialize class com.android.monkeyrunner.MonkeyDevice

    Here is my code:

    from com.android.monkeyrunner import MonkeyDevice, MonkeyRunner, MonkeyImage, MonkeyManager

    device= MonkeyDevice
    for i in range(5):
    device = MonkeyRunner.waitForConnection(8)
    if device != None:
    print “Device found…”
    break;

    device.press(“KEYCODE_NOTIFICATION”, “DOWN_AND_UP”)
    time.sleep(1)
    device.press(“KEYCODE_BACK”, “DOWN_AND_UP”)

    do you have any thoughts?

    appreciate it

    • Karl

      As previous comment said, these steps just make enable “auto-completion, grammmer error notice etc”. You still have to start script from monkeyrunner.

      I misunderstand it once. :)

  4. You can configure Eclipse to run your code by configuring monkeyrunner.bat as Run/External Tools. Location: [...]\skd\tools\monkeyrunner.bat;
    Worlking Dir.: is your directory of your apk and other resources.
    Arguments: e.g. c:\workspace.py\MyDonkeyrunner\src\testpack\example.py

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s