uiautomator2巨坑

uiautomator2巨坑

windows安装相关包:

1
pip install --pre uiautomator2

这里安装雷电模拟器,这里要记住,要用雷电模拟器自带的adb

1
where adb

img

启动雷电模拟器,开启开发者选项,以及USB调试,以及配置下模拟器IP地址。img

重启下adb

1
2
3
adb kill-server

adb start-server

img

再查询是否检测到设备:

1
adb devices

查询到了,再安装ATX。

1
python -m uiautomator2 init

安装完后,会有这个图标:

img

点开他,按下:img

发现启动不了。

这里直接进入shell,操作手机,进行打开。

1
2
3
4
5
adb shell

chmod 775 /data/local/tmp/atx-agent

/data/local/tmp/atx-agent server -d (添加-d表示在后台动)

这样就打开了。不会提示Uiautomator not starting

下面安装weditor

1
pip install --pre -U weditor

然后启动

1
weditor

img

注意遇到的天坑:

1.weditor连不上

今天因业务需求需要用到 uiautomator2 和 webitor, 但是在下载webitor 的时候一直报错, 在网上差了1个小时也没搞定,
最后找到了解决办法, 指定版本下载

1
pip install weditor==0.6.4

结果,安装是成功了, 但是因为版本冲突,链接不上手机,白费, 继续找方法- -
最后的最后 让我成功解决了,浪费劳资将近2个小时。。。

git clone https://github.com/openatx/weditor,下载源码 再 pip3 install -e weditor

2.不显示安装的atx

一、python -m uiautomator2 init,报错:由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败;尝试手动安装

1
https://github.com/openatx/atx-agent/releases

1.访问该网站,下载以linux_armv7.tar.gz结尾的二进制包

2.解压出atx-agent文件

img

二、控制台输入:

1
2
3
4
5
6
7
8
#push 到手机指定路径下
adb push D:/download/atx-agent_0.10.0_linux_armv7atx-agent/atx-agent /data/local/tmp
#授权
adb shell chmod 755 /data/local/tmp/atx-agent
#安装后查看版本号
adb shell /data/local/tmp/atx-agent server -d
#启动后台运行
adb shell /data/local/tmp/atx-agent server -d --stop

三、uiautomator2版本匹配的apk

PS:uiautomator2版本匹配可以在pip安装的uiautomator2的目录下有个versiopn.py的文件里

1
https://github.com/openatx/android-uiautomator-server/releases

img

1.访问网址下载对应版本app-uiautomator.apk、app-uiautomator-test.apk进行安装

1
2
adb install app-uiautomator.apk
adb install app-uiautomator-test.apk

2.再次执行python -m uiautomator2 init 成功安装