Saturday, February 5, 2011


I was looking for a way on how to remotely execute touch events on an Android device/emulator. I couldn't find something that met all my requirements but came through this great tool that Android SDK offers: monkeyrunner.

It is quite simple to write a sequence of commands to execute: open an activity, press a key, touch the screen, everything (or almost everything?) you can do with a device. Additionally to sending commands, it is also possible to take screenshots of the screen to check if it is showing the expected behavior. Quite nice.

Information about monkeyrunner and a sample script can be found this page:

Documentation is available on these URLs:

Ohh... and by the way, the sample code has some problems:
1. the activity to launch has to be in this format:
2. device.takeSnapShot should be: device.takeSnapshot()

Now.. wouldn't it be great if there was some kind of cloud service that executed uploaded scripts into a wide variety of devices? ;-)


Shiju Koyalikkal said...


I want to know is it possible to load image from hard disk and compare that image with the image that we took at the time of running/testing the application using monkey runner. another thing is that is there any way to launch an application with out device.touch instruction. If possible can u send me the code for that


joão said...

Hello Shiju,

It is possible to compare two images using the MonkeyImage#sameAs method. It will compare both images on a pixel-by-pixel basis and return true if both images have the specified percentage of equal pixels. Using this combined with MonkeyImage#getSubImage will probably be the best you can do with monkeyrunner.

You can start any activity without a single touch instruction using MonkeyDevice#startActivity. An example: device.startActivity(component='')


Shiju Koyalikkal said...

Hi joao,

Thanks for your reply.I realy need help from people like you to go with monkeyrunner tool because I am new with Monkeyrunner and there is not much documents in web site.

I want to campare the current image(that I am taking at the time of running the monkeyrunner) with an image that I previously stord in hard disk(Image is taken using monkeyrunner and stored the image in harddisk as .png file). Is it possible to compare an image stored in hard disk with an image that is taken using the statement scMenu = device.takeSnapshot()?

joão said...


I've re-read the manual, and realized now that the #sameAs method only takes a MonkeyImage object but there is no way to load an image from the local disk.

ImageMagick has a command-line tool "compare" that can compare two images for you.

More info can be found on their website:

Shiju Koyalikkal said...

Hello Joao
Thanks for your reply.
Is it possible to use this ImageMagic command in monkeyrunner tool. If possible how? can you give me some sample code.
In android site "" said that using monkeyrunner we can do functional/regression testing, extensible automation etc. but I can't understand how this is possible with this tool. I need to automate an application that run in android mobile, Using that application we can capture the videos from a external device and make it as clips or video and save it in mobile. In this Application I need to automate the clips and video options are working and saved it in to the mobile, and also verify the clarity of the images.
Is this this are possible to automate using monkeyrunner? if not please tell me some other tool for this.
Once again thank you very much for your reply and time spend for my doubts.

Techie said...

I have a confusion, how can I make a project using MonkeyRunner, or in simple terms, How would I use Monkey Runner to write code. Eclipse SDK for android is in Java. How, can i write python there.

Any link will be greatly appreciated


HInfante said...

I have a simple question, how to do the same think like the monkeyrunner do, sending events to the smarphone (so mimics the user finger), but not using the ADB, is possible to do using wifi&socktes instead using the ADB?

Do you know if is possible, what i should search to find this kind of solution?

Thank you all!

joão said...

MonkeyRunner is a SDK command-line tool. You don't need to create a project on eclipse to use it. Further explanation about the concepts of monkeyrunner can be found on the given link:

I don't know if it is possible to run monkeyrunner through wifi or sockets.
I know about some android vnc server projects out there (you'll need to root you device) but never tried them...