
-
在IDE中一鍵生成、導出報告 -
用命令行生成、導出報告 -
在腳本中生成、導出報告
生成報告css
查看報告
按鈕(快捷鍵Ctrl+L),便可快速生成並在瀏覽器中打開html格式的報告:

打開報告文件目錄
:

查看報告
按鈕的同時,log查看窗會出現1條生成報告的命令(這條命令很是重要,下文咱們也會講到):

--outfile
參數,咱們也能夠知道報告所在的本地文件路徑。


導出報告html
導出報告
,以後再選擇導出報告的存放路徑便可:


生成報告失敗python

poco
和
pocoui
(卸載 poco ,僅保留 pocoui ),這兩個庫衝突致使生成報告失敗。
airtest
和
pocoui
庫的精簡python環境(注意是
pocoui
,不是
poco
,若已經安裝了
poco
,則須要卸載,不然會跟
pocoui
有衝突)。
airtest
和
pocoui
,使用
pip list
指令便可查看。
pip install airtest
pip install pocoui
運行腳本:airtest run ...web
airtest run + 腳本文件路徑
,另外該命令還能夠傳入如下幾個參數:
-
--device
,用來指定鏈接的被測設備 -
--log
,用來指定log內容和截圖存放的目錄 -
--recording
,運行腳本時進行錄屏操做
airtest run D:/test/report_test.air --device Android:/// --log C:/Users/xiaoming/log --recording
生成報告:airtest report ...瀏覽器
airtest report + 腳本文件路徑
指令來生成一份HTML格式的報告。
-
--log_root
,指定log內容和截圖文件所在的目錄 -
--outfile
,指定生成報告的目錄 -
--lang
,指定報告語言,能夠是中文/英文 -
--export
,導出一個包含全部資源的報告文件 -
--static_root
,指定靜態資源文件的路徑
airtest report D:/test/report_test.air --log_root C:/Users/xiaoming/log --outfile E:/log_test/log.html --lang zh
查看報告
按鈕的時候,log查看窗會相應地出現1條生成報告的命令,咱們也能夠複製該命令到命令行中運行,也可以幫助咱們生成報告。
導出報告:--export ...服務器
--export
生成的報告,與IDE點擊查看報告按鈕生成的報告是同樣的,只能在本地查看,不能發到別的電腦上查看。
--export
參數:
# 使用了export參數,outfile參數會失效,因此使用了export參數就能夠不使用outfile
airtest report D:/test/report_test.air --log_root C:/Users/xiaoming/log --lang zh --export E:/log_test/

靜態資源:--static_root ...微信
static
,它包含了報告中的css和js等文件,這樣的重複拷貝佔用了不少的磁盤空間。而且咱們知道,除非報告的樣式作了某些更新,不然這些靜態資源文件都是固定不變的。
--static_root
參數便可實現!咱們能夠將這些資源文件部署到靜態資源文件服務器上,用例如
https://host:port/static/css/
的路徑來訪問它。而後在生成報告時,將這個部署出來的服務器地址做爲
--static_root
的參數傳過去:
airtest report D:/test/report_test.air --log_root C:/Users/xiaoming/log --lang zh --static_root https://host:port --export E:/log_test/
--static_root
的參數須要以
http
開頭才能被識別:

simple_report()
接口或者
LogToHtml()
類來實現。
simple_report :生成報告app
simple_report
接口,它實際上是1個簡化版的生成報告的接口,能夠減小同窗們的理解成本和使用成本:

output='log.html'
表示在當前腳本路徑下生成名爲
log.html
的airtest報告:
from airtest.report.report import simple_report
simple_report(__file__)

output
參數,則會按指定路徑生成報告:
from airtest.report.report import simple_report
simple_report(__file__,logpath=True,output=r"D:\test\report02\log.html")


LogToHtml:導出報告less
simple_report
接口便可。
LogToHtml
類:

simple_report()
就複雜的多了,包含:
-
script_root
,腳本路徑 -
log_root
,log文件的路徑 -
static_root
,部署靜態資源的服務器路徑 -
export_dir
,導出報告的存放路徑 -
script_name
,腳本名稱 -
logfile
,log文件log.txt的路徑 -
lang
,報告的語言(中文:zh;英文:en) -
plugins
,插件,使用了poco或者airtest-selenium會用到
D:\test\report02
中導出了
D:\test\report01.air
腳本的運行報告,報告語言爲英文:
from airtest.report.report import LogToHtml
h1 = LogToHtml(script_root=r'D:\test\report01.air', log_root=r"D:\test\report01.air\log", export_dir=r"D:\test\report02" ,logfile=r'D:\test\report01.air\log\log.txt', lang='en', plugins=None)
h1.report()


try-finally:保證最後都能生成報告編輯器
try-finally
語句,不論腳本是否運行失敗,最終都會生成1份運行報告:
try:
poco("com.netease.newsreader.activity:id/bjd").wait_for_appearance()
poco("com.netease.newsreader.activity:id/awo").click()
...
finally:
simple_report(__file__,logpath=True,output="../netease_music/登陸.html")
print("-----執行完畢-----")

本文分享自微信公衆號 - AirtestProject(AirtestProject)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。