2012-06-27 41 views
1

我採用了android MonkeyRunner做一些測試每運行Monkeyruuner.sleep(時間Monkeyrunner.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 

謝謝!

回答

1

這不是失敗,因爲的Monkeyruuner.sleep(),在device.press'DOWN_AND_UP'實際上應該是MonkeyDevice.DOWN_AND_UP

3

你的關鍵代碼按照API。

但是,我有類似的問題與MonkeyRunner.sleep函數(可能是某些android版本中的一個bug itslef)。

作爲解決方法,我使用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') 

謝謝。

+0

API文檔不正確。如果給出無效選項,device.press()將默認使用down_and_up。這就是字符串工作的原因。嘗試做device.press('KEYCODE_ENTER','DOWN')然後device.press('KEYCODE_ENTER','UP')。這應該表現得像一個down_and_up,但是你會得到兩次enter鍵。然而,執行device.press('KEYCODE_ENTER',MonkeyDevice.DOWN)然後device.press('KEYCODE_ENTER',MonkeyDevice.UP)的行爲正常。 – someoneHuman

+0

此外,它看起來像API文檔已更正。請參閱http://developer.android.com/tools/help/monkeyrunner_concepts.html – someoneHuman