一、@allure.step的用法
- 可以理解為我們編寫測試用例中的每一步操作步驟,而在allure中表示對每個測試用例進行非常詳細的步驟說明
- 通過 @allure.step(),可以讓測試用例在allure報告中顯示更詳細的測試過程
示例代碼:
# -*- coding: utf-8 -*-
# @Time : 2020/12/12 8:34
# @Author : longrong.lang
# @FileName: test_allure.py
# @Software: PyCharm
# @Cnblogs :https://www.cnblogs.com/longronglang
import allure
@allure.step("打開網站首頁")
def open():
pass
@allure.step("輸入賬號、密碼")
def input_UsernameAndPassWord():
sendAndClickLogin("xiaoqiang", "1")
@allure.step("輸入賬號、密碼{arg1},{arg2},並點擊登錄")
def sendAndClickLogin(arg1, arg2):
pass
@allure.step("驗證登錄過程")
def test_login():
open()
input_UsernameAndPassWord()
測試用例在allure的顯示
小結
- step(參數),參數就是標題,你傳什么,在allure上的步驟名就顯示什么
- 支持位置參數和關鍵字參數 {arg1},{arg2},可參考報告中“ 輸入賬號、密碼'xiaoqiang','1',並點擊登錄”處,如果函數的參數沒有匹配成功就會報錯
二、allure.attach的用法
作用: allure報告還支持顯示許多不同類型的附件,可以補充測試結果;可根據自身情況進行調整
語法: allure.attach(body, name, attachment_type, extension)
參數列表
body:要顯示的內容(附件)
name:附件名字
attachment_type:附件類型,是 allure.attachment_type 里面的其中一種
extension:附件的擴展名(比較少用)
allure.attachment_type提供了哪些附件類型?
語法二: allure.attach.file(source, name, attachment_type, extension)
source:文件路徑,相當於傳一個文件
示例代碼如下:
# -*- coding: utf-8 -*-
# @Time : 2020/12/12 8:34
# @Author : longrong.lang
# @FileName: test_allure.py
# @Software: PyCharm
# @Cnblogs :https://www.cnblogs.com/longronglang
import allure
@allure.step("打開網站首頁")
def open():
pass
@allure.step("輸入賬號、密碼")
def input_UsernameAndPassWord():
sendAndClickLogin("xiaoqiang", "1")
@allure.step("輸入賬號、密碼{arg1},{arg2},並點擊登錄")
def sendAndClickLogin(arg1, arg2):
pass
@allure.step("驗證登錄過程")
def test_login():
open()
input_UsernameAndPassWord()
# 添加附件
def test_attachments():
# 在測試報告中畫了一個html頁面
allure.attach('<head></head><body><strong>HTML頁面,HelloWorld!</strong> </body>', 'Attach with HTML type',
allure.attachment_type.HTML)
# 添加一個html附件
allure.attach.file('./report.html', attachment_type=allure.attachment_type.HTML)
# 添加一個圖片附件
allure.attach.file('./demo.jpg', attachment_type=allure.attachment_type.JPG)
在allure報告中展示如下: