探索Allure Report:提升自動(dòng)化測(cè)試效率的秘密武器
感謝您抽出
.
.
閱讀本文
一.使用 Allure2 運(yùn)行方式-Python
# --alluredir 參數(shù)生成測(cè)試報(bào)告。
# 在測(cè)試執(zhí)行期間收集結(jié)果
pytest [測(cè)試用例/模塊/包] --alluredir=./result/ (—alluredir這個(gè)選項(xiàng) 用于指定存儲(chǔ)測(cè)試結(jié)果的路徑)
# 生成在線的測(cè)試報(bào)告
allure serve ./result
二.使用 Allure2 運(yùn)行方式-Java
1.使用 allure:report 參數(shù)生成測(cè)試報(bào)告
# 在測(cè)試執(zhí)行期間收集結(jié)果
# mvn命令行使用 maven插件安裝
mvn clean test allure:report
# 生成在線的測(cè)試報(bào)告
# mvn 直接找target/allure-results目錄
mvn allure:serve
2.運(yùn)行mvn命令對(duì)應(yīng)沒有在target下面生成allure-results目錄。在src/test/resources路徑下配置allure配置文件allure.properties,指名allure報(bào)告生成路徑。
allure.results.directory=target/allure-resultsa
3.運(yùn)行mvn命令一直卡在下載中,解決方法
①在項(xiàng)目下創(chuàng)建.allure文件夾。
②下載allure解壓到.allure文件夾下。
三.生成測(cè)試報(bào)告
1.生成測(cè)試報(bào)告需要使用命令行工具allure
2.命令格式allure [option] [command] [command options]
# 步驟一:在測(cè)試執(zhí)行期間收集結(jié)果
# —alluredir這個(gè)選項(xiàng) 用于指定存儲(chǔ)測(cè)試結(jié)果的路徑
pytest [測(cè)試文件] -s –q --alluredir=./result/
# 如果要清除已經(jīng)生成的報(bào)告的歷史記錄,可以添加參數(shù)--clean-alluredir
pytest [測(cè)試文件] -s –q --alluredir=./result/ --clean-alluredir
# 步驟二:查看測(cè)試報(bào)告,注意這里的serve書寫
allure serve ./result/
3.Allure報(bào)告生成的兩種方式
方式一:在線報(bào)告,會(huì)直接打開默認(rèn)瀏覽器展示當(dāng)前報(bào)告。
# 方式一:測(cè)試完成后查看實(shí)際報(bào)告,在線查看報(bào)告,會(huì)直接打開默認(rèn)瀏覽器展示當(dāng)前報(bào)告。
allure serve ./result/
方式二:靜態(tài)資源文件報(bào)告(帶 index.html、css、js等文件),需要將報(bào)告布署到 web服務(wù)器上。
a.應(yīng)用場(chǎng)景:如果希望隨時(shí)打開報(bào)告,可以生成一個(gè)靜態(tài)資源文件報(bào)告,將這個(gè)報(bào)告布署到 web 服務(wù)器上,啟動(dòng) web 服務(wù),即可隨時(shí)隨地打開報(bào)告。
b.解決方案:使用allure generate 生成帶有 index.html 的結(jié)果報(bào)告。這種方式需要兩個(gè)步驟:第一步:生成報(bào)告。第二步:打開報(bào)告。
# 生成報(bào)告
allure generate ./result
# 打開報(bào)告
allure open ./report/
4.常用參數(shù)
①allure generate 可以指定輸出路徑,也可以清理上次的報(bào)告記錄。
②-o / –output 輸出報(bào)告的路徑。
③-c / –clean 如果報(bào)告路徑重復(fù)。
④allure open 打開報(bào)告。
⑤-h / –host 主機(jī) IP 地址,此主機(jī)將用于啟動(dòng)報(bào)表的 web 服務(wù)器。
⑥-p / –port 主機(jī)端口,此端口將用于啟動(dòng)報(bào)表的 web 服務(wù)器,默認(rèn)值:0。
# 生成報(bào)告,指定輸出路徑,清理報(bào)告。
allure generate ./result -o ./report --clean
# 打開報(bào)告,指定IP地址和端口。
allure open -h 127.0.0.1 -p 8883 ./report/
四.Allure2 報(bào)告中添加用例標(biāo)題
通過使用裝飾器@allure.title可以為測(cè)試用例自定義一個(gè)可閱讀性的標(biāo)題。allure.title的三種使用方式如下
方式一:直接使用裝飾器@allure.title 為測(cè)試用例自定義標(biāo)題。
import allure
import pytest
@allure.title("自定義測(cè)試用例標(biāo)題")
def test_with_title():
assert True
方式二:@allure.title支持通過占位符的方式傳遞參數(shù),可以實(shí)現(xiàn)測(cè)試用例標(biāo)題參數(shù)化,動(dòng)態(tài)生成測(cè)試用例標(biāo)題。
import allure
import pytest
@allure.title("參數(shù)化用例標(biāo)題:參數(shù)一:{param1} ,參數(shù)二: {param2}")
@pytest.mark.parametrize("param1, param2, expected", [
(1, 1, 2),
(0.1, 0.3, 0.4)
])
def test_with_parametrize_title(param1, param2, expected):
assert param1 + param2 == expected
方式三:allure.dynamic.title 動(dòng)態(tài)更新測(cè)試用例標(biāo)題。
@allure.title("原始標(biāo)題")
def test_with_dynamic_title():
assert True
allure.dynamic.title("更改后的新標(biāo)題")
五.Allure2報(bào)告中添加用例步驟
方法一:使用裝飾器定義一個(gè)測(cè)試步驟,在測(cè)試用例中使用。
# 方法一:使用裝飾器定義一個(gè)測(cè)試步驟,在測(cè)試用例中使用
import allure
import pytest
# 定義測(cè)試步驟:simple_step1
@allure.step
def simple_step1(step_param1, step_param2 = None):
'''定義一個(gè)測(cè)試步驟'''
print(f"步驟1:打開頁面,參數(shù)1: {step_param1}, 參數(shù)2:{step_param2}")
# 定義測(cè)試步驟:simple_step2
@allure.step
def simple_step2(step_param):
'''定義一個(gè)測(cè)試步驟'''
print(f"步驟2:完成搜索 {step_param} 功能")
@pytest.mark.parametrize('param1', ["pytest", "allure"], ids=['search pytest', 'search allure'])
def test_parameterize_with_id(param1):
simple_step2(param1) # 調(diào)用步驟二
@pytest.mark.parametrize('param1', [True, False])
@pytest.mark.parametrize('param2', ['value 1', 'value 2'])
def test_parametrize_with_two_parameters(param1, param2):
simple_step1(param1, param2) # 調(diào)用步驟一
@pytest.mark.parametrize('param2', ['pytest', 'unittest'])
@pytest.mark.parametrize('param1,param3', [[1,2]])
def test_parameterize_with_uneven_value_sets(param1, param2, param3):
simple_step1(param1, param3) # 調(diào)用步驟一
simple_step2(param2) # 調(diào)用步驟二
方法二:使用 with allure.step() 添加測(cè)試步驟。
# 方法二:使用 `with allure.step()` 添加測(cè)試步驟
@allure.title("搜索用例")
def test_step_in_method():
with allure.step("測(cè)試步驟一:打開頁面"):
print("操作 a")
print("操作 b")
with allure.step("測(cè)試步驟二:搜索"):
print("搜索操作 ")
with allure.step("測(cè)試步驟三:斷言"):
assert True
六.Allure2報(bào)告中添加用例鏈接
應(yīng)用場(chǎng)景:將報(bào)告與bug管理系統(tǒng)或測(cè)試用例管理系統(tǒng)集成,可以添加鏈接裝飾器@allure.link、@allure.issue和@allure.testcase。
[email protected](url, name) 添加一個(gè)普通的 link 鏈接。
[email protected](url, name) 添加一個(gè)用例管理系統(tǒng)鏈接。
[email protected](url, name),添加 bug 管理系統(tǒng)
# 格式1:添加一個(gè)普通的link 鏈接
@allure.link('https://ceshiren.com/t/topic/15860')
def test_with_link():
pass
# 格式1:添加一個(gè)普通的link 鏈接,添加鏈接名稱
@allure.link('https://ceshiren.com/t/topic/15860', name='這是用例鏈接地址')
def test_with_named_link():
pass
# 格式2:添加用例管理系統(tǒng)鏈接
TEST_CASE_LINK = 'https://github.com/qameta/allure-integrations/issues/8#issuecomment-268313637'
@allure.testcase(TEST_CASE_LINK, '用例管理系統(tǒng)')
def test_with_testcase_link():
pass
# 格式3:添加bug管理系統(tǒng)鏈接
# 這個(gè)裝飾器在展示的時(shí)候會(huì)帶 bug 圖標(biāo)的鏈接。可以在運(yùn)行時(shí)通過參數(shù) `--allure-link-pattern` 指定一個(gè)模板鏈接,以便將其與提供的問題鏈接類型鏈接模板一起使用。執(zhí)行命令需要指定模板鏈接:
`--allure-link-pattern=issue:https://abc.com/t/topic/{}`
@allure.issue("15860", 'bug管理系統(tǒng)')
def test_with_issue():
pass
七.Allure2報(bào)告中添加用例分類
1.Allure分類
(1)應(yīng)用場(chǎng)景:可以為項(xiàng)目,以及項(xiàng)目下的不同模塊對(duì)用例進(jìn)行分類管理。也可以運(yùn)行某個(gè)類別下的用例。
(2)報(bào)告展示:類別會(huì)展示在測(cè)試報(bào)告的Behaviors欄目下。
(3)Allure提供了三個(gè)裝飾器:
-
@allure.epic:敏捷里面的概念,定義史詩,往下是feature。 -
@allure.feature:功能點(diǎn)的描述,理解成模塊往下是story。 -
@allure.story:故事story是feature的子集。
2.Allure分類 - epic
-
場(chǎng)景:希望在測(cè)試報(bào)告中看到用例所在的項(xiàng)目,需要用到 epic,相當(dāng)于定義一個(gè)項(xiàng)目的需求,由于粒度比較大,在epic下面還要定義略小粒度的用戶故事。 -
裝飾器: @allure.epic
import allure
@allure.epic("需求1")
class TestEpic:
def test_case1(self):
print("用例1")
def test_case2(self):
print("用例2")
def test_case3(self):
print("用例3")
3.Allure分類 - feature/story
-
場(chǎng)景: 希望在報(bào)告中看到測(cè)試功能,子功能或場(chǎng)景。 -
裝飾器: @allure.Feature、@allure.story
import allure
@allure.epic("需求1")
@allure.feature("功能模塊1")
class TestEpic:
@allure.story("子功能1")
@allure.title("用例1")
def test_case1(self):
print("用例1")
@allure.story("子功能2")
@allure.title("用例2")
def test_case2(self):
print("用例2")
@allure.story("子功能2")
@allure.title("用例3")
def test_case3(self):
print("用例3")
@allure.story("子功能1")
@allure.title("用例4")
def test_case4(self):
print("用例4")
4.Allure運(yùn)行feature/story
# allure相關(guān)的命令查看
pytest --help|grep allure
#通過指定命令行參數(shù),運(yùn)行 epic/feature/story 相關(guān)的用例:
pytest 文件名
--allure-epics=EPICS_SET --allure-features=FEATURES_SET --allure-stories=STORIES_SET
# 只運(yùn)行 epic 名為 "需求1" 的測(cè)試用例
pytest --alluredir ./results --clean-alluredir --allure-epics=需求1
# 只運(yùn)行 feature 名為 "功能模塊2" 的測(cè)試用例
pytest --alluredir ./results --clean-alluredir --allure-features=功能模塊2
# 只運(yùn)行 story 名為 "子功能1" 的測(cè)試用例
pytest --alluredir ./results --clean-alluredir --allure-stories=子功能1
# 運(yùn)行 story 名為 "子功能1和子功能2" 的測(cè)試用例
pytest --alluredir ./results --clean-alluredir --allure-stories=子功能1,子功能2
# 運(yùn)行 feature + story 的用例(取并集)
pytest --alluredir ./results --clean-alluredir --allure-features=功能模塊1 --allure-stories=子功能1,子功能2
Allure epic/feature/story 的關(guān)系
5.總結(jié)
-
epic:敏捷里面的概念,用來定義史詩,相當(dāng)于定義一個(gè)項(xiàng)目。 -
feature:相當(dāng)于一個(gè)功能模塊,相當(dāng)于testsuite,可以管理很多個(gè)子分支story。 -
story:相當(dāng)于對(duì)應(yīng)這個(gè)功能或者模塊下的不同場(chǎng)景,分支功能。 -
epic與feature、feature與story類似于父子關(guān)系。
八.Allure2 報(bào)告中添加用例描述
1.應(yīng)用場(chǎng)景:Allure 支持往測(cè)試報(bào)告中對(duì)測(cè)試用例添加非常詳細(xì)的描述語,用來描述測(cè)試用例詳情。
2.Allure添加描述的四種方式:
方式一:使用裝飾器 @allure.description() 傳遞一個(gè)字符串參數(shù)來描述測(cè)試用例。
@allure.description("""
多行描述語:<br/>
這是通過傳遞字符串參數(shù)的方式添加的一段描述語,<br/>
使用的是裝飾器 @allure.description
""")
def test_description_provide_string():
assert True
方式二:使用裝飾器 @allure.description_html 傳遞一段 HTML 文本來描述測(cè)試用例。
@allure.description_html("""html代碼塊""")
def test_description_privide_html():
assert True
方式三:直接在測(cè)試用例方法中通過編寫文檔注釋的方法來添加描述。
def test_description_docstring():
"""
直接在測(cè)試用例方法中
通過編寫文檔注釋的方法
來添加描述。
:return:
"""
assert True
方式四:用例代碼內(nèi)部動(dòng)態(tài)添加描述信息。
import allure
@allure.description("""這個(gè)描述將被替換""")
def test_dynamic_description():
assert 42 == int(6 * 7)
allure.dynamic.description('這是最終的描述信息')
# allure.dynamic.description_html(''' html 代碼塊 ''')
九.Allure2報(bào)告中添加用例優(yōu)先級(jí)
1.應(yīng)用場(chǎng)景:用例執(zhí)行時(shí),希望按照嚴(yán)重級(jí)別執(zhí)行測(cè)試用例。
2.解決:可以為每個(gè)用例添加一個(gè)等級(jí)的裝飾器,用法:@allure.severity。
3.Allure 對(duì)嚴(yán)重級(jí)別的定義分為 5 個(gè)級(jí)別:
-
Blocker級(jí)別:中斷缺陷(客戶端程序無響應(yīng),無法執(zhí)行下一步操作)。 -
Critical級(jí)別:臨界缺陷( 功能點(diǎn)缺失)。 -
Normal級(jí)別:普通缺陷(數(shù)值計(jì)算錯(cuò)誤)。 -
Minor級(jí)別:次要缺陷(界面錯(cuò)誤與UI需求不符)。 -
Trivial級(jí)別:輕微缺陷(必輸項(xiàng)無提示,或者提示不規(guī)范)。
4.使用裝飾器添加用例方法/類的級(jí)別。類上添加的級(jí)別,對(duì)類中沒有添加級(jí)別的方法生效。
#運(yùn)行時(shí)添加命令行參數(shù) --allure-severities:
pytest --alluredir ./results --clean-alluredir --allure-severities normal,blocker
import allure
def test_with_no_severity_label():
pass
@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
pass
@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
pass
@allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object):
def test_inside_the_normal(self):
pass
@allure.severity(allure.severity_level.CRITICAL)
def test_critical_severity(self):
pass
@allure.severity(allure.severity_level.BLOCKER)
def test_blocker_severity(self):
pass
十.Allure2報(bào)告中添加用例支持tags標(biāo)簽
1.Allure2 添加用例標(biāo)簽-xfail、skipif
import pytest
# 用法:使用裝飾器 @pytest.xfail()、@pytest.skipif()
# 當(dāng)用例通過時(shí)標(biāo)注為 xfail
@pytest.mark.xfail(condition=lambda: True, reason='這是一個(gè)預(yù)期失敗的用例')
def test_xfail_expected_failure():
"""this test is a xfail that will be marked as expected failure"""
assert False
# 當(dāng)用例通過時(shí)標(biāo)注為 xpass
@pytest.mark.xfail
def test_xfail_unexpected_pass():
"""this test is a xfail that will be marked as unexpected success"""
assert True
# 跳過用例
@pytest.mark.skipif('2 + 2 != 5', reason='當(dāng)條件觸發(fā)時(shí)這個(gè)用例被跳過 @pytest.mark.skipif')
def test_skip_by_triggered_condition():
pass
2.Allure2 添加用例標(biāo)簽-fixture
應(yīng)用場(chǎng)景:fixture 和 finalizer 是分別在測(cè)試開始之前和測(cè)試結(jié)束之后由 Pytest 調(diào)用的實(shí)用程序函數(shù)。Allure 跟蹤每個(gè) fixture 的調(diào)用,并詳細(xì)顯示調(diào)用了哪些方法以及哪些參數(shù),從而保持了調(diào)用的正確順序。
import pytest
@pytest.fixture()
def func(request):
print("這是一個(gè)fixture方法")
# 定義一個(gè)終結(jié)器,teardown動(dòng)作放在終結(jié)器中
def over():
print("session級(jí)別終結(jié)器")
request.addfinalizer(over)
class TestClass(object):
def test_with_scoped_finalizers(self,func):
print("測(cè)試用例")
十一.Allure2報(bào)告中支持記錄失敗重試功能
1.Allure 可以收集用例運(yùn)行期間,重試的用例的結(jié)果,以及這段時(shí)間重試的歷史記錄。
2.重試功能可以使用 pytest 相關(guān)的插件,例如 pytest-rerunfailures。重試的結(jié)果信息,會(huì)展示在詳情頁面的Retries 選項(xiàng)卡中。
import pytest
@pytest.mark.flaky(reruns=2, reruns_delay=2) # reruns重試次數(shù),reruns_delay每次重試間隔時(shí)間(秒)
def test_rerun2():
assert False
十二.Allure2 報(bào)告中添加附件-圖片
1.應(yīng)用場(chǎng)景:在做 UI 自動(dòng)化測(cè)試時(shí),可以將頁面截圖,或者出錯(cuò)的頁面進(jìn)行截圖,將截圖添加到測(cè)試報(bào)告中展示,輔助定位問題。
2.解決方案
-
Python:使用 allure.attach或者allure.attach.file()添加圖片。 -
Java:直接通過注解或調(diào)用方法添加。
3.python方法一
語法:allure.attach.file(source, name, attachment_type, extension),
參數(shù)解釋:
①source:文件路徑,相當(dāng)于傳一個(gè)文件。
②name:附件名字。
③attachment_type:附件類型,是 allure.attachment_type 其中的一種(支持 PNG、JPG、BMP、GIF 等)。
④extension:附件的擴(kuò)展名。
import allure
class TestWithAttach:
def test_pic(self):
allure.attach.file("pic.png", name="圖片", attachment_type=allure.attachment_type.PNG, extension="png")
4.python方法二
語法:allure.attach(body, name=None, attachment_type=None, extension=None)
參數(shù)解釋:
①body:要寫入附件的內(nèi)容
②name:附件名字。
③attachment_type:附件類型,是 allure.attachment_type 其中的一種(支持 PNG、JPG、BMP、GIF 等)。
④extension:附件的擴(kuò)展名。
5.裂圖的原因以及解決辦法
-
圖片上傳過程中出現(xiàn)了網(wǎng)絡(luò)中斷或者傳輸過程中出現(xiàn)了錯(cuò)誤。 解決方案:重新上傳圖片。
-
Allure報(bào)告中的圖片大小超過了Allure的限制。 解決方案:調(diào)整圖片大小。 -
圖片本身存在問題。 解決方案:檢查圖片格式和文件本身。
十三.Allure2報(bào)告中添加附件-日志
1.應(yīng)用場(chǎng)景:報(bào)告中添加詳細(xì)的日志信息,有助于分析定位問題。 2.解決方案:使用 python 自帶的 logging 模塊生成日志,日志會(huì)自動(dòng)添加到測(cè)試報(bào)告中。日志配置,在測(cè)試報(bào)告中使用 logger 對(duì)象生成對(duì)應(yīng)級(jí)別的日志。
# 創(chuàng)建一個(gè)日志模塊: log_util.py
import logging
import os
from logging.handlers import RotatingFileHandler
# 綁定綁定句柄到logger對(duì)象
logger = logging.getLogger(__name__)
# 獲取當(dāng)前工具文件所在的路徑
root_path = os.path.dirname(os.path.abspath(__file__))
# 拼接當(dāng)前要輸出日志的路徑
log_dir_path = os.sep.join([root_path, f'/logs'])
if not os.path.isdir(log_dir_path):
os.mkdir(log_dir_path)
# 創(chuàng)建日志記錄器,指明日志保存路徑,每個(gè)日志的大小,保存日志的上限
file_log_handler = RotatingFileHandler(os.sep.join([log_dir_path, 'log.log']), maxBytes=1024 * 1024, backupCount=10 , encoding="utf-8")
# 設(shè)置日志的格式
date_string = '%Y-%m-%d %H:%M:%S'
formatter = logging.Formatter(
'[%(asctime)s] [%(levelname)s] [%(filename)s]/[line: %(lineno)d]/[%(funcName)s] %(message)s ', date_string)
# 日志輸出到控制臺(tái)的句柄
stream_handler = logging.StreamHandler()
# 將日志記錄器指定日志的格式
file_log_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)
# 為全局的日志工具對(duì)象添加日志記錄器
# 綁定綁定句柄到logger對(duì)象
logger.addHandler(stream_handler)
logger.addHandler(file_log_handler)
# 設(shè)置日志輸出級(jí)別
logger.setLevel(level=logging.INFO)
代碼輸出到用例詳情頁面。運(yùn)行用例命令:pytest --alluredir ./results --clean-alluredir(注意不要加-vs)。
import allure
from pytest_test.log_util import logger
@allure.feature("功能模塊2")
class TestWithLogger:
@allure.story("子功能1")
@allure.title("用例1")
def test_case1(self):
logger.info("用例1的 info 級(jí)別的日志")
logger.debug("用例1的 debug 級(jí)別的日志")
logger.warning("用例1的 warning 級(jí)別的日志")
logger.error("用例1的 error 級(jí)別的日志")
logger.fatal("用例1的 fatal 級(jí)別的日志")
日志展示在 Test body 標(biāo)簽下,標(biāo)簽下可展示多個(gè)子標(biāo)簽代表不同的日志輸出渠道:
-
log子標(biāo)簽:展示日志信息。 -
stdout子標(biāo)簽:展示print信息。 -
stderr子標(biāo)簽:展示終端輸出的信息。
禁用日志,可以使用命令行參數(shù)控制 --allure-no-capture
pytest --alluredir ./results --clean-alluredir --allure-no-capture
public void exampleTest() {
byte[] contents = Files.readAllBytes(Paths.get("a.txt"));
attachTextFile(byte[]的文件, "描述信息");
}
@Attachment(value = "{attachmentName}", type = "text/plain")
public byte[] attachTextFile(byte[] contents, String attachmentName) {
return contents;
}
調(diào)用方法添加。
--String類型添加。 日志文件為String類型
Allure.addAttachment("描述信息", "text/plain", 文件讀取為String,"txt");
--InputStream類型添加。日志文件為InputStream流
Allure.addAttachment("描述信息", "text/plain", Files.newInputStream(文件Path), "txt");
十四.Allure2報(bào)告中添加附件-html
1.應(yīng)用場(chǎng)景:可以定制測(cè)試報(bào)告頁面效果,可以將 HTML 類型的附件顯示在報(bào)告頁面上。
2.解決方案:使用 allure.attach() 添加 html 代碼。
語法:allure.attach(body, name, attachment_type, extension),
參數(shù)解釋:
body:要寫入附件的內(nèi)容(HTML 代碼塊)。
name:附件名字。
attachment_type:附件類型,是 allure.attachment_type 其中的一種。
extension:附件的擴(kuò)展名。
import allure
class TestWithAttach:
def test_html(self):
allure.attach('<head></head><body> a page </body>',
'附件是HTML類型',
allure.attachment_type.HTML)
def test_html_part(self):
allure.attach('''html代碼塊''',
'附件是HTML類型',
allure.attachment_type.HTML)
十五.Allure2 報(bào)告中添加附件-視頻
使用 allure.attach.file() 添加視頻。
語法:allure.attach.file(source, name, attachment_type, extension)
參數(shù)解釋:
source:文件路徑,相當(dāng)于傳一個(gè)文件。
name:附件名字。
attachment_type:附件類型,是 allure.attachment_type 其中的一種。
extension:附件的擴(kuò)展名。
import allure
class TestWithAttach:
def test_video(self):
allure.attach.file("xxx.mp4", name="視頻", attachment_type=allure.attachment_type.MP4, extension="mp4")
十六.Allure2 報(bào)告定制
應(yīng)用場(chǎng)景:針對(duì)不同的項(xiàng)目可能需要對(duì)測(cè)試報(bào)告展示的效果進(jìn)行定制,比如修改頁面的 logo、修改項(xiàng)目的標(biāo)題或者添加一些定制的功能等等。
1.修改頁面 Logo
(1)修改allure.yml文件,在后面添加 logo 插件:custom-logo-plugin(在 allure 安裝路徑下:/allure-2.21.0/config/allure.yml,可以通過 where allure 或者which allure查看 allure 安裝路徑)
(2)編輯 styles.css 文件,配置 logo 圖片(logo圖片可以提前準(zhǔn)備好放在/custom-logo-plugin/static中)
/* 打開 styles.css 文件,
目錄在安裝allure時(shí),解壓的路徑:/xxx/allure-2.21.0/plugins/custom-logo-plugin/static/styles.css,
將內(nèi)容修改圖片logo和相應(yīng)的大小:*/
.side-nav__brand {
background: url("logo.jpeg") no-repeat left center !important;
margin-left: 10px;
height: 40px;
background-size: contain !important;
}
2.修改頁面標(biāo)題,編輯 styles.css 文件,添加修改標(biāo)題對(duì)應(yīng)的代碼。
/* 去掉圖片后邊 allure 文本 */
.side-nav__brand-text {
display: none;
}
/* 設(shè)置logo 后面的字體樣式與字體大小 */
.side-nav__brand:after {
content: "測(cè)試報(bào)告";
margin-left: 18px;
height: 20px;
font-family: Arial;
font-size: 13px;
}
來源:https://juejin.cn/post/7232696604045803580
如果覺得有用,就請(qǐng)關(guān)注、點(diǎn)贊、在看、分享到朋友圈吧。
推薦閱讀:
END
長(zhǎng)按二維碼/微信掃碼 添加作者
