allure測試報告(3): allure測試報告的用例描述設置


allure測試報告的用例描述相關方法;如下圖

 

allure標記用例級別severity

在做自動化測試的過程中,測試用例越來越多的時候,如果執行一輪測試發現了幾個測試不通過,我們也希望能快速統計出缺陷的等級。

pytest結合allure框架可以對用例的等級做詳細的划分。

allure對用例的等級划分成五個等級:

  • blocker 阻塞缺陷(功能未實現,無法下一步)
  • critical 嚴重缺陷(功能點缺失)
  • normal 一般缺陷(邊界情況,格式錯誤)
  • minor 次要缺陷(界面錯誤與ui需求不符)
  • trivial 輕微缺陷(必須項無提示,或者提示不規范)

寫法一:

@allure.severity("blocker")
@allure.severity("critical")
@allure.severity("normal")
@allure.severity("minor")
@allure.severity("trivial")

寫法二:

@allure.severity(allure.severity_level.Blocker)
@allure.severity(allure.severity_level.critical)
@allure.severity(allure.severity_level.normal)
@allure.severity(allure.severity_level.Minor)
@allure.severity(allure.severity_level.Trival)

如果想根據用例等級去執行用例可以使用下面的參數:

 allure命令行參數allure-severities

pytest --alluredir=./report/allure --allure-severities=blocker

pytest --alluredir=./report/allure --allure-severities=blocker,critical

執行代碼如下:

import os
import pytest
# 根據優先級過濾 --allure-severities=blocker,normal
pytest.main(['-s','-v','--alluredir=./allure_json_path','--clean-alluredir','--allure-severities=blocker'])
os.system('allure generate %s -o %s --clean'%('./allure_json_path','./allure_html_path'))

 

敏捷模型中的常用概念

 

 

allure測試報告用例描述相關方法實戰

1、使用pycharm工具新建一個項目test_suites,在該目錄下新建login_module模塊、product_module模塊,如下圖

 

2、在login_module模塊下新建 test_login.py文件下

代碼如下:

import allure
# 用例步驟  寫法一 用例步驟可寫在公有層
@allure.step('步驟一:打開小叮當電商登錄界面')
def step_01():
    pass

# epic 項目名稱描述
@allure.epic('[epic] 小叮當電商系統')
# feature 項目版本
@allure.feature('[feature] 小叮當電商系統_V1.0')
class TestLogin:
    # 用例模塊
    @allure.story('[story] 用戶登錄模塊')
    # 用例標題
    @allure.title('[Title] 驗證正確的用戶名和密碼能否成功登錄')
    # 管理測試用例的鏈接地址
    @allure.testcase(url='http://47.107.187.45/zentao/www/index.php?m=testcase&f=view&caseID=17&version=1',name='用例連接')
    # 管理缺陷的鏈接地址
    @allure.issue(url='http://47.107.187.45/zentao/www/index.php?m=bug&f=browse&productID=4',name='缺陷地址')
    # 用例描述
    @allure.description('登錄測試用例 執行人:小白')
    # 定義一個鏈接
    @allure.link(url='https://www.baidu.com/',name='百度搜素')
    # 用例等級 blocker、critical、normal、minor、trivial
    # @allure.severity('normal')  # 用例等級寫法1
    # 用例等級 blocker、critical、normal、minor、trivial
    @allure.severity(allure.severity_level.BLOCKER)  # 用例等級寫法2
    def test_login_case_01(self):
        step_01()
        # 用例步驟 寫法二 用例步驟可寫在方法內部
        with allure.step('步驟二:輸入用戶名admin'):
            pass
        with allure.step('步驟三:輸入密碼123456'):
            pass
        # @allure.attach 報告添加附件
        with open('C:/Users\Jeff\PycharmProjects\APP_AUTO_DEMO/test_suites\login_module/test.jpeg', 'rb') as img_file:
            img_file_obj = img_file.read()
            allure.attach(img_file_obj,'測試報錯截圖',allure.attachment_type.JPG)

        print("TestLogin test_login_case_01",end=' ')
        assert True

    @allure.story('[story] 用戶登錄模塊')
    @allure.title('[Title] 驗證錯誤的用戶名和密碼能否正確處理')
    def test_login_case_02(self):
        print("TestLogin test_login_case_02",end=' ')
        assert True

3、在product_module模塊下新建test_product.py文件

代碼如下:

import allure

@allure.epic('[epic] 小叮當電商系統')
@allure.feature('[feature] 小叮當電商系統_V1.0')
class TestProduct:
    @allure.story('[story] 商品模塊')
    @allure.title('[Title] 驗證能夠成功添加商品到購物車')
    def test_product_case_01(self):
        print("TestProduct test_product_case_01",end=' ')
        assert True
    @allure.story('[story] 商品模塊')
    @allure.title('[Title] 驗證商品能成功支付')
    def test_product_case_02(self):
        print("TestProduct test_product_case_02",end=' ')
        assert True

4、在項目test_suites根目錄下新建執行文件run_cases.py

代碼如下:

import os
import pytest

pytest.main(['-s','-v','--alluredir=./allure_json_path','--clean-alluredir'])
os.system('allure generate %s -o %s --clean'%('./allure_json_path','./allure_html_path'))

5、執行run_cases.py文件,在項目test_suites目錄下生成兩個目錄文件夾 allure_json_path和allure_html_path

allure_json_path目錄下生的是allure測試報告的json數據源

allure_html_path目錄下生成的是allure測試報告html 

如下圖:

 

使用谷歌瀏覽器打開allure_html_path目錄下index.html文件;如下圖

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM