#! /usr/bin/env monkeyrunner
import sys
import os
from com.android.monkeyrunner import MonkeyRunner
PLI = 'pm list instrumentation'
prog = os.path.basename(sys.argv[0])
def usage():
print >>sys.stderr, \
"usage: %s target-package-name" % prog
sys.exit(1)
def main():
if len(sys.argv) != 2:
usage()
pkg = sys.argv[1]
print "waiting for connection..."
device = MonkeyRunner.waitForConnection()
print "running istrumentation for %s" % pkg
for (i, t) in map(lambda l: l.split(), device.shell(PLI).splitlines()):
if t == '(target=%s)' % pkg:
print device.instrument(i.split(':')[1], { 'wait':True })['stream']
return
print >>sys.stderr, "ERROR: instrumentation for %s not found" % pkg
if __name__ == '__main__':
main()You can invoke this script as in the following command line:
$ instrumentation.mr com.example.package
compare this against the command line you may need to invoke the same instrumentation using plain am instrument.
Once you invoke the script with the correct package name, the instrumentation for that package is run and the results are presented, like in this example:
waiting for connection...
running istrumentation for com.example.package
Test results for InstrumentationTestRunner=..................................
Time: 37.844
OK (34 tests)