airtest之命令方式执行全攻略

原创: George555    公众号: 测试江湖路  

如果这些内容对你有帮助,也可以打开微信扫一扫,加关注:

 

    引言:本文将介绍怎么使用命令方式执行.air文件,各种命令集合使用全在这里,而且配有案例使用。

一、airtest包含的三大基础命令 run、info、report

    用airtest -h 或airtest --help查询下全部命令.

    使用的主要命令有:run/info/report/help

    airtest run:运行.air脚本

    airtest info:获取脚本中 author/title/desc的信息

    airtest report:生成脚本的报告

    airtest -h或airtest --help:显示帮助信息

二、用airtest run -h 查询下run的使用命令参数

    使用参数: airtest run [-h] [--device [DEVICE]] [--log [LOG]]

                       [--recording [RECORDING]]

                       script

    airtest run  -h 或airtest --help:显示帮助信息

    airtest run --device [DEVICE] :设备连接,如:--device Android:///

    airtest run --log [LOG]:设置日志目录,未设置的默认当前脚本目录

   airtest run --recording [RECORDING]:运行时录制屏幕,如:--recording

    airtest run  script:脚本文件

    【完整示例】:

airtest run airCase1.air --device Android://127.0.0.1:5037/Y2J5T1781500?cap_method=JAVACAP^&^&ori_method=ADBORI^&^&touch_method=ADBTOUCH --log .\log --recording

    【含义】:在Y2J5T1781500设备上运行airCase1.air脚本,在当前目录的log目录下生成日志,且执行脚本过程中对屏幕录屏,最后保存到log日志目录下。

    【特殊说明】:run命令中支持多个device去执行.air脚本,如果在命令行写多个--device,请注意在代码中用set_current(index) 去切换不同设备device的url。比如:

 airtest run airCase1.air --device Android://1 --device Android://2

    这样默认执行只会去执行Android://2设备,如果要执行设备1,必须在脚本代码中加set_current(0),这样实现多个设备切换。代码如下:

    当然,这样也可以实现循环遍历去执行多台设备脚本,比如:

三、用airtest info -h或airtest info --help 查询下info 的使用命令参数

    使用案例: airtest info test.air 获取test.air中的author/title/desc的信息

四、用airtest report -h 查询下report 的使用命令参数

    使用参数:  

    airtest report [-h] [--outfile OUTFILE] [--static_root STATIC_ROOT]

                     [--log_root LOG_ROOT] [--record RECORD [RECORD ...]]

                     [--export EXPORT] [--lang LANG]

                     [--plugins PLUGINS [PLUGINS ...]] [--report [REPORT]]

                     script

    airtest report -h或airtest report --help:显示帮助信息

    airtest report --outfile OUTFILE:输出html测试报告文件,未指定文件名默认log.html

    airtest report --static_root STATIC_ROOT:测试报告静态文件资源根目录,可以是远端静态文件服务器地址,配置报告远端访问地址,避免每次生成报告传输到对应机器时浪费宽带流量。这里引用下官方说法:

    ####可以使用 --static_root 静态资源目录 参数,来指定静态资源文件的路径(即报告中的css, js等文件)。我们可以将资源文件部署到静态资源文件服务器上,用例如 https://host:port/static/css/ 的路径来访问它,然后在生成报告时,将这个部署出来的服务器地址作为 --static_root 的参数传过去,这样报告中会默认去访问这个URL读取静态资源文件,避免导出报告时重复拷贝这些资源文件造成的磁盘空间占用。####

    airtest report --log_root LOG_ROOT:运行报告后的log和截图、录屏根目录,即上面第二节中的\log,因为生成报告需要依赖这个log目录的文件内容

    airtest report --record RECORD [RECORD ...] :自定义屏幕录制文件路径

    airtest report --export EXPORT :导出包含所有资源的可移植报表目录

    airtest report --lang LANG   :报告语言设置,默认英文en ,中文:zh

    airtest report --plugins PLUGINS [PLUGINS ...] :  加载报告插件,如selenium或poco报告插件

    airtest report --report [REPORT]     报表命令占位符

    【示例1】:在二中执行完的log日志目录下根据已有图片、视频和log.txt生成log.html报告,且为中文

airtest report airCase1.air --log_root log/ --outfile log.html --lang zh

--log_root log/:指定日志目录是log

--outfile log/log.html:指定输出html报告文件目录是log下的log.html

--lang zh:报告使用中文方式显示

    【示例2】: --export

airtest report airCase1.air --log_root log --outfile log.html --lang zh --export exportDir

--export exportDir :导出测试报告(日志、图片、静态文件、视频等)到当前目录的exportDir 目录下,加了此参数,最后的log.html就会在exportDir\airCase1.log下生成log.html。

    【示例3】: --static_root

airtest report airCase1.air --log_root log --outfile log.html --lang zh --export exportDir --static_root http://127.0.0.1:8888/test

--static_root http://127.0.0.1:8888/test:设置静态资源文件访问服务器地址,设置后生成的报告log.html内容如下:

    【示例4】: --record

    airtest report airCase1.air --log_root log --outfile log.html --lang zh --export exportDir --static_root http://127.0.0.1:8888/static --record recording_0.mp4 recording_1.mp4

    --record recording_0.mp4 recording_1.mp4 :设置录制的视频资源,如果运行日志airtest run --log 目录有多个视频,可添加多个,最后在log.html报告中就会看到多个。

    【示例5】:报告插件使用,例如接入poco报告命令:

    airtest report airCase1.air --log_root log --outfile log.html --lang zh --export exportDir --plugins poco.utils.airtest.report

    --plugins poco.utils.airtest.report:结合poco报告插件生成对应poco的报告,如果代码中有poco代码,报告中会显示

    也可以接入selenium报告:

    airtest report test.air --plugins airtest_selenium.report

    【备注】:生成report之前必须先run,生成log.txt文件才可以出报告。

五、不同平台,多设备命令使用

    最后需要注意的是,如果命令行中有出现 ^ < > | &  等字符,则需要转义

    Windows环境下:注意加 ^

airtest run airCase1.air --device Android://127.0.0.1:5037/127.0.0.1:62001?cap_method=JAVACAP^&^&ori_method=ADBORI^&^&touch_method=ADBTOUCH

    Mac环境下:注意加 \

airtest run airCase1.air --device Android://127.0.0.1:5037/79d03fa?cap_method=JAVACAP\&\&ori_method=ADBORI  # mac命令行添加\转义

 

最后帖一张生成的报告截图:

 

 

 

 

#####欢迎大家加群交流####

QQ:464314378

微信群请先加群主微信,群主会拉各位小伙伴进群,注意添加备注。

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值