最近用monkeyrunner做自动化测试,遇到连续两次点击,第二次点击就会报错“Error sending touch event”。
具体做法如下:
device.touch(234,112, 'MonkeyDevice.DOWN_AND_UP')
time.sleep(3)
device.touch(297,250,'MonkeyDevice.DOWN_AND_UP')
第二次touch的时候报错如下:
Error sending touch event: 297 250 DOWN_AND_UP
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at com.android.chimpchat.ChimpManager.sendMonkeyEventAndGetResponse(ChimpManager.java:188)
google后找到的解决方案,是在每次使用device的时候必须先要给他初始化device。在第二个device.touch(297,250,'MonkeyDevice.DOWN_AND_UP')前面加上device = MonkeyRunner.waitForConnection()就可以了。
百度了半天都没结果,还是上stackoverflow.com找到的。
具体可以参考:http://stackoverflow.com/questions/16466013/device-press-touch-with-monkeyrunner-on-droidbox-dont-work