工欲善其事,必先利其器,在盲目的入门教程遍历后,诉求逐步明朗,不是在IDE里跑脚本,而是要一种能在命令行里运行自定义参数的脚本方式,所以airtest官网安装只是基础。而且在官方IDE跑了几个github上的demo脚本后,官方IDE的短板逐步显露,自定义python插件才是归宿。
建议安装3.8版本,3.7安装插件报错,提示要升级pip;官网下载win可执行程序3.8版本,配上把环境变量都设置好了,省事。
pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com airtest
pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com pocoui
pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com openpyxl
两种方式:
airtest run "D:\qasite.air" --device "android://127.0.0.1:5037/65fade15?cap_method=JAVACAP&&ori_method=MINICAPORI&&touch_method=MINITOUCH" --log "D:\log" --compress 90 --recording qasite.mp4
python launcher.py xianyu.air --device android:///L4SDU18A16000399
如果每次需要传入不同的参数控制脚本的运行,那么就需要用启动器,启动器也是普通的py文件,有固定的模板,可以加入参数解析
from airtest.cli.runner import AirtestCase, run_script
from airtest.cli.parser import runner_parserclass CustomAirtestCase(AirtestCase):def setUp(self):# 在air脚本运行之前获取这个自定义的参数if self.args.name:self.scope['name']=self.args.nameif self.args.count:self.scope['count']=self.args.countif __name__ == '__main__':ap = runner_parser()# 添加自定义的命令行参数ap.add_argument("--name", help="The product name ready to search")ap.add_argument("--count", help="The product count to search")args = ap.parse_args()run_script(args, CustomAirtestCase)
在air脚本中,就可以直接使用name和count这两个变量了,使用启动器后,run命令可以加参数:
python launcher.py xianyu.air --device android:///L4SDU18A16000399 --name 8259u --count 50
语法跟随python,利用缩进来控制代码块作用域;
正则表达式在字符串处理中很有用,也是爬虫的基本素质
python也有try catch
poco是基本的ui元素交互工具,实测发现对付xianyu还是力不从心,flutter框架本身就复杂,而且里面加入了一些反爬的逻辑
列举一些常用的函数