移动端自动化测试,adb、androidviewclient 相
2019-12-03 本文已影响0人
过桥
一、手机链接不成功
>adb devices
List of devices attached
解决办法
没有发现设备,可能数据线没插好,或没开启USB调试,缺后再次尝试
二、手机没有操作没有权限
>adb devices
List of devices attached
D3H7N17B25023225 unauthorized
解决办法
连接后可能未经许可,需要点亮手机,弹出框中选择允许当前电脑调试
>adb devices
List of devices attached
D3H7N17B25023225 device
# 显示 device 为链接成功
三、无法正确启动adb下uiautomatorviewer.bat
双击启动\adb\adt-bundle-windows-x86_64-20140702\sdk\tools uiautomatorviewer.bat
Error obtaining UI hierarchy
Reason:
Unexpected error while obtaining UI hierarchy
Details:
java.lang.reflect.InvocationTargetException
解决办法
uiautomatorview 不兼容Android8.0以上版本,换低版本Android系统
四、无法安装 androidviewclient
解决办法
# 安装方式一、 androidviewclient,本地 Python 2.7 环境
# https://github.com/dtmilano/AndroidViewClient
# easy_install --upgrade androidviewclient
# 安装方式二、下载发行版androidviewclient
# https://github.com/dtmilano/AndroidViewClient/releases
# 设置环境变量 ANDROID_VIEW_CLIENT_HOME = E:\01_Code\02_Python\02_Tools\adb\AndroidViewClient-15.8.1
# 测试方法
# E:\01_Code\02_Python\02_Tools\adb\AndroidViewClient-15.8.1>cd examples
# E:\01_Code\02_Python\02_Tools\adb\AndroidViewClient-15.8.1\examples>python2 check-import.py
# OK
五、代码中不识别ViewClient包
from com.dtmilano.android.viewclient import ViewClient
解决办法
1、系统环境变量中添加
ANDROID_VIEW_CLIENT_HOME = E:\01_Code\02_Python\02_Tools\adb\AndroidViewClient-15.8.1
2、代码引包前添加
try:
if os.environ.has_key('ANDROID_VIEW_CLIENT_HOME'):
avcd = os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')
if os.path.isdir(avcd):
sys.path.append(avcd)
else:
print >>sys.stderr, "WARNING: '%s' is not a directory and is pointed by ANDROID_VIEW_CLIENT_HOME environment variable" % avcd
except:
pass
from com.dtmilano.android.viewclient import ViewClient
六、无法输入中文问题
解决办法
1、下载 https://github.com/senzhk/ADBKeyBoard/raw/master/ADBKeyboard.apk,手机上安装,并设置为默认输入法
2、代码调用
def adbSendText(text):
adb1 = 'adb shell ime set com.android.adbkeyboard/.AdbIME'
os.system(adb1)
adb2 = "adb shell am broadcast -a ADB_INPUT_TEXT --es msg '%s' " % text
os.system(adb2)
adbSendText("今天天气不错,挺风和日丽的")
七、中文繁体或个别字符显示错误或缺失
解决办法
def adbSendText(text):
adb1 = 'adb shell ime set com.android.adbkeyboard/.AdbIME'
os.system(adb1)
# 使用base64转换
text = base64.b64encode(text)
adb2 = "adb shell am broadcast -a ADB_INPUT_B64 --es msg '%s' " % text
os.system(adb2)