AVC adbclient操作因RuntimeError而失败

时间:2014-08-29 03:24:18

标签: python androidviewclient

我有一个简单的代码片段,如下所示,使用AVC对Nexus3手机执行一些连续操作。

#! /usr/bin/python
import sys, os, time

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.adb.adbclient import AdbClient
#from com.dtmilano.android.viewclient import ViewClient

adbc=AdbClient(serialno='.*')
print 'taking snapshot...'
adbc.takeSnapshot()
print 'touch 1st time...'
adbc.touch(50,70)
time.sleep(1)
print 'touch 2nd time...'
adbc.touch(50,70)

在touch()之前使用takeSnapshot()代码,touch()失败并出现以下异常:

touch 1st time...
sending 0015shell:input tap 50 70
shell(cmd=input tap 50 70)
__send(shell:input tap 50 70, checkok=True, reconnect=False)
__checkOk()
checkConnected()
    checkConnected: returning True
setAlarm(150)
    __checkOk: recv= ''
setAlarm(0)
Traceback (most recent call last):
  File "/home/swang/engine/test.py", line 19, in <module>
    adbc.touch(50,70)
  File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 430, in touch
    self.shell('input tap %d %d' % (x, y))
  File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 260, in shell
    self.__send('shell:%s' % cmd, checkok=True, reconnect=False)
  File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 157, in __send
    self.__checkOk()
  File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 193, in __checkOk
    raise RuntimeError("ERROR: %s %s" % (repr(recv), error))
RuntimeError: ERROR: '' 
Closing socket... <socket._socketobject object at 0xa9da60>

但如果我删除了takeSnapshot(),则以下2次touch()将成功。我使用的是最近的AVC版本。我在这里忽略了什么吗?

1 个答案:

答案 0 :(得分:0)

由于历史原因,AdbClient.takeSnapshot()定义为

def takeSnapshot(self, reconnect=False):
   ...

这意味着在截取屏幕后会断开连接。 所以你需要在脚本中做的就是

...
adbc=AdbClient(serialno='.*')
print 'taking snapshot...'
adbc.takeSnapshot(reconnect=True)
print 'touch 1st time...'
adbc.touch(50,70)
time.sleep(1)
print 'touch 2nd time...'
adbc.touch(50,70)

它会起作用。