国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

allure結(jié)合python生成測試報(bào)告教程

瀏覽:26日期:2022-06-17 15:52:18

百度搜索實(shí)例

一、代碼結(jié)構(gòu)

本案例來自于霍格沃茲測試學(xué)院《高薪測試成長圖譜》。data.yml為數(shù)據(jù)管理文件,test_baidudemo.py為測試用例文件,文件結(jié)構(gòu)如下:

allure結(jié)合python生成測試報(bào)告教程

創(chuàng)建data/data.yml文件,代碼如下

- allure- pytest- unittest

創(chuàng)建test_baidudemo.py,代碼如下

#!/usr/bin/env python# -*- coding: utf-8 -*-from __future__ import unicode_literalsimport allureimport pytestimport yamlfrom selenium import webdriverimport [email protected]('https://www.baidu.com')@allure.feature('百度搜索')@pytest.mark.parametrize(’test_data1’,yaml.safe_load(open('data/data.yml')))def test_steps_demo(test_data1): with allure.step('打開百度網(wǎng)頁'):driver = webdriver.Chrome()driver.get('https://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('./result/b.png')allure.attach.file('./result/b.png',attachment_type=allure.attachment_type.PNG) with allure.step('關(guān)閉瀏覽器'):driver.quit()二、運(yùn)行結(jié)果

進(jìn)入項(xiàng)目目錄下,使用以下語句運(yùn)行

pytest test_baidudemo.py -s -q --alluredir=./result/ #執(zhí)行測試用例,并生成測試報(bào)告數(shù)據(jù)在當(dāng)前文件夾result文件下allure serve ./result/ #啟動allure,并使用result下的測試結(jié)果數(shù)據(jù)生成測試報(bào)告

生成的報(bào)告如下圖所示:

allure結(jié)合python生成測試報(bào)告教程

allure結(jié)合python生成測試報(bào)告教程

問題解決

運(yùn)行時(shí)總是報(bào)錯(cuò)當(dāng)前chromedriver只支持chrome78,實(shí)際上已經(jīng)更新了chromedriver83,未找到原因解決,最終在代碼里加上chromedriver絕對路徑。將driver = webdriver.Chrome()修改為driver = webdriver.Chrome(‘C:Program Files (x86)GoogleChromeApplicationchromedriver.exe’)。

with allure.step(f'輸入搜索詞:{test_data1}'):,在python3.6.8版本上運(yùn)行該語句總是報(bào)語法錯(cuò)誤,修改為 with allure.step(“輸入搜索詞:”+test_data1):,可以正常運(yùn)行并輸出。

allure簡介與使用allure簡介

Allure是一款輕量級并且非常靈活的開源測試報(bào)告框架。 它支持絕大多數(shù)測試框架, 例如TestNG、Pytest、JUint等。它簡單易用,易于集成。

allure如何生成測試報(bào)告

運(yùn)行的時(shí)候加上 pytest.main ( ‘?alluredir’, ‘report/result’, ‘TestDemo01.py’]) 會在當(dāng)前文件夾創(chuàng)建一個(gè)report文件夾,在report文件夾下創(chuàng)建result

allure結(jié)合python生成測試報(bào)告教程

allure結(jié)合python生成測試報(bào)告教程

生成html測試報(bào)告

因?yàn)樯傻臏y試報(bào)告是json的,不好看,所有用這個(gè)命令生成一個(gè)好看的HTML測試報(bào)告

allure結(jié)合python生成測試報(bào)告教程

運(yùn)行之后,就會生成一個(gè)HTML文件夾,點(diǎn)開index.html這個(gè)就是我們的測試報(bào)告啦

allure結(jié)合python生成測試報(bào)告教程

allure結(jié)合python生成測試報(bào)告教程

allure幾個(gè)常用特性(測試報(bào)告中展示)

@allure.feature (用于描述被測試產(chǎn)品需求)

allure結(jié)合python生成測試報(bào)告教程

@allure.story (用于描述feature的用戶場景,即測試需求)

allure結(jié)合python生成測試報(bào)告教程

with allure.step() (用于描述測試步驟,將會輸出到報(bào)告中)

allure結(jié)合python生成測試報(bào)告教程

allure.attach (用于向測試報(bào)告中輸入一些附加的信息,通常是一些測試數(shù)據(jù),截圖等)

allure結(jié)合python生成測試報(bào)告教程

pytest斷言設(shè)置并結(jié)合allure生成測試報(bào)告

allure結(jié)合python生成測試報(bào)告教程

測試報(bào)告

allure結(jié)合python生成測試報(bào)告教程

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产精品久久精品 | 国产男女爽爽爽爽爽视频 | 久草在线免费资源站 | 久久r这里只有精品 | 国产91啦 | 成人软件18免费 | 久久久久久日本一区99 | 欧美资源在线观看 | 99精品国产一区二区三区 | 国产成人一区二区三区在线视频 | 久久久精品影院 | 福利视频黄 | 欧洲精品一区二区三区在线观看 | 欧美日韩一区二区在线观看 | 日韩三级视频在线 | 欧美一及| 久久91亚洲精品中文字幕奶水 | 国产亚洲精品自在久久77 | 女人张开腿给人桶免费视频 | 久99频这里只精品23热 视频 | 欧美日韩高清不卡一区二区三区 | 男女性男女刺激大片免费观看 | 欧美一级网址 | 日韩中文在线 | 亚洲精品区一区二区三区四 | 免费ab| 播放一级毛片 | 中国老妇另类xxxx | 在线国产一区 | 日本黄色毛片 | 久久免费看片 | 国产盗摄精品一区二区三区 | 欧美特黄aaaaaaaa大片 | 在线免费观看一级片 | 国产日产欧产精品精品推荐在线 | 在线看黄网址 | 欧美另类69xxxxx极品 | 国产欧美一区视频在线观看 | 国产精品久久久久影视不卡 | 国产三级日本三级日产三级66 | 日韩视频在线观看一区 |