Saturday, February 5, 2011

monkeyrunner

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:
http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html

Documentation is available on these URLs:
http://developer.android.com/guide/developing/tools/MonkeyDevice.html
http://developer.android.com/guide/developing/tools/MonkeyImage.html
http://developer.android.com/guide/developing/tools/MonkeyRunner.html

Ohh... and by the way, the sample code has some problems:
1. the activity to launch has to be in this format: your.package.name/.NameOfYourActivity
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? ;-)

19 comments:

Shiju Koyalikkal said...

Hi,

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

Thanks

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='com.example.android.myapplication/.MainActivity')

Joao

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...

Hello,

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:
http://www.imagemagick.org/Usage/compare/

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 " http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html" 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

Thanks
Gorav

HInfante said...

Hi,
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...

Techie:
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: http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html

HInfante:
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...

DEVELOPERS said...

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. vShare iOS 9

LETSDOIT said...

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. XmodGames iOS 11

2009 DREAM said...

I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. Pangu

SEO KILLER said...

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. Jailbreak iOS 11.3

vshare apk iphone said...


Very Good and great share awesome...!!
Click me

dhooon said...

Lovely visit of this website where I am letting about delicious recipe of making pumpkin cupcakes.
Like to bookmarking this website and surly visit again. Keep posting visiting.

Wheel of fortune Same Name

michael smith said...

Thanks, for sharing the information I like very much
Residential housekeeping

michael smith said...

limo services tequesta florida
limo service wellington
car service of south florida
south florida car service
airport car service west palm beach
limo service from west palm beach airport
limo service lake worth
limo services juno beach
limo services singer islands
limo services jupiter island
Airport limo car Company offers chauffeured limo services in these areas Airport Wellington, Airport West Palm Beach, Singer Island to Fort Lauderdale airport, Spa Palm Beach, Tequesta, pga national resort limo in South Florida. Get a Quote.

Unknown said...

Thanks for the help eveThank you so much for this. I was into this issue and tired to tinker around to check if its possible but couldnt get it done. Now that i have seen the way you did it, thanks guys
with
regardsryone!
mobdro
vidmate

waniaabegg said...

Play at Slots.lv Casino Review - MrCD
The 목포 출장안마 Slots.lv Casino Review. 인천광역 출장샵 Read our detailed 남양주 출장안마 review of the 보령 출장샵 site, bonus features, and game selection. Read our casino review 영천 출장안마 before you go.

abhijitoberhelman said...

Our assortment of the best sex toys will certainly satisfy your sexual wants and urges. sex toy Sex toys like these are simply satisfying at a complete new stage and have been talked about within the Kama Sutra as well. Things have undoubtedly changed prior to now few a few years and at present, we now have dildos that are be} made up of unique supplies like glass and metallic. They are probably the most excellent toys in case you are planning on something sizzling and steamy together with your companion or just need to have prime quality|a high quality} alone time. Dildos and vibrators are both sex toys, and there’s a good amount of overlap between their features.