前言
Airtest IDE 自帶了python3 環境,但是每次執行腳本都需要打開IDE,在IDE 上點運行按鈕才能執行。
如果我們想通過命令行執行腳本,可以在本機安裝python3
環境准備
安裝python3 環境和pip,這個不多說,我用的python3.6環境
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 庫
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
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 上運行腳本后,查看日志
# 作者-上海悠悠 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.
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 運行腳本
# 作者-上海悠悠 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 命令
# 作者-上海悠悠 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是報告顯示中文
查看報告