Allure測試框架 python


關於Allure

Allure是一個report框架,可以基於一些測試框架生成測試報告,比較常用的一般是Junit/Testng框架;

Allure 生成的報告樣式簡潔美觀,同時又支持中文;

Allure還支持使用Jenkins工具持續集成,整套環境搭建下來以后,使用起來非常方便。

分析測試的整體趨勢

實現自動化測試用例與手動測試用例關聯

下載allure

https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/allure-2.7.0.zip

並配置環境變量

詳情參考:https://www.jianshu.com/p/5735d388faa2

官網:

http://allure.qatools.ru/

下載:pip install allure-pytest

使用

pytest --alluredir=/tmp/my_allure_results

pytest test_baidu.py --alluredir ./result1

生成報告:allure serve /tmp/my_allure_results

Allure特性

pytest test_baidu.py --alluredir ./result1 --allure-features "搜索類"

import allure

@allure.feature("搜索類")
class TestSearchDemo:
    @allure.story("搜索 英文")
    def test_search(self):
        print("這是一個搜索測試 英文")

    @allure.story("搜索 中文")
    def test_search1(self):
        print("這是一個搜索測試1 中文")

    @allure.story("搜索 特殊字符")
    def test_search2(self):
        print("這是一個搜索測試2 特殊字符")

 

 清除之前的記錄: --clean-alluredir

添加圖片,html代碼塊,視頻

import allure
import pytest


@allure.feature("搜索類")
class TestSearchDemo:
    @allure.story("搜索 英文")
    #關鍵字驅動
    @pytest.mark.parametrize("searchkey",[
        "android","連衣裙","$#2!"
    ])
    def test_search(self,searchkey):
        with allure.step("第1步"):
            print("第一步:打開搜索頁面")
        with allure.step("第2步"):
            print("第二步:點擊搜索框")
        with allure.step("第3步"):
            print(f"第三步:輸入搜索詞:{searchkey}")


    @allure.story("搜索 中文")
    def test_search1(self):
        print("這是一個搜索測試1 中文")

    @allure.story("搜索 特殊字符")
    def test_search2(self):
        print("這是一個搜索測試2 特殊字符")

@allure.feature("登錄類")
class TestLoginDemo:
    def test_login1(self):
        #插入圖片
        allure.attach('<img class="s_lg_img_gold_show" src="//www.baidu.com/img/flexible/logo/pc/result.png" alt="到百度首頁" title="到百度首頁">',
                      attachment_type=allure.attachment_type.HTML)
        #插入本地圖片
        allure.attach.file('/Users/ADMIN/Desktop/a8d5a467242709a8c3a49a336abae8cd_1.PNG',
            attachment_type=allure.attachment_type.PNG)
        # 插入本地視頻  allure.attach.file   allure.attachment_type.MP4
        print("login1")

    def test_login2(self):
        print("login2")

    def test_login3(self):
        print("login3")

 

 

 

 

 


免責聲明!

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



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