色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告

瀏覽:2日期:2022-06-20 15:58:16

Allure測(cè)試報(bào)告框架幫助你輕松實(shí)現(xiàn)”高大上”報(bào)告展示。本文通過示例演示如何從0到1集成Allure測(cè)試框架。重點(diǎn)展示了如何將Allure集成到已有的自動(dòng)化測(cè)試工程中、以及如何實(shí)現(xiàn)報(bào)表的優(yōu)化展示。Allure非常強(qiáng)大,支持多種語言多種測(cè)試框架,無論是Java/Python還是Junit/TestNG,其他語言或者框架實(shí)現(xiàn)的流程和本文一致,具體配置參照各語言框架規(guī)范

安裝

安裝allure

Windows用戶:

scoop install allure (需要先下載并安裝Scoop,該方法無需配置環(huán)境變量)

MAC用戶:

通過Homebrew進(jìn)行自動(dòng)安裝 brew install allure (如果Homebrew版本比較舊,需要先升級(jí)Homebrew,否則安裝的allure版本也很老,可能會(huì)與Python插件不兼容)

手動(dòng)安裝:

可以從官網(wǎng) https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/ 手動(dòng)下載目前最新版本為2.13.6

python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告

下載后解壓并配置環(huán)境變量

安裝allure-pytest插件

pip install allure-pytest

allure常用特性

希望在報(bào)告中看到測(cè)試功能,子功能或場(chǎng)景,測(cè)試步驟,包括測(cè)試附加信息可以使用@feature,@story,@step,@attach

步驟:

import allure 功能上加@allure.feature('功能名稱') 子功能上加@allure.story('子功能名稱') 步驟上加@allure.step('步驟細(xì)節(jié)') @allure.attach('具體文本信息'),需要附加的信息,可以是數(shù)據(jù),文本,圖片,視頻,網(wǎng)頁 如果只測(cè)試部分功能運(yùn)行的時(shí)候可以加限制過濾: pytest 文件名 --allure-features '需要運(yùn)行的功能名稱' allure特性—feature/story

@allure.feature與@allure.store的關(guān)系

feature相當(dāng)于一個(gè)功能,一個(gè)大的模塊,將case分類到某個(gè)feature中,報(bào)告中在behaviore中顯示,相當(dāng)于testsuite story相當(dāng)于對(duì)應(yīng)這個(gè)功能或者模塊下的不同場(chǎng)景,分支功能,屬于feature之下的結(jié)構(gòu),報(bào)告在features中顯示,相當(dāng)于testcase feature與story類似于父與子關(guān)系

step特性

測(cè)試過程中每個(gè)步驟,一般放在具體邏輯方法中 可以放在關(guān)鍵步驟中,在報(bào)告中顯示 在app,web自動(dòng)化測(cè)試中,建議每切換到一個(gè)新的頁面當(dāng)做一個(gè)step 用法: @allure.step() 只能以裝飾器的形式放在類或方法上面with allure.step(): 可以放在測(cè)試用例方法里面,但測(cè)試步驟的代碼需要被該語句包含

運(yùn)行:

在測(cè)試執(zhí)行期間收集結(jié)果

pytest [測(cè)試文件] -s -q --alluredir=./result --clean-alluredir

--alluredir這個(gè)選項(xiàng),用于指定存儲(chǔ)測(cè)試結(jié)果的路徑 --clean-alluredir 這個(gè)選項(xiàng)用來清除之前生成的結(jié)果

查看測(cè)試報(bào)告:

方法一:測(cè)試完成后查看實(shí)際報(bào)告,在線看報(bào)告,會(huì)直接打開默認(rèn)瀏覽器展示當(dāng)前報(bào)告

allure serve ./result

方法二:從結(jié)果生成報(bào)告,這是一個(gè)啟動(dòng)tomcat的服務(wù),需要兩個(gè)步驟

生成報(bào)告:

allure generate ./result -o ./report --clean (注意:--clean用來清除之前已生成的報(bào)告)

打開報(bào)告:

allure open -h 127.0.0.1 -p 8883 ./report (該方法直接生成一個(gè)tomcat服務(wù),可遠(yuǎn)程訪問)

舉個(gè)例子:

有如下代碼文件

#!/usr/bin/python# -*- coding: UTF-8 -*-'''@author:chenshifeng@file:test_allure.py@time:2020/10/10'''import allureimport [email protected](’登錄模塊’)class TestLogin(): @allure.story(’登錄成功’) @allure.title(’登錄成功標(biāo)題’) def test_login_sucess(self):with allure.step(’步驟1:打開應(yīng)用’): print(’應(yīng)用已打開’)with allure.step(’步驟2:進(jìn)入登錄頁面’): print(’登錄頁面已打開’)with allure.step(’步驟3:輸入用戶名和密碼’): print(’用戶名和密碼輸入成功’)print(’登錄測(cè)試用例:登錄成功’) @allure.story(’登錄成功’) def test_login_sucess2(self):assert ’1’ == 1print(’登錄測(cè)試用例:登錄成功’) @allure.story(’登錄失敗’) def test_login_failure_a(self):print(’登錄測(cè)試用例:登錄失敗,用戶名缺失’) @allure.story(’登錄失敗’) def test_login_failure_b(self):print(’登錄測(cè)試用例:登錄失敗,密碼缺失’) @allure.story(’登錄失敗’) def test_login_failure_c(self):with allure.step(’輸入用戶名’): print(’已輸入用戶名’)with allure.step(’輸入密碼’): print(’已輸入密碼’)with allure.step(’點(diǎn)擊登錄’): print(’已點(diǎn)擊登錄’)print(’登錄測(cè)試用例:登錄失敗,密碼錯(cuò)誤’)@allure.feature(’搜索模塊’)class TestSearch(): def test_search1(self):print(’搜索用例1’) TEST_CASE_LINK = ’https://mirrors.huaweicloud.com/’ @allure.testcase(TEST_CASE_LINK,’測(cè)試用例連接’) def test_search2(self):print(’搜索用例2’) @allure.step(’搜索步驟’) def test_search3(self):print(’搜索用例3’)

依次執(zhí)行命令: 

pytest test_allure.py --alluredir=./result --clean-alluredir

allure serve ./result

chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_allure.py --alluredir=./result --clean-alluredir============================================================================= test session starts =============================================================================platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.iniplugins: allure-pytest-2.8.18collected 8 items test_allure.py .F...... [100%]================================================================================== FAILURES ===================================================================================________________________________________________________________________ TestLogin.test_login_sucess2 _________________________________________________________________________self = <test_allure.TestLogin object at 0x7fef3d5cba90> @allure.story(’登錄成功’) def test_login_sucess2(self):> assert ’1’ == 1E AssertionError: assert ’1’ == 1test_allure.py:27: AssertionError=========================================================================== short test summary info ===========================================================================FAILED test_allure.py::TestLogin::test_login_sucess2 - AssertionError: assert ’1’ == 1========================================================================= 1 failed, 7 passed in 0.07s =========================================================================chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result Generating report to temp directory...Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/7024790777193223986/allure-reportStarting web server...2020-10-13 21:39:56.174:INFO::main: Logging initialized @6818ms to org.eclipse.jetty.util.log.StdErrLogServer started at <http://192.168.12.100:58977/>. Press <Ctrl+C> to exit

生成的報(bào)告:

python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告

allure特性-testcase

關(guān)聯(lián)測(cè)試用例(可以直接給測(cè)試用例的地址鏈接)

例子:

TEST_CASE_LINK = ’https://mirrors.huaweicloud.com/’@allure.testcase(TEST_CASE_LINK,’測(cè)試用例連接’)def test_search(self): print(’搜索用例’)

python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告

按重要性級(jí)別進(jìn)行一定范圍測(cè)試

通常測(cè)試有P0、冒煙測(cè)試、驗(yàn)證上線測(cè)試。按重要性級(jí)別來執(zhí)行的,比如上線要把主流程和重要模塊都跑一遍,可通過以下方法解決

通過附加@pytest.mark標(biāo)記

通過allure.feature,allure.story

也可以通過allure.severity來附加標(biāo)記

級(jí)別: trivial:不重要,輕微缺陷(必輸項(xiàng)無提示,或者提示不規(guī)范) minor 不太重要,次要缺陷(界面錯(cuò)誤與UI需求不符) normal:正常問題,普通缺陷(數(shù)值計(jì)算錯(cuò)誤) critical:嚴(yán)重,臨界缺陷(功能點(diǎn)缺失) blocker:阻塞,中斷缺陷(客戶端程序無響應(yīng),無法執(zhí)行下一步操作)

使用方法:

 在方法、函數(shù)和類上面加 @allure.severity(allure.severity_level.TRIVIAL)

執(zhí)行:

 pytest -s -v 文件名 --allure-severities normal,critical

舉例說明:

#!/usr/bin/python# -*- coding: UTF-8 -*-'''@author:chenshifeng@file:test_severity.py@time:2020/10/11'''import allureimport pytest# 不加任何標(biāo)記,默認(rèn)normaldef test_with_no_severity(): pass# trivial:不重要,輕微缺陷(必輸項(xiàng)無提示,或者提示不規(guī)范)@allure.severity(allure.severity_level.TRIVIAL)def test_with_trivial_severity(): pass# minor 級(jí)別 不太重要,次要缺陷(界面錯(cuò)誤與UI需求不符)@allure.severity(allure.severity_level.MINOR)def test_with_minor_severity(): pass# normal:正常問題,普通缺陷(數(shù)值計(jì)算錯(cuò)誤)@allure.severity(allure.severity_level.NORMAL)def test_with_normal_severity(): pass# critical:嚴(yán)重,臨界缺陷(功能點(diǎn)缺失)@allure.severity(allure.severity_level.CRITICAL)def test_with_ritical_severity(): pass# blocker:阻塞,中斷缺陷(客戶端程序無響應(yīng),無法執(zhí)行下一步操作)@allure.severity(allure.severity_level.BLOCKER)def test_with_blocker_severity(): [email protected](allure.severity_level.NORMAL)class TestClassWithNormalSeverity(object): # 不加任何標(biāo)記,默認(rèn)為同class級(jí)別 def test_inside_with_normal_severity(self):pass # 重新設(shè)置了critical級(jí)別 @allure.severity(allure.severity_level.CRITICAL) def test_inside_with_critical_severity(self):pass

執(zhí)行:

chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_severity.py --alluredir=./result --clean-alluredir -vs============================================================================= test session starts =============================================================================platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python3.9cachedir: .pytest_cacherootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.iniplugins: allure-pytest-2.8.18collected 8 items test_severity.py::test_with_no_severity PASSEDtest_severity.py::test_with_trivial_severity PASSEDtest_severity.py::test_with_minor_severity PASSEDtest_severity.py::test_with_normal_severity PASSEDtest_severity.py::test_with_ritical_severity PASSEDtest_severity.py::test_with_blocker_severity PASSEDtest_severity.py::TestClassWithNormalSeverity::test_inside_with_normal_severity PASSEDtest_severity.py::TestClassWithNormalSeverity::test_inside_with_critical_severity PASSED============================================================================== 8 passed in 0.03s ==============================================================================chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result Generating report to temp directory...Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/17788207943997663035/allure-reportStarting web server...2020-10-13 22:27:49.842:INFO::main: Logging initialized @6620ms to org.eclipse.jetty.util.log.StdErrLogServer started at <http://192.168.12.100:59696/>. Press <Ctrl+C> to exit

python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告

終極用例:

百度搜索:

#!/usr/bin/python# -*- coding: UTF-8 -*-'''@author:chenshifeng@file:test_baidudemo.py@time:2020/10/13'''import pytestimport allurefrom selenium import webdriverimport [email protected](’https://www.github.com’)@allure.feature('百度搜索')@pytest.mark.parametrize(’test_data1’,[’allure’,’pytest’,’unittest’])def test_steps_demo(test_data1): with allure.step(’打開百度網(wǎng)頁’):driver=webdriver.Chrome()driver.get(’http://www.baidu.com’)driver.maximize_window() with allure.step(f’輸入搜索詞:{test_data1}’):driver.find_element_by_id(’kw’).send_keys(test_data1)time.sleep(2)driver.find_element_by_id(’su’).click()time.sleep(2) with allure.step(’保存圖片’):driver.save_screenshot(’./screenshot/baidu.png’)allure.attach.file(’./screenshot/baidu.png’,attachment_type=allure.attachment_type.PNG) with allure.step(’關(guān)閉瀏覽器’):driver.quit()

執(zhí)行:

chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_baidudemo.py --alluredir=./result --clean-alluredir -vs============================================================================= test session starts =============================================================================platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python3.9cachedir: .pytest_cacherootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.iniplugins: allure-pytest-2.8.18collected 3 items test_baidudemo.py::test_steps_demo[allure] PASSEDtest_baidudemo.py::test_steps_demo[pytest] PASSEDtest_baidudemo.py::test_steps_demo[unittest] PASSED============================================================================= 3 passed in 24.65s ==============================================================================chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result Generating report to temp directory...Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/18005664130273264423/allure-reportStarting web server...2020-10-13 23:03:39.221:INFO::main: Logging initialized @7360ms to org.eclipse.jetty.util.log.StdErrLogServer started at <http://192.168.12.100:60775/>. Press <Ctrl+C> to exit

報(bào)告:

python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告

總結(jié)

到此這篇關(guān)于python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告的文章就介紹到這了,更多相關(guān)python allure生成測(cè)試報(bào)告內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产福利片在线 易阳 | 久久综合久久久久 | 黄色理论视频 | 久久久国产精品网站 | 欧美男人操女人 | 精品国产香港三级 | 欧美成人一区二区三区 | 国产xh98hx在线观看 | 国产高清国产专区国产精品 | 美女的被男人桶爽网站 | 欧美高清性色生活片免费观看 | 午夜爽爽视频 | 成人a毛片在线看免费全部播放 | 国产一级做a爰片... | 久热国产在线视频 | 成人性动漫高清免费观看网址 | 久久久精品一区二区三区 | 亚洲一级毛片免费看 | 日本久久不射 | 性高湖久久久久久久久 | 欧美一级xxx | 亚洲欧美在线精品一区二区 | 成人三级做爰在线观看男女 | 国产精品久久久久影视不卡 | 日韩在线一区二区三区视频 | 俄罗斯毛片免费大全 | 欧美一级xxx | 免费看 s色 | 一区二区三区四区在线播放 | 国产成人精品一区二区秒拍 | 亚洲综合91社区精品福利 | 欧美成人亚洲国产精品 | 一 级 黄 色 大片 | 国产乱码精品一区二区三区中 | 久久久久琪琪去精品色村长 | 一本一道久久综合狠狠老 | 国产性tv国产精品 | 久久久国产99久久国产久 | 免费国产a理论片 | 久久99视频精品 | 毛片视频在线免费观看 |