AIrtest命令行运行脚本和报告生成

Airtest脚本基于python语言(官方推荐使用python3.5以上的版本运行)。 用python运行airtest脚本时,需要依赖airtest的库。

如果不想看详情,简化版本:

#生成测试日志
airtest run D:\AirtestIDE\firstONe.air (要运行的脚本的绝对路径) –log D:\AirtestIDE\log (日志存放的绝对路径)
#或者:
python -m airtest run D:\AirtestIDE\firstONe.air (要运行的脚本的绝对路径) –log D:\AirtestIDE\log (日志存放的绝对路径)
#生成测试报告
airtest report D:\AirtestIDE\firstONe.air (运行的脚本绝对路径) –log_root D:\AirtestIDE\log\firstONe (刚刚生成的log日志的绝对路径) –outfile D:\AirtestIDE\log\firstONe.html (要生成的html文件的绝对路径) –lang zh --plugins airtest_selenium.report

详情版本:

【python执行airtest的selenium脚本时必备库安装:
pip install pynput
pip install selenium
pip install airtest
使用cmd框就可以安装~
在这里插入图片描述在这里插入图片描述

1. 将airtest IDE目录下的airtest_selenium文件夹拷贝到python安装目录下。
在这里插入图片描述
放到根目录下就可以了。
在这里插入图片描述
2. 在cmd框下使用pip install airtest命令安装airtest (如果安装过就会出现下图:)
在这里插入图片描述

3. 如果运行web自动化脚本,就要将对应浏览器驱动版本程序(比如谷歌的:chromediver.exe)配置在系统环境变量能找到的地方,比如python安装目录下。
4. 通过python -m airtest run 脚本文件名.air 命令,执行脚本 :

C:\Users\AnlyserManxi>python -m airtest run D:\AirtestIDE\firstONe.air --log D:\AirtestIDE\log
do not connect device
save log in 'D:\AirtestIDE\log'

DevTools listening on ws://127.0.0.1:22875/devtools/browser/e12df28d-8b7c-4b02-a154-53f572f32068
[25764:25924:0411/171708.755:ERROR:device_event_log_impl.cc(214)] [17:17:08.754] USB: usb_device_handle_win.cc:1056 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
[25764:25924:0411/171708.780:ERROR:device_event_log_impl.cc(214)] [17:17:08.779] Bluetooth: bluetooth_adapter_winrt.cc:1203 Getting Radio failed. Chrome will be unable to change the power state by itself.
[25764:25924:0411/171708.797:ERROR:device_event_log_impl.cc(214)] [17:17:08.797] Bluetooth: bluetooth_adapter_winrt.cc:1296 OnPoweredRadiosEnumerated(), Number of Powered Radios: 0
this is jpg path: D:\AirtestIDE\log\1618132636.jpg
D:\Download\Python\pythonSetup\lib\site-packages\selenium\webdriver\remote\webdriver.py:1030: UserWarning: name used for saved screenshot does not match file type. It should end with a `.png` extension
  warnings.warn("name used for saved screenshot does not match file "
this is jpg path: D:\AirtestIDE\log\1618132637.jpg
this is jpg path: D:\AirtestIDE\log\1618132638.jpg
this is jpg path: D:\AirtestIDE\log\1618132644.jpg
this is jpg path: D:\AirtestIDE\log\1618132645.jpg
this is jpg path: D:\AirtestIDE\log\1618132655.jpg
this is jpg path: D:\AirtestIDE\log\1618132656.jpg
#略~~~~

或者 airtest run 脚本文件名.air 命令,执行脚本:

airtest run D:\AirtestIDE\firstONe.air --log D:\AirtestIDE\log
do not connect device
save log in 'D:\AirtestIDE\log'

DevTools listening on ws://127.0.0.1:23092/devtools/browser/2f703b87-83ca-492f-acbb-ac10a6c4e17e
this is jpg path: D:\AirtestIDE\log\1618132873.jpg
d:\download\python\pythonsetup\lib\site-packages\selenium\webdriver\remote\webdriver.py:1030: UserWarning: name used for saved screenshot does not match file type. It should end with a `.png` extension
  warnings.warn("name used for saved screenshot does not match file "
this is jpg path: D:\AirtestIDE\log\1618132874.jpg
this is jpg path: D:\AirtestIDE\log\1618132875.jpg
[8928:22336:0411/172116.587:ERROR:device_event_log_impl.cc(214)] [17:21:16.587] USB: usb_device_handle_win.cc:1056 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
[8928:22336:0411/172116.607:ERROR:device_event_log_impl.cc(214)] [17:21:16.607] Bluetooth: bluetooth_adapter_winrt.cc:1203 Getting Radio failed. Chrome will be unable to change the power state by itself.
[8928:22336:0411/172116.623:ERROR:device_event_log_impl.cc(214)] [17:21:16.623] Bluetooth: bluetooth_adapter_winrt.cc:1296 OnPoweredRadiosEnumerated(), Number of Powered Radios: 0
this is jpg path: D:\AirtestIDE\log\1618132880.jpg
this is jpg path: D:\AirtestIDE\log\1618132881.jpg
this is jpg path: D:\AirtestIDE\log\1618132892.jpg
#略~~~~

5. 指定运行日志输出目录,生成测试报告:
在脚本运行时,可以通过–log参数来指定log的输出目录,log会包含运行时的截图和log.txt文件~
通过airtest repot 命令可以生成报告。
air脚本和log文件夹目录必须是绝对路径,不然可能会出现无法找到路径的错误。
设置 --plugin参数是用来指定调用airtest selenium执行插件的。
详情:
airtest report D:\AirtestIDE\firstONe.air (运行的脚本绝对路径) –log_root D:\AirtestIDE\log\firstONe (刚刚生成的log日志的绝对路径) –outfile D:\AirtestIDE\log\firstONe.html (要生成的html文件的绝对路径) –lang zh --plugins airtest_selenium.report

airtest report  D:\AirtestIDE\firstONe.air --log_root D:\AirtestIDE\log\firstONe --outfile D:\AirtestIDE\log\firstONe.html --lang zh --plugins airtest_selenium.report
[17:32:59][DEBUG]<airtest.report.report> try loading plugin: airtest_selenium.report
[17:32:59][INFO]<airtest.report.report> D:\AirtestIDE\log\firstONe.html

然后就可以在(刚刚设置的html文件的绝对路径)下找到对应的html文件,双击打开就可以看到测试报告 了~

我们可以设置一个定时程序,定时执行这一段脚本:

创建一个txt文件,在文件中写入刚刚在cmd框中执行的命令
在这里插入图片描述
然后保存,并重命名为.bat文件
在这里插入图片描述
双击可以正常运行。
找到计算机或此电脑,右键选择管理。
在这里插入图片描述
选择任务计划程序,右边选择创建基本任务
在这里插入图片描述
输入名称后,选择下一步,选择任务运行周期,点击下一步后可以设置具体的时间
在这里插入图片描述
选择下一步
在这里插入图片描述
选择操作,下一步,选择刚刚创建的bat文件
在这里插入图片描述
点完成就好了~
在这里插入图片描述
然后就可以在任务计划程序——》任务计划程序库下就可以找到刚刚的定时程序了
在这里插入图片描述不想要了可以点击右侧的所选项下的禁用或删除
好了,到这就结束了,让我们为这么有耐心查看到最后的自己点个赞~~~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值