我正在测试 monkeyrunner 并使用下面的 .py 文件进行屏幕截图。
生成截屏图像,但有时会在“resulet = device.takeSnapshot()”中出现错误
我不知道有什么问题。我已经用 Eclipse 对其进行了测试。(Eclipse -> AVD,皮肤 WVGA854)
请帮帮我~谢谢~
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
#device.installPackage('D:\\study_java\\monkeyrunner\\HelloAndroid.apk')
# sets a variable with the package's internal name
package = 'com.example.helloandroid'
# sets a variable with the name of an Activity in the package
activity = 'com.example.helloandroid.HelloAndroid'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
# Takes a screenshot
MonkeyRunner.sleep(0.5)
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')
下面是错误日志。
D:\study_java\monkeyrunner>monkeyrunner d:\study_java\monkeyrunner\monkeytest.py
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice] Unab
le to take snapshot
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]java.
io.IOException: EOF
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.ddmlib.AdbHelper.read(AdbHelper.java:643)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.ddmlib.AdbHelper.read(AdbHelper.java:616)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.ddmlib.AdbHelper.getFrameBuffer(AdbHelper.java:326)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.ddmlib.Device.getScreenshot(Device.java:270)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.monkeyrunner.adb.AdbMonkeyDevice.takeSnapshot(AdbMonkeyDevice.jav
a:197)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.monkeyrunner.MonkeyDevice.takeSnapshot(MonkeyDevice.java:83)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at java.lang.reflect.Method.invoke(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyObject.__call__(PyObject.java:355)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyMethod.__call__(PyMethod.java:215)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyMethod.__call__(PyMethod.java:206)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyObject.__call__(PyObject.java:381)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyObject.__call__(PyObject.java:385)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.pycode._pyx0.f$0(d:\study_java\monkeyrunner\monkeytest.py:37)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.pycode._pyx0.call_function(d:\study_java\monkeyrunner\monkeytest.p
y)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyTableCode.call(PyTableCode.java:165)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.PyCode.call(PyCode.java:18)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.Py.runCode(Py.java:1197)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:93)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:20
3)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
pt terminated due to an exception
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Trace
back (most recent call last):
File "d:\study_java\monkeyrunner\monkeytest.py", line 27, in <module>
result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')
at com.android.monkeyrunner.MonkeyImage.writeToFile(MonkeyImage.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NullPointerException: java.lang.NullPointerException
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyException.fillInStackTrace(PyException.java:70)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at java.lang.Throwable.<init>(Throwable.java:181)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at java.lang.Exception.<init>(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at java.lang.RuntimeException.<init>(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyException.<init>(PyException.java:46)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyException.<init>(PyException.java:43)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.JavaError(Py.java:455)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.JavaError(Py.java:448)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:177)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyObject.__call__(PyObject.java:355)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyMethod.__call__(PyMethod.java:215)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyMethod.__call__(PyMethod.java:206)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyObject.__call__(PyObject.java:414)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyObject.__call__(PyObject.java:418)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.pycode._pyx0.f$0(d:\study_java\monkeyrunner\monkeytest.py:37)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.pycode._pyx0.call_function(d:\study_java\monkeyrunner\monkeytest.p
y)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyTableCode.call(PyTableCode.java:165)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyCode.call(PyCode.java:18)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.runCode(Py.java:1197)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:93)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:20
3)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Cause
d by: java.lang.NullPointerException
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyImage.writeToFile(MonkeyImage.java:85)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at java.lang.reflect.Method.invoke(Unknown Source)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
... 16 more
D:\study_java\monkeyrunner>