最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2021年06月03日 08:41:53   作者:Yu_擺擺  
這篇文章主要介紹了allure結(jié)合python生成測(cè)試報(bào)告教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

百度搜索實(shí)例

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

本案例來自于霍格沃茲測(cè)試學(xué)院《高薪測(cè)試成長(zhǎng)圖譜》。data.yml為數(shù)據(jù)管理文件,test_baidudemo.py為測(cè)試用例文件,文件結(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()

二、運(yùn)行結(jié)果

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

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

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

在這里插入圖片描述

問題解決

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

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

allure簡(jiǎn)介與使用

allure簡(jiǎn)介

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

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

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

在這里插入圖片描述

在這里插入圖片描述

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

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

在這里插入圖片描述

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

在這里插入圖片描述

在這里插入圖片描述

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

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

在這里插入圖片描述

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

在這里插入圖片描述

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

在這里插入圖片描述

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

在這里插入圖片描述

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

在這里插入圖片描述

測(cè)試報(bào)告

在這里插入圖片描述

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

相關(guān)文章

最新評(píng)論

平安县| 荆州市| 灵宝市| 织金县| 娄底市| 贺兰县| 福贡县| 昭平县| 合山市| 东阿县| 桃园市| 永安市| 长宁县| 黄大仙区| 寿宁县| 凉城县| 海南省| 铜陵市| 剑川县| 扶余县| 孟津县| 松滋市| 上虞市| 邹平县| 保靖县| 巴马| 溆浦县| 天台县| 潼南县| 滦南县| 皮山县| 宣威市| 太湖县| 方城县| 洛阳市| 万载县| 台南县| 涡阳县| 金秀| 桐梓县| 梁河县|