allure一款測試報告架構,具有以下幾個特點
- allure是一個輕量級,靈活的,支援多語言的測試報告工具;
- java語言開發的,支援pytest,PHP等;
- 可以提供詳細的測試報告,測試步驟,log;
- 可以內建到Jenkins
1.安裝
使用pip指令安裝
pip install allure-pytest
使用pip list檢視是否有該元件
我們使用的windows環境安裝,同時我們下載下傳一個allure-2.7.0.zip的檔案,将其bin目錄配置到環境變量Path中,例如:
在cmd中輸入allure,出現以下界面,即配置成功:
C:\Users\shaem>allure
Usage: allure [options] [command] [command options]
Options:
--help
Print commandline help.
-q, --quiet
Switch on the quiet mode.
Default: false
-v, --verbose
Switch on the verbose mode.
Default: false
--version
Print commandline version.
Default: false
Commands:
generate Generate the report
Usage: generate [options] The directories with allure results
Options:
-c, --clean
Clean Allure report directory before generating a new one.
Default: false
--config
Allure commandline config path. If specified overrides values from
--profile and --configDirectory.
--configDirectory
Allure commandline configurations directory. By default uses
ALLURE_HOME directory.
--profile
Allure commandline configuration profile.
-o, --report-dir, --output
The directory to generate Allure report into.
Default: allure-report
serve Serve the report
Usage: serve [options] The directories with allure results
Options:
--config
Allure commandline config path. If specified overrides values from
--profile and --configDirectory.
--configDirectory
Allure commandline configurations directory. By default uses
ALLURE_HOME directory.
-h, --host
This host will be used to start web server for the report.
-p, --port
This port will be used to start web server for the report.
Default: 0
--profile
Allure commandline configuration profile.
open Open generated report
Usage: open [options] The report directory
Options:
-h, --host
This host will be used to start web server for the report.
-p, --port
This port will be used to start web server for the report.
Default: 0
plugin Generate the report
Usage: plugin [options]
Options:
--config
Allure commandline config path. If specified overrides values from
--profile and --configDirectory.
--configDirectory
Allure commandline configurations directory. By default uses
ALLURE_HOME directory.
--profile
Allure commandline configuration profile.
2.allure用例描述
代碼如下:
import allure
import pytest
@pytest.fixture(scope="session")
def login():
print("用例先登入")
@allure.step("步驟1:點xxx")
def step_1():
print("111")
@allure.step("步驟2:點xxx")
def step_2():
print("222")
@allure.feature("編輯頁面")
class TestEditPage():
'''編輯頁面'''
@allure.story("這是一個xxx的用例")
def test_1(self, login):
'''用例描述:先登入,再去執行xxx'''
step_1()
step_2()
print("xxx")
@allure.story("打開a頁面")
def test_2(self, login):
'''用例描述:先登入,再去執行yyy'''
print("yyy")
第一步:在pycharm的指令行輸入:pytest --alluredir reports testcases/pytest/test_allure.py
reports為儲存報告相關資料的資訊
第二步:執行allure serve reports,浏覽器預設會彈出一個html頁面