濮阳杆衣贸易有限公司

主頁 > 知識庫 > allure結(jié)合python生成測試報告教程

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

熱門標(biāo)簽:朝陽手機外呼系統(tǒng) 所得系統(tǒng)電梯怎樣主板設(shè)置外呼 小蘇云呼電話機器人 地圖標(biāo)注面積 佛山400電話辦理 北瀚ai電銷機器人官網(wǎng)手機版 北京電銷外呼系統(tǒng)加盟 儋州電話機器人 市場上的電銷機器人

百度搜索實例

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

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

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

- allure
- pytest
- unittest

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

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import allure
import pytest
import yaml
from selenium import webdriver
import 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("打開百度網(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()

二、運行結(jié)果

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

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

生成的報告如下圖所示:

問題解決

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

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

allure簡介與使用

allure簡介

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

allure如何生成測試報告

運行的時候加上 pytest.main ( ‘–alluredir', ‘report/result', ‘TestDemo01.py']) 會在當(dāng)前文件夾創(chuàng)建一個report文件夾,在report文件夾下創(chuàng)建result

生成html測試報告

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

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

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

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

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

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

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

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

測試報告

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • python自動化之如何利用allure生成測試報告
  • 詳解用Pytest+Allure生成漂亮的HTML圖形化測試報告
  • Pytest allure 命令行參數(shù)的使用

標(biāo)簽:金融催收 云南 寧夏 龍巖 商丘 酒泉 定西 江蘇

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《allure結(jié)合python生成測試報告教程》,本文關(guān)鍵詞  allure,結(jié)合,python,生成,測試,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《allure結(jié)合python生成測試報告教程》相關(guān)的同類信息!
  • 本頁收集關(guān)于allure結(jié)合python生成測試報告教程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    应用必备| 南江县| 周口市| 桑植县| 德州市| 大冶市| 连云港市| 邹平县| 沂南县| 海晏县| 张家界市| 原阳县| 博乐市| 大田县| 古浪县| 龙泉市| 庆城县| 吴桥县| 垫江县| 巴塘县| 晋宁县| 屏山县| 秀山| 阿城市| 河曲县| 洮南市| 文化| 五寨县| 镇原县| 日土县| 信宜市| 巴彦淖尔市| 五大连池市| 沈阳市| 天气| 衡山县| 东城区| 四平市| 遂川县| 遂溪县| 乌兰县|