我的python脚本中的代码如下:
params = dict()
params['package']='com.pp.assistant.test'
device.instrument(r"com.pp.assistant.test/android.test.InstrumentationTestRunner",params)
但是当我运行代码时:
C:\Users\Administrator>monkeyrunner E:\MyPython\MonkeyRunnerTest\test.py
150708 12:14:18.683:S [main] [com.android.chimpchat.adb.AdbChimpDevice]
我收到以下错误:
执行命令时出错: 是仪器-w -r com.pp.assistant.test / android.test.InstrumentationTestRunner
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice] com.android.ddmlib.ShellCommandUnresponsiveException
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:513)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:390)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:359)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.ddmlib.Device.executeShellCommand(Device.java:568)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.chimpchat.adb.AdbChimpDevice.shell(AdbChimpDevice.java:274)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.chimpchat.adb.AdbChimpDevice.shell(AdbChimpDevice.java:267)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.chimpchat.adb.AdbChimpDevice.shell(AdbChimpDevice.java:262)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.chimpchat.adb.AdbChimpDevice.instrument(AdbChimpDevice.java:503)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.monkeyrunner.MonkeyDevice.instrument(MonkeyDevice.java:358)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 java.lang.reflect.Method.invoke(Method.java:606)150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来 org.python.core.PyReflectedFunction。的呼叫(PyReflectedFunction.java:186) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 org.python.core.PyReflectedFunction。的呼叫(PyReflectedFunction.java:204) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 org.python.core.PyObject。 call (PyObject.java:422)150708 12:14:18.683:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at at org.python.core.PyObject。 call (PyObject.java:426)150708 12:14:18.683:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at at org.python.core.PyMethod。 call (PyMethod.java:139)150708 12:14:18.683:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at at org.python.pycode._pyx0.f $ 0(E:\ MyPython \ MonkeyRunnerTest \ test.py:65) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 org.python.pycode._pyx0.call_function(E:\ MyPython \ MonkeyRunnerTest \ test.py) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 org.python.core.PyTableCode.call(PyTableCode.java:165)150708 12:14:18.683:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at at org.python.core.PyCode.call(PyCode.java:18)150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来 org.python.core.Py.runCode(Py.java:1275)150708 12:14:18.683:S [main] [com.android.chimpchat.adb.AdbChimpDevice]来了 org.python.core的内置 .execfile_flags(的内置的.java:522)。 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:225) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77) 150708 12:14:18.683:S [主要] [com.android.chimpchat.adb.AdbChimpDevice]来了 com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:189) 150708 12:14:18.692:S [主要] [com.android.monkeyrunner.MonkeyRunnerOptions]脚本终止到期 异常150708 12:14:18.692:S [主要] [com.android.monkeyrunner.MonkeyRunnerOptions]回溯(最近的 最后调用):文件" E:\ MyPython \ MonkeyRunnerTest \ test.py",第64行,in device.instrument(" com.pp.assistant.test / android.test.InstrumentationTestRunner",则params) 在java.util.regex.Matcher.getTextLength(Matcher.java:1234) 在java.util.regex.Matcher.reset(Matcher.java:308) 在java.util.regex.Matcher。(Matcher.java:228) 在java.util.regex.Pattern.matcher(Pattern.java:1088) 在com.android.chimpchat.adb.AdbChimpDevice.convertInstrumentResult(AdbChimpDevice.java:517) 在com.android.chimpchat.adb.AdbChimpDevice.instrument(AdbChimpDevice.java:504) 在com.android.monkeyrunner.MonkeyDevice.instrument(MonkeyDevice.java:358) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:606)
java.lang.NullPointerException:java.lang.NullPointerException
答案 0 :(得分:0)
您可以改为使用AndroidViewClient/culebra。
此脚本将帮助您为不同的包运行仪器,甚至列出它们。
#! /usr/bin/python
import sys
import os
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
PLI = 'pm list instrumentation'
prog = os.path.basename(sys.argv[0])
def usage():
print >>sys.stderr, \
"usage: %s [-s|--serialno serialno] {target-package-name | LIST}" % prog
sys.exit(1)
def main():
serialno = '.*'
if len(sys.argv) < 2:
usage()
if sys.argv[1] in ['-s', '--serialno']:
sys.argv.pop(1)
serialno = sys.argv.pop(1)
elif sys.argv[1].startswith('-'):
usage
if len(sys.argv) != 2:
usage()
pkg = sys.argv[1]
kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False, 'timeout': 500}
device, serialno = ViewClient.connectToDeviceOrExit(serialno=serialno, **kwargs1)
isList = (pkg.upper() == 'LIST')
if not isList:
print "running instrumentation for %s on %s" % (pkg, serialno)
for (i, t) in map(lambda l: l.split(), device.shell(PLI).splitlines()):
ptr = i.split(':')[1]
if isList:
print ptr, t
elif t == '(target=%s)' % pkg:
print device.shell('am instrument -w %s' % ptr)
return
if not isList:
print >>sys.stderr, "ERROR: instrumentation for %s not found" % pkg
if __name__ == '__main__':
main()