前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Airtest IDE 自动化测试17 - 命令行运行 airtest 脚本

Airtest IDE 自动化测试17 - 命令行运行 airtest 脚本

作者头像
上海-悠悠
发布2021-06-25 00:03:06
1.1K0
发布2021-06-25 00:03:06
举报
文章被收录于专栏:从零开始学自动化测试

前言

Airtest IDE 自带了python3 环境,但是每次执行脚本都需要打开IDE,在IDE 上点运行按钮才能执行。 如果我们想通过命令行执行脚本,可以在本机安装python3

环境准备

安装python3 环境和pip,这个不多说,我用的python3.6环境

代码语言:javascript
复制
C:\Users\dell>python
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

pip 安装 Airtest 库

代码语言:javascript
复制
C:\Users\dell>pip install airtest --index-url https://pypi.douban.com/simple

C:\Users\dell>pip show airtest
Name: airtest
Version: 1.1.11
Summary: UI Test Automation Framework for Games and Apps on Android/iOS/Windows/Linux
Home-page: https://github.com/AirtestProject/Airtest
Author: Netease Games
Author-email: gzliuxin@corp.netease.com
License: Apache License 2.0
Location: e:\python36\lib\site-packages
Requires: Jinja2, Pillow, requests, six, mss, numpy, opencv-contrib-python, facebook-wda, pywinauto, pywin32
Required-by:

pip 安装 poco 框架 ,库名是pocoui

代码语言:javascript
复制
C:\Users\dell>pip install pocoui --index-url https://pypi.douban.com/simple

C:\Users\dell>pip show pocoui
Name: pocoui
Version: 1.0.82
Summary: Poco cross-engine UI automated test framework.
Home-page: https://github.com/AirtestProject/Poco
Author: Netease Games
Author-email: lxn3032@corp.netease.com, gzliuxin@corp.netease.com
License: Apache License 2.0
Location: e:\python36\lib\site-packages
Requires: six, requests, airtest, hrpc, websocket-client
Required-by:

安装了airtest 和 pocoui 后就可以不用 AirtestIDE, 自己写python脚本,运行脚本了。

命令行参数

AirtestIDE 上运行脚本后,查看日志

代码语言:javascript
复制
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/

"D:\soft\Airtest\AirtestIDE\AirtestIDE" runner "D:\airtest_code\a4.air"  --device android://127.0.0.1:5037/emulator-5554?cap_method=JAVACAP&&ori_method=MINICAPORI&&touch_method=MINITOUCH --log "C:\Users\dell\AppData\Local\Temp\AirtestIDE\scripts\fb0e431ec500b363a99cf53d431f4afc"

运行可以知道运行脚本的命令格式

AirtestIDE runner 脚本.air —device android://127.0.0.1:5037/emulator-5554(手机设备) —log 指定日志保存路径

参数说明:

  • AirtestIDE AirtestIDE执行命令行工具
  • runner 需运行的脚本,后面参数指定脚本地址,格式是x.air目录的格式
  • —device host是adb server所在主机的ip,默认是本机127.0.0.1,adb port默认是5037,后面是android手机的序列号,adb device查看到的
  • —log 指定日志保存路径

本地 python3 安装完 airtest 库后,可以用airtest 命令代替 AirtestIDE, run 指令代替 runner.

代码语言:javascript
复制
C:\Users\dell>airtest
usage: airtest [-h] {version,run,info,report} ...
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/

positional arguments:
  {version,run,info,report}
                        version/run/info/report
    version             show version and exit
    run                 run script
    info                get & print author/title/desc info of script
    report              generate report of script

optional arguments:
  -h, --help            show this help message and exit

运行.air 脚本

运行脚本和生成 html 报告是2个步骤,cd到脚本所在的目录

run 运行脚本

代码语言:javascript
复制
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/

D:\airtest_code>airtest run a4.air --device android://127.0.0.1:5037/emulator-5554 --log ./log

运行完成后,在当前脚本目录会生成一个log文件夹,log.txt记录测试运行的结果

生成 html 报告

生成测试报告用 report 命令

代码语言:javascript
复制
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/

D:\airtest_code>airtest report a4.air --log_root ./log --outfile ./log/log.html --lang zh
[23:23:22][INFO]<airtest.report.report> ./log/log.html

参数说明:

  • report 指定运行脚本生成报告
  • —log_root 指定log文件命令
  • —outfile 指定log.html 文件存放地方
  • —lang zh是报告显示中文

查看报告

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-06-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 环境准备
  • 命令行参数
  • 运行.air 脚本
  • 生成 html 报告
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档