Thursday, November 03, 2011

Android Application Testing Guide: Q&A

Q:  Hi Diego, I wanted to ask that can i write a monkey runner script which controls a web based apk ?
Eg; I install youtube.apk which is nothing but a browser with hardcoded youtube url.
Now my monkeyrunner script shall install this apk and then pass events such as a search string etc on this web based application.
All this i want to do and control externally through the monkey runner script. Is this possible? If yes, then could you please guide me by some pseudo code? 

Comment on Using Android monkeyrunner from Eclipse

Posted by latha

A:  This is an interesting question and a good monkeyrunner example, so here we go. monkeyrunner has the ability of installing APKs after obtaining the connection with the device. Then we start Youtube main activity, sleep for a bit to let things settle down.
Once we have the activity running is time to start our search. To do it, we touch the Search icon, enter the desired search string, 'android' in this particular case and the we touch the Search button again to actually start the action.
Following, is the script that translates our plan to monkeyrunner:

#! /usr/bin/env monkeyrunner

import sys
import os
from import MonkeyRunner, MonkeyDevice

prog = os.path.basename(sys.argv[0])

def usage():
        print >>sys.stderr, "usage: %s" % prog

def main():
        if len(sys.argv) != 1:

        print "waiting for connection..."
        device = MonkeyRunner.waitForConnection()

        print "installing youtube"

        # search
        device.touch(450, 80, MonkeyDevice.DOWN_AND_UP)
        # done
        device.touch(450, 740, MonkeyDevice.DOWN_AND_UP)

if __name__ == '__main__':

This script covers the case described in the question but it could be easily adapted for other cases and application.

I hope this is the answer you were looking for.
Post a Comment