從0開始python學習-35.allure報告企業定制

目錄

1. 搭建allure環境

2. 生成報告

3. logo定制

4. 企業級報告內容或層級定制

5. allure局域網查看


1. 搭建allure環境

1.1 JDK,使用PyCharm

  1. 找到pycharm安裝目錄
  2. 找到java.exe
  3. 記下jbr目錄的完整路徑,eg: C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\jbr\bin
  4. 將地址添加進入環境變量
  5. 重啟

1.2 allure程序

  1. 下載地址:https://github.com/allure-framework/allure2/releases
  2. 解壓到指定路徑。eg: D:\study\allure-2.25.0\allure-2.25.0\bin
  3. 執行allure
  4. Path 追加allure安裝路徑
  5. 驗證是否安裝成功:在dos窗口和Pycharm(需要重啟加載環境變量)中都需要驗證:allure --version

2. 生成報告

2.1 生成臨時的json格式的報告

addopts = -vs --alluredir=./temps --clean-alluredir
; --clean-alluredir生成臨時報告并清除

2.2 生成HTML的allure報告

if __name__ == "__main__":pytest.main(['./test_study/test_fixture.py'])os.system("allure generate ./temps -o ./reports --clean") # -o 指定輸出測試報告路徑# --clean 清空歷史數據# ./temps 表示用來生成html的JSON臨時文件目錄# ./reports 表示html文件生成目錄

3. logo定制

3.1 在D:\study\allure-2.25.0\allure-2.25.0\config目錄下的allure.yml中配置自定義的logo插件【- custom-logo-plugin】

3.2 重新運行并生成allue報告

3.3 增加一個自己的logo文件并修改D:\study\allure-2.25.0\allure-2.25.0\plugins\custom-logo-plugin\static路徑下的styles.css文件里面的樣式(最好將需要修改的logo也放在custom-logo-plugin目錄下)

.side-nav__brand {background: url('1.png') no-repeat left center !important; //將你需要的logo圖片地址放在這里margin-left: 22px; //調整方位height: 90px; //調整大小background-size: contain !important;
}
//去掉圖片后邊 allure 文本
.side-nav__brand-text{display: none; 
}
//配置logo 后面的字體樣式與字體大小
.side-nav__brand:after {content: "測試測試";margin-left: 18px;height: 20px;font-family: Arial;font-size: 13px;
}

?注:logo圖片和文字可以同時存在,也可以只要一個

4. 企業級報告內容或層級定制

左邊:

1. 項目名稱(史詩):@allure.epic("測試報告")

2. 模塊名稱(特性):@allure.feature("測試模塊")

3. 接口名稱(分組):@allure.story("測試接口")

@allure.epic('測試報告')
@allure.feature('測試模塊')
class TestA:@allure.story('測試1')def test_1(self):print('11111')@allure.story('測試2')def test_2(slef):print('22222')

?將多個用例寫到一個組:

@allure.story('測試1')
@allure.title('用例1')
def test_1(self):print('11111')@allure.story('測試1')
def test_2(slef):allure.dynamic.title('用例2')print('22222')

4. 用例標題:@allure.title("用例1") or allure.dynamic.title('用例2') 兩種方法都可以實現

@allure.title('用例1') //方法1
def test_1(self):print('11111')@allure.story('測試2')
def test_2(slef):allure.dynamic.title('用例2') //方法2print('22222')

?右邊:

1. 測試用例嚴重級別:@allure.severity(allure.severity_level.BLOCKER) //BLOCKER(致命),CRITICAL(嚴重),NORMAL(一般),MINOR(提示),TRIVIAL(輕微),一般默認為NORMAL

@allure.severity(allure.severity_level.TRIVIAL)
@allure.story('測試3')
def test_3(slef):print('33333')

?2. 測試用例的描述:@allure.description("測試用例的描述")

@allure.description("測試用例的描述方法1")
@allure.title('測試4')
def test_4(slef):print('44444')@allure.title('測試5')
def test_5(slef):allure.dynamic.description("測試用例的描述方法2")print('55555')

3. 接口訪問鏈接:@allure.link("接口鏈接")

4. BUG鏈接:@allure.issue("bug鏈接")

5. 測試用例鏈接:@allure.testcase("用例鏈接")

@allure.story('測試6')
@allure.link('https://www.baidu.com/0',name='接口鏈接')
@allure.issue('https://www.baidu.com/',name='bug鏈接')
@allure.testcase('https://www.baidu.com/',name='用例鏈接')
def test_6(slef):print('66666')

6. 測試用例的操作步驟:allure.step("第"+str(i)+"步"):

@allure.story('測試1')
def test_7(self):for i in range(0,10):with allure.step("第"+str(i)+"步"):pass

7. 測試附件:allure.attach(body=content,name="錯誤截圖",attachment_type=allure.attachment_type.PNG) //一般用于錯誤截圖(常用于web自動化測試)

@allure.story('測試1')
def test_8(self):# 附件上傳需要使用二進制,可以是圖片,可以是文本,可以是其它文件with open(r'D:\study\allure-2.25.0\allure-2.25.0\plugins\custom-logo-plugin\static\1.png',mode='rb') as f:content = f.read()allure.attach(body=content,name='錯誤截圖',attachment_type=allure.attachment_type.PNG)

8. 文本內容的定制:一般應用于接口自動化

@allure.story('測試1')
def test_9(self):# 請求allure.attach('https://www.baidu.com/0',name='接口地址',attachment_type=allure.attachment_type.TEXT)allure.attach('接口參數,一般從yaml中獲取',name='接口參數',attachment_type=allure.attachment_type.TEXT)allure.attach('請求方式:get/post',name='請求方式',attachment_type=allure.attachment_type.TEXT)allure.attach('請求頭,一般從yaml中獲取',name='請求頭',attachment_type=allure.attachment_type.TEXT)# 響應allure.attach('響應文本,一般從yaml中獲取', name='響應文本', attachment_type=allure.attachment_type.TEXT)allure.attach('執行結果:成功/失敗', name='執行結果', attachment_type=allure.attachment_type.TEXT)

9. 數據驅動:

@allure.story('測試1')
@pytest.mark.parametrize('x', ['這是第1個測試值', "這是第2個測試值"])
def test_a(self,x):print(f'test_a中的X值為{x}')

?由于使用數據驅動,用例標題會展示參數數據化驅動中的所有參數,若不想要顯示則需要修改allure配置

# 修改前
test_result.parameters.extend([Parameter(name=name, value=represent(value)) for name, value in params.items()if name not in current_param_names])# 修改后 (將列表內容去除即可)     
test_result.parameters.extend([])

5. allure局域網查看

局域網(內網):allure open ./reports

if __name__ == "__main__":pytest.main(['./test_study/test_allure.py'])os.system("allure generate ./temps -o ./reports --clean")os.system("allure open ./reports")

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/383319.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/383319.shtml
英文地址,請注明出處:http://en.pswp.cn/news/383319.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

grep 常用命令

這個--include選項,可以這樣使用: grep -rn --include*.c --include*.h re . 可以指定多次, 如果真是上面的這種情況, 其實可以用 grep -rn --include*.[ch] re . 但是, 如果源文件中含有C源代碼,上面的方法就不湊效了, 因為[]中只能放一個字符. grep -rn --include*.{cp…

c++中友元函數詳解

友元 友元分為:友元函數和友元類 友元提供了一種突破封裝的方式,有時提供了便利。但是友元會增加耦合度,破壞了封裝,所以友元不宜多 用。 全局函數做友元函數 全局函數寫到類中做聲明 并且最前面寫關鍵字 friend 友元函數可訪問…

Linux時間函數札記

關于gmtime、gmtime_r、localtime、localtime_r 測試環境:vmware 7 Redhat5.5,系統時間使用UTC,時區為上海。 1、函數功能介紹 使用man gmtime或man localtime都可以的得到這幾個函數的介紹。原型如下: struct tm *gmtime(const …

c++實現順序表的相關操作

Myarray.h文件 #pragma once#include<iostream>using namespace std;class MyArray { public:MyArray();//默認構造 默認100容量MyArray(int capacity);MyArray(const MyArray& array);~MyArray();//尾插法void Push_Back(int val);//根據索引獲取值int getData(int…

系統架構札記

什么是高內聚、低耦合&#xff1f; 起因&#xff1a;模塊獨立性指每個模塊只完成系統要求的獨立子功能&#xff0c;并且與其他模塊的聯系最少且接口簡單&#xff0c;兩個定性的度量標準――耦合性和內聚性。 耦合性也稱塊間聯系。指軟件系統結構中各模塊間相互聯系緊密程度的一…

c++中運算符重載(加號運算,左移運算,前置后置++運算符,賦值運算,關系運算,函數運算)

運算符重載注意 重載的運算符要易讀內置的數據類型的表達式的運算符是不可以改變的不要重載&& 和 | | 運算符&#xff0c;[]和->運算符只能通過成員函數進行重載<<和>>只能通過全局函數配合友元函數進行重載 加號運算符重載 如果想讓自定義數據類型 進…

linux fstab解讀

fstab這個文件挺有用的。 從左到右&#xff1a; /dev/device mount-point type rules dump fsck 1. /dev/device: 不用說了吧&#xff1f;例如&#xff0c;/dev/hda1為M$-Win9x下的c:盤。 2. mount-point: 掛載點。例如&#xff0c;把/dev/hda1掛到/mnt/mywinc下。 3. type: ex…

c++實現字符串類的封裝

MyString.h文件 #define _CRT_SECURE_NO_WARNINGS#pragma once#include<iostream>#include<string>using namespace std;class MyString{friend ostream & operator<<(ostream & cout, MyString & str);friend istream & operator>>(…

c++中的繼承--1(引出,繼承方式,繼承的對象模型)

繼承的引出 概念&#xff1a; 繼承(inheritance)機制是面向對象程序設計使代碼可以復用的最重要的手段&#xff0c;它允許程序員在保持原有類特 性的基礎上進行擴展&#xff0c;增加功能&#xff0c;這樣產生新的類&#xff0c;稱派生類。繼承呈現了面向對象程序設計的層次結構…

Makefile經典教程(掌握這些足夠)

makefile很重要 什么是makefile&#xff1f;或許很多Winodws的程序員都不知道這個東西&#xff0c;因為那些Windows的IDE都為你做了這個工作&#xff0c;但我覺得要作一個好的和professional的程序員&#xff0c;makefile還是要懂。這就好像現在有這么多的HTML的編輯器&#xf…

c++中的繼承--2(繼承中的析構函數和構造函數,繼承中同名成員,繼承中靜態成員)

繼承中的構造函數和析構函數 繼承中的構造和析構順序 子類創建對象時&#xff0c;先調用父類的構造&#xff0c;然后調用自身構造析構順序與構造順序相反子類不會繼承父類的構造函數和析構函數如果父類中沒有合適默認構造&#xff0c;那么子類可以利用初始化列表的方式顯示的…

Linux鎖機制和線程安全

鎖機制是多線程編程中最常用的同步機制&#xff0c;用來對多線程間共享的臨界區進行保護。 1. 互斥鎖&#xff1a;pthread_mutex&#xff0c;屬于sleep-waiting類型的鎖 pthread_mutex_t *mutex; int pthread_mutex_int(mutex, attr) //以動態方式創建互斥鎖&#xff0c;參…

c++中的繼承--3(多繼承問題,菱形繼承)

繼承中的多繼承 #include<iostream>using namespace std;class Base1 { public:Base1(){m_A 10;} public:int m_A;};class Base2 { public:Base2(){m_A 10;} public:int m_B;int m_A;};class Son :public Base1, public Base2 {public:int m_C;int m_D; };void test01…

c++中的多態---1(多態概念,靜態聯編和動態聯編,多態原理解析,重載,重寫,重定義的對比)

多態的基本概念 多態是面向對象設計語言數據抽象和繼承之外的第三個基本特征多態性(polymorphism)提供接口與具體實現之間的另一層隔膜&#xff0c;從而將“what”和“how”分離開來&#xff0c;多態性改善了代碼的可讀和組織性&#xff0c;同時也使創建的程序具有可擴展性&am…

Ubuntu下各種服務搭建及操作技巧

Ubuntu下搭建TFTP 1、安裝軟件包 sudo apt-get install tftpd tftp xinetd 2、建立配置文件 在/etc/xinetd.d/下建立一個配置文件tftp sudo vi /etc/xinetd.d/tftp 內容如下 service tftp { socket_type dgram protocol udp wait yes user root …

c++多態--2(計算器,純虛函數和抽象類)

為什么要用多態 早期方法不利于擴展開閉原則 開閉原則 對擴展開放 對修改關閉利用多態實現—利于后期擴展&#xff0c;結構性非常好&#xff0c;可讀性高&#xff0c;效率稍微低&#xff0c;發生多態內部結構復雜 多態成立的條件 又繼承 子類重寫父類虛函數的函數&#xff1…

使用Automake和Autoconf生成Makefile

automake 所產生的 Makefile 除了可以做到程序的自動編譯和鏈接 外&#xff0c;還可以用來生成各種文檔&#xff08;如manual page、info文件&#xff09;&#xff0c;可以將源代碼文件包裝起來以供發布。所以程序源代碼所存放的目錄 結構最好符合GNU的標準慣例。下面以hello.…

c++中多態---3(虛析構和純虛析構,向上類型轉化和向下類型轉化)

虛析構和純虛析構 虛析構virtual ~類名(){}類內聲明&#xff0c;類內實現解決問題&#xff1a;通過父類指針指向子類對象釋放時候不干凈的問題 純虛析構 寫法 virtual ~類名(){}0; 類內聲明 類外實現 如果出現了純虛析構函數&#xff0c;這個類也算是抽象類&#xff0c;不可…

嵌入式開發硬件知識札記

三態邏輯 1. 概念 三態指其輸出既可以是一般二值邏輯電路&#xff0c;即正常的高電平&#xff08;邏輯1&#xff09;或低電平&#xff08;邏輯0&#xff09;&#xff0c;又可以保持特有的高阻抗狀態。高阻態相當于隔斷狀態&#xff08;電阻很大&#xff0c;相當于開路&#xff…

《凡人修仙傳》中打斗場景(c++多態實現)

我們 要實現打斗場景&#xff0c;第一&#xff0c;我們需要有打斗的雙方&#xff0c;一個是英雄&#xff0c;一個是怪物&#xff0c;他們都有自己的屬性&#xff0c;比如攻擊&#xff0c;防御&#xff0c;血量。其次我們的英雄還會有武器。武器上有一些加成屬性&#xff0c;可以…