1. 程式人生 > 其它 >httprunner3.x詳細教程一(框架結構介紹及搭建)

httprunner3.x詳細教程一(框架結構介紹及搭建)

1、環境準備

安裝httprunner

pip install httprunner -i https://pypi.douban.com/simple

使用hrun -V 檢視httprunner版本,我的是3.1.4

檢視幫助資訊:httprunner --help

positional arguments:

{run,startproject,har2case,make}

sub-command help

run Make HttpRunner testcases and run with pytest.執行httprunner檔案

startproject Create a new project with template structure.建立httprunner專案結構

har2case Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner.轉換har檔案為yml檔案或者json檔案或者pytest檔案

make Convert YAML/JSON testcases to pytest cases. 轉換yml或json檔案為pytest檔案

optional arguments:

-h, --help show this help message and exit 檢視幫助資訊

-V, --version show version 檢視版本

2、建立專案

cmd到專案檔案下執行:httprunner startproject interfacedemo(interfacedemo是你的介面專案名稱)

使用pycharm開啟interfaceDemo:

各個目錄代表的含義:

debugtalk.py 放置在專案根目錄下(借鑑了pytest的conftest檔案的設計)
.env 放置在專案根目錄下,可以用於存放一些環境變數
reports 資料夾:儲存 HTML 測試報告
testcases 用於存放測試用例
har 可以存放錄製匯出的.har檔案
.gitignore 設定上傳到git時需要忽略那些檔案資訊
執行官方提供的小例子:

在testcases下,有兩個yml檔案,在專案interfaceDemo的上級目錄執行:

兩種執行方式:

1、hrun interfaceDemo:命令等價於httprunner run interfaceDemo,其中先進行httprunner make json/yml,會將json/yml檔案先轉換為pytest檔案,之後再執行hrun(httprunner run),如果pytest檔案是已經存在的(你直接編寫的pytest檔案,而不是yml或者json),httprunner會直接執行你的pytest指令碼,不需要進行轉換,官方推薦:直接使用pytest指令碼編寫

在tacecases目錄下生成了三個py檔案,生成的py檔案會加上_test字尾,如果yml或者json檔案有修改,需要再次http make scriptPath一下,或者直接修改py檔案

生成了logs日誌檔案,每一個yml都會對應生成一個日誌檔案如下,每一個testcase指令碼都會又要給唯一的id,對應了日誌檔案的檔名:

2、pytest interfaceDemo(前提,已經使用hrun interfaceDemo生成了yml或json對應的pytest檔案,否則不生效)