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

您的位置:首頁技術文章
文章詳情頁

allure結合python生成測試報告教程

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

百度搜索實例

一、代碼結構

本案例來自于霍格沃茲測試學院《高薪測試成長圖譜》。data.yml為數據管理文件,test_baidudemo.py為測試用例文件,文件結構如下:

allure結合python生成測試報告教程

創建data/data.yml文件,代碼如下

- allure- pytest- unittest

創建test_baidudemo.py,代碼如下

#!/usr/bin/env python# -*- coding: utf-8 -*-from __future__ import unicode_literalsimport allureimport pytestimport yamlfrom selenium import webdriverimport time@allure.testcase('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('打開百度網頁'):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('關閉瀏覽器'):driver.quit()二、運行結果

進入項目目錄下,使用以下語句運行

pytest test_baidudemo.py -s -q --alluredir=./result/ #執行測試用例,并生成測試報告數據在當前文件夾result文件下allure serve ./result/ #啟動allure,并使用result下的測試結果數據生成測試報告

生成的報告如下圖所示:

allure結合python生成測試報告教程

allure結合python生成測試報告教程

問題解決

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

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

allure簡介與使用allure簡介

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

allure如何生成測試報告

運行的時候加上 pytest.main ( ‘?alluredir’, ‘report/result’, ‘TestDemo01.py’]) 會在當前文件夾創建一個report文件夾,在report文件夾下創建result

allure結合python生成測試報告教程

allure結合python生成測試報告教程

生成html測試報告

因為生成的測試報告是json的,不好看,所有用這個命令生成一個好看的HTML測試報告

allure結合python生成測試報告教程

運行之后,就會生成一個HTML文件夾,點開index.html這個就是我們的測試報告啦

allure結合python生成測試報告教程

allure結合python生成測試報告教程

allure幾個常用特性(測試報告中展示)

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

allure結合python生成測試報告教程

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

allure結合python生成測試報告教程

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

allure結合python生成測試報告教程

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

allure結合python生成測試報告教程

pytest斷言設置并結合allure生成測試報告

allure結合python生成測試報告教程

測試報告

allure結合python生成測試報告教程

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 久久精品国产精品亚洲毛片 | 美女被男人cao的爽视频黄 | 欧美一区二区三区视频在线观看 | 亚洲免费天堂 | 精品国产成人综合久久小说 | 久久99国产一区二区三区 | 三级色网站 | 国产免费一区二区在线看 | 亚洲线精品久久一区二区三区 | 国产日韩一区二区三区在线播放 | 精品欧美高清不卡在线 | 国产91精选在线观看网站 | 欧美性色一级在线观看 | 黄色福利网 | 最近最新中文字幕免费的一页 | 亚洲欧美第一 | 久久成人国产 | 成人18网站 | 精品国产一区二区三区成人 | 国产成人丝袜视频在线视频 | 一区二区三区精品视频 | 国产精品久久久久9999小说 | 日本免费不卡在线一区二区三区 | 久久精品国产午夜伦班片 | 成人国产精品免费网站 | 久久久久久国产精品免费免 | 精品视频在线一区 | 操她视频网站 | 第一区免费在线观看 | 中文在线视频观看 | 波多野结衣在线播放视频 | 亚洲综合在线观看视频 | 无码精品一区二区三区免费视频 | 3d动漫精品成人一区二区三 | 91高清免费国产自产 | 精品久久久久久久久久久久久久久 | 精品欧美成人高清视频在线观看 | 在线观看视频亚洲 | 颜值超高的女神啪啪 | 国产精品久久久精品三级 | 国产cao|