日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

Httprunner簡介、安裝及基本使用教程_python

作者:愛學(xué)習(xí)de測試小白 ? 更新時(shí)間: 2022-04-20 編程語言

前言

本系列文章開始介紹接口開源測試工具 --httprunner3的使用,基當(dāng)前最新版本的3.1.6

簡介

主要特點(diǎn)

HttpRunner 是一款面向 HTTP(S) 協(xié)議的通用測試框架,只需編寫維護(hù)一份 YAML/JSON 腳本,即可實(shí)現(xiàn)自動(dòng)化測試、性能測試、線上監(jiān)控、持續(xù)集成等多種測試需求。

繼承所有強(qiáng)大的特性requests,享受人性化處理 HTTP(S) 的樂趣。以 YAML 或 JSON 格式定義測試用例,pytest以簡潔優(yōu)雅的方式運(yùn)行。在支持下記錄和生成測試用例HAR。支持///variables機(jī)制來創(chuàng)建極其復(fù)雜的測試場景extract。validatehooks使用debugtalk.py插件,任何功能都可以在測試用例的任何部分使用。使用jmespath,提取和驗(yàn)證 json 響應(yīng)從未如此簡單。有了pytest,數(shù)百個(gè)插件隨時(shí)可用。使用allure,測試報(bào)告可以非常漂亮和強(qiáng)大。通過重用locust,您無需額外工作即可運(yùn)行性能測試。支持 CLI 命令,與CI/CD

說明 需要Python3.6+

Httprunner2.x和3.x區(qū)別

  • 執(zhí)行用例框架:3.x 是pytest;2.x是unitest
  • 用例格式:3.x支持YAML/JSON/pytest;2.x支持YAML/JSON

安裝

  • 需要python3.6+環(huán)境:可參考 python環(huán)境搭建
  • 使用pip

安裝

pip3 install httprunner

也可使用github 源碼安裝

pip3 install git+https://github.com/httprunner/httprunner.git@master

如果之前安裝HttpRunner可以使用-U選項(xiàng),升級到最新版本

pip3 install -U httprunner
# 或
pip3 install -U git+https://github.com/httprunner/httprunner.git@master

查看版本

pip show httprunner

相關(guān)命令

查看幫助

httprunner -h

參數(shù)名 功能
-V --version 查看版本號
-h, --help 查看幫助
run 用于運(yùn)行YAML/JSON/Pytest 測試用例
startproject 使用模板結(jié)構(gòu)創(chuàng)建新項(xiàng)目
har2case HAR(HTTP Archive) 轉(zhuǎn)成 YAML/JSON
make YAML/JSON 測試用例轉(zhuǎn)成 pytest用例

安裝 HttpRunner 后,以下 5 個(gè)命令會寫入系統(tǒng)環(huán)境變量配置。

  • httprunner:主命令,用于所有功能。
  • hrun:指令 httprunner run 的別名,用于運(yùn)行 YAML/JSON/Pytest 測試用例。
  • hmake: 指令 httprunner make 的別名,將 YAML/JSON 用例轉(zhuǎn)換成 pytest 用例。
  • har2case:指令 httprunner har2case 的別名,將 HAR 文件轉(zhuǎn)換成 YAML/JSON 用例。
  • locust:利用 locust 運(yùn)行性能測試。

基本使用

創(chuàng)建項(xiàng)目

httprunner startproject 項(xiàng)目名

httprunner startproject  dahai_demo  

make轉(zhuǎn)pytest用例

make 是把 YAML/JSON 測試用例轉(zhuǎn)成 pytest用例, 需指定 yaml 文件路徑或文件夾路徑

httprunner make testcase 
 # 等價(jià)于 
 hmake testcase

run 運(yùn)行用例

run 命令實(shí)際上有 2 個(gè)動(dòng)作,一個(gè)是把 YAML/JSON 測試用例轉(zhuǎn)成 pytest 用例,同上一步 make 的功能一樣;第二個(gè)動(dòng)作是用 pytest 執(zhí)行測試用例

httprunner run testcases
# 等價(jià)于
hrun testcase

原文鏈接:https://blog.csdn.net/IT_heima/article/details/122825791

欄目分類
最近更新