【python學(xué)習(xí)】11.Allure生成測(cè)試報(bào)告

allure介紹

其能量計(jì)、靈活的、支持多語言的測(cè)試報(bào)告共計(jì)
多平臺(tái)的、奢華report框架
可以為dev/qa提供詳盡的測(cè)試報(bào)告、測(cè)試步驟、log
也可以為管理層提供highlevel統(tǒng)計(jì)報(bào)告
java語言看法,支持pytest、JavaScript、PHP
可集成到Jenkins

allure安裝

--需要先安裝jdk
下載,安裝,添加環(huán)境變量

jdk環(huán)境變量

添加到path中

安裝地址
下載包后解壓-進(jìn)入bin目錄-運(yùn)行allure.bat
把bin目錄加入Path環(huán)境變量
官方文檔 | 幫助文檔
在python 環(huán)境中安裝中安裝 allure-pytest

Allure常用特性

在測(cè)試報(bào)告中看到測(cè)試功能、子功能或場(chǎng)景、測(cè)試步驟、測(cè)試附加消息

測(cè)試類

import allure


# allure 定義模塊
@allure.feature('登錄模塊')
class TestLogin():
    # allure定義登錄成功
    @allure.story('登錄成功')
    def test_login_success(self):
        # 在測(cè)試用例中添加步驟
        with allure.step('步驟1:  diyibugaisha'):
            print('這里是步驟1')
        with allure.step('步驟2:abcddefegji'):
            print('這里是步驟2')
        with allure.step('這里是步驟3:hijklmnopqrstu'):
            print('這里是步驟3')
        print('登錄模塊,測(cè)試用例:登錄成功')
        pass

    @allure.story('登錄失敗')
    def test_login_fail(self):
        print('登錄模塊,測(cè)試用例:登錄失敗')

    @allure.story('登錄缺失用戶名')
    def test_login_nullname(self):
        print('登錄模塊,測(cè)試用例:缺失用戶名')

    @allure.story('登錄缺失密碼')
    def test_login_nullname(self):
        print('登錄模塊,測(cè)試用例:缺失密碼')

@allure.feature('搜索模塊')
class TestSearch():
    @allure.story('全量搜索')
    def test_none_key(self):
        print('空值全量搜索')

    @allure.story('精準(zhǔn)搜索')
    def test_has_key(self):
        print('精準(zhǔn)搜索關(guān)鍵字')

在terminal里查詢pytest 中allure 的方法
pytest --help|findstr allure

運(yùn)行某個(gè)模塊,并查看詳細(xì)日志
pytest test_ch0722.py --allure-features="搜索模
塊" -vs

運(yùn)行storypytest test_ch0722.py --allure-stories="登錄失
敗" -vs

執(zhí)行并生成報(bào)告
pytest test_ch0722.py --allure-stories="登錄成
功" -vs --alluredir=./result

啟動(dòng)服務(wù)并在瀏覽器查看報(bào)告
allure serve ./result

allure特性分析

按照重要性級(jí)別進(jìn)行一定范圍測(cè)試

  • 通過pytest.mark標(biāo)記
  • 通過allure.feature,allure.story
  • 也可以通過allure.severity附加標(biāo)記
    • 級(jí)別:Trivial:不重要、Minor不太重要,Normal正常問題Critical嚴(yán)重,Blocker阻塞
      給方法、類添加級(jí)別
import allure
def test_with_no_severity():
    pass

@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_1_severity():
    pass
# 在測(cè)試用例中,添加title
@allure.title('第5條測(cè)試用例')
@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_2_severity():
    pass

@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_1_severity():
    pass

@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_2_severity():
    pass

@allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object):

    def test_isside_the_normal_severity_test_class(self):
        pass
    @allure.severity(allure.severity_level.CRITICAL)
    def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
        pass
  • 在測(cè)試中添加截圖

  • 使用級(jí)別運(yùn)行用例: pytest test_ch0722_2.py --allure-severities="normal" -vs

  • 在pycharm使用allure執(zhí)行


    pycharm配置用allure執(zhí)行

allure運(yùn)行

allure報(bào)告中嵌入文本、圖片、視頻資源

    # 在測(cè)試用例中添加文本
def test_attach_text():
    allure.attach('這是一個(gè)純文本', attachment_type=allure.attachment_type.TEXT)

    # 在測(cè)試用例中添加html
def test_attach_html():
    allure.attach("<body>這是一段htmlbody塊</body>", 'html測(cè)試塊', attachment_type=allure.attachment_type.HTML)
    # 在測(cè)試用例中添加圖片
def test_attach_photo():
    allure.attach.file('D:\\testpic\\1.jpg', name='這是一個(gè)圖片', attachment_type=allure.attachment_type.JPG)
    # 在測(cè)試用例中添加視頻
def test_attach_video():
    allure.attach.file('D:\\testpic\\testmp4_01.mp4', name='這是一個(gè)視頻',
                       attachment_type=allure.attachment_type.MP4)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容