1

我使用 android MonkeyRunner 做一些测试

每次运行 Monkeyruuner.sleep() 都会失败

像这样

from com.android.monkeyrunner import MonkeyRunner
device = MonkeyRunner.waitForConnection()
device.press('KEYCODE_ENTER', 'DOWN_AND_UP')
MonkeyRunner.sleep(10)
device.press('KEYCODE_ENTER', 'DOWN_AND_UP')

在第二

device.press('KEYCODE_ENTER', 'DOWN_AND_UP')

总是失败

[main] [com.android.chimpchat.adb.AdbChimpDevice] Error sending press event: KEYCODE_ENTER DOWN_AND_UP

请帮忙谢谢'谢谢大家的回复!

但即使使用 time.sleep() 或 MonkeyDevice.DOWN_AND_UP 总是有错误

我的分数代码

from com.android.monkeyrunner import MonkeyRunner
import time 
device = MonkeyRunner.waitForConnection()
device.press('KEYCODE_DPAD_RIGHT', device.DOWN)
device.press('KEYCODE_DPAD_RIGHT', device.UP)
time.sleep(2)
device.press('KEYCODE_DPAD_RIGHT', device.DOWN)
device.press('KEYCODE_DPAD_RIGHT', device.UP)
time.sleep(2)
device.press('KEYCODE_DPAD_RIGHT', device.DOWN)
device.press('KEYCODE_DPAD_RIGHT', device.UP)
time.sleep(2)

三下下来,上来总是错的

日志

120718 09:50:51.744:S [main] [com.android.chimpchat.adb.AdbChimpDevice] Error sending press event: KEYCODE_DPAD_RIGHT DOWN
120718 09:50:51.744:S [main][com.android.chimpchat.adb.AdbChimpDevice]java.net.SocketException: Software caused connection abort: recv failed
120718 09:50:51.744:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at java.net.SocketInputStream.socketRead0(Native Method)
120718 09:50:51.744:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at java.net.SocketInputStream.read(Unknown Source)
120718 09:50:51.744:S [main] [com.android.chimpchat.adb.AdbChimpDevice] at

谢谢!

4

2 回答 2

3

您的关键代码是根据 API。

但是,我对 MonkeyRunner.sleep 函数有类似的问题(在某些 android 版本中可能是一个错误)。

作为一种解决方法,我使用如下所述的 time.sleep 函数。

import time
from com.android.monkeyrunner import MonkeyRunner
device = MonkeyRunner.waitForConnection()
device.press('KEYCODE_ENTER', 'DOWN_AND_UP')
time.sleep(10)
device.press('KEYCODE_ENTER', 'DOWN_AND_UP')

谢谢你。

于 2012-07-03T12:24:35.357 回答
1

它没有失败,因为Monkeyruuner.sleep()实际上device.press 'DOWN_AND_UP'应该是MonkeyDevice.DOWN_AND_UP

于 2012-06-27T17:54:23.980 回答