adb自动化测试代码问题总结

2021-03-27  本文已影响0人  陶_306c

未解决的问题

1、adb shell input text 带有特殊符号的字符串。

account ='aqniu-wx'
os.system('adb shell input text '+account)

显示的是-aqniuwx

解决的问题:

1、Uiautomator not starting

先试用adb devices查询到设备
再使用命令python -m uiautomator2 init在模拟器上安装ATX
打开ATX,启动UIautomator,提示Uiautomator not starting
解决办法:

adb shell
chmod 755 /data/local/tmp/atx-agent
data/local/tmp/atx-agent version # 查看版本
/data/local/tmp/atx-agent server -d # 启动atx-agent并切换到后台运行

2、pip install atx报错PyYAML

依赖包的错误ERROR:

Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

\color{darkblue}{解决办法:}
可以加一句--ignore-installed PyYAML,忽略依赖包的安装

3、打开 UI Automator Viewer 程序报错

Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncExceptio
\color{blue}{解决办法}:重启模拟器

4、adb devices报错adb server version (31) doesn't match this client (40); killing...

这里adb server版本指的是模拟器中adb程序的版本
client 的版本指的是SDK中adb的程序版本
\color{darkblue}{有两种解决办法:}

第一种是更改client版本:

这个可以在网上找自己想要的版本,但是不好下载,这里提供40版本的adb下载。链接: https://pan.baidu.com/s/10fYDO6OIviIfABhaQi73vw 提取码: 9ud4

第二种是更改adb server版本:

server version是指模拟器中的adb版本,直接把sdk(也就是client)中的platform-tools文件夹里的adb.exe复制到安卓模拟器所在路径下,替换模拟器中的adb.exe。

5、命令行输入adb shell报错error: device offline

\color{blue}{解决办法}

adb kill-server
adb start-server
adb shell

6、uiautomator链接问题

import uiautomator2 as u2
d = u2.connect_usb('127.0.0.1:21503')

报错

[W 210326 15:34:25 __init__:203] atx-agent has something wrong, auto recovering
RuntimeError: USB device 10.0.2.15 is offline

devices offline可能是adb版本较低的原因

\color{red}{解决办法:}
经过试验,确实是版本问题,我之前是31版本,现在是40版本。解决。。。

7、报错adbutils.errors.AdbError: unknown host service

运行下列命令,报上面的错

python -m uiautomator2 init```

升级adb版本后,问题解决。。。

8、python -m weditor报错OSError: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。

这个最后也好了,这个error不是很频繁,只出现了一次,解决完其他的error,这个也就自然好了

9、电脑adb devices没有发现模拟器设备list of devices attached

由于我将adb.exe做了更换,没有重启模拟器报错。重启一下安卓模拟器即可。

10、安装uiautomator2一直循环报错

Command errored out with exit status 1: python setup.py egg_info Check the l

解决办法:

pip install --upgrade pip
pip install --upgrade setuptools

11、模拟器上的ATX安装

安装好uiautomator2之后,初始化python -m uiautomator2 init后 模拟器上就自动安装好ATXapp

上一篇 下一篇

猜你喜欢

热点阅读