Reputation: 129
i using android MonkeyRunner do some test
every time run Monkeyruuner.sleep() will FAIL
like this
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')
in the second
device.press('KEYCODE_ENTER', 'DOWN_AND_UP')
always fail
[main] [com.android.chimpchat.adb.AdbChimpDevice] Error sending press event: KEYCODE_ENTER DOWN_AND_UP
please help thank ' Thanks all reply!
but even using time.sleep() or MonkeyDevice.DOWN_AND_UP always have wrong
my scores code
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)
in the three time down , up always wrong
log
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
THANKS!
Upvotes: 1
Views: 3377
Reputation: 1881
Your key code is as per the API.
However, I had similar issue with MonkeyRunner.sleep function (Could be a bug itslef in certain android builds).
As a workaround I use time.sleep function as mentioned below.
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')
Thank You.
Upvotes: 3
Reputation: 2781
It's not failing because of Monkeyruuner.sleep()
, in device.press
'DOWN_AND_UP'
should actually be MonkeyDevice.DOWN_AND_UP
Upvotes: 1