框架:python+uiautomator2+pytest
搭建环境
python
1.安装pycharm
2.python插件:allure-2.13.5 【我放在python目录下了,需要设置环境变量】
3.pip install uiautomator2 【安卓Android平台的自动化测试,开源工具】
4.pip install pillow 【安装图像处理器】
5.Java环境,安装jdk,配置环境变量,目前装的是jdk22
adb【Android SDK】
安装 setuptools,pip install setuptools
安装 weditor,pip install weditor==0.6.4,运行python -m weditor
安装atx-agent
下载zip完整的Android SDK
配置环境变量
查看版本,验证安装成功
直接在当前目录下输入cmd,回车
输入adb version 查看安装的adb的版本和目录
也可以直接打开cmd,在默认目录下输入adb version 进行查看
元素定位weditor
weditor是基于web网页端调试,安装前检查setuptools是否已经装好,pip show setuptools
一下检查,没装好的话 pip install setuptools;
安装weditor
当前 python 版本 3.12.5,但是直接 pip install -U weditor 时,报 UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xad in position 795: illegal multibyte,python版本已是当前最高,没有去细究;直接安装了指定版本 pip install weditor==0.6.4 ,安装成功;
weditor --help 查看安装好的weditor;
安装 weditor 报错的话,还有第二种方法:先git clone https://github.com/openatx/weditor,下载源码 再 pip3 install -e weditor,但是我没有尝试;
创建快捷方式:weditor --shortcut
后续使用的时候直接在桌面打开就好啦
启动weditor
在命令行运行 python -m weditor ,跳转到 http://localhost:17310/ 即为安装成功,命令行和页面如下图所示:【装了快捷键以后用快捷键就好啦】
设备&电脑连接
【代理和抓包要关掉】
1.用数据线将手机和电脑连接,打开手机上“开发者选项”
2.在cmd输入adb devices列出连接的设备
unauthorized:指没有权限,需要手动在设备上进行配置【华为平板在选择USB配置时,选择音频来源,执行adb devices时设备弹框需要给予权限】
device:在线可用
运行 python -m weditor
3.将获取的设备序列号输入在浏览器Weditor中并connect,开始自动安装ATX到该手机上;如果系统中的adb无法识别,则手动执行 python -m uiautomator2 init,设备上有atx小车图标显示时,表示初始化成功,或直接在poycharm里运行代码
4.打开ATX,里面有ip,在weditor里输入ip能连接上啦
5.如果断开再重连的,kill掉devcies,重新连接