首页 > 其他分享 >pytest html报告

pytest html报告

时间:2023-01-31 17:14:16浏览次数:32  
标签:报告 -- driver html pytest report browser

pytest-html是pytest用于生成测试结果的html插件。可以登录github下载,可以使用pip进行安装。 pip安装命令:pip install pytest-html 以下是pytest-html通过pip安装的截图 0

运行html获取报告

  执行语句:pytest --html=report.html 0   report.html 0

指定路径存放

  命令:pytest --html=./assert/report.html 0 0

独立显示报告

  独立显示报告是为了分享报告时,界面依旧能按照原样式显示。   命令: pytest --html=report.html --self-contained-html 0

pytest错误截图

# conftest.py
# coding:utf-8
import time
from selenium import webdriver
import pytest

driver = None

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()
    extra = getattr(report, 'extra', [])

    if report.when == 'call' or report.when == "setup":
        xfail = hasattr(report, 'wasxfail')
        if (report.skipped and xfail) or (report.failed and not xfail):
            file_name = report.nodeid.replace("::", "_") + ".png"
            screen_img = _capture_screenshot()
            if file_name:
                html = '<div><img src="data:image/png;base64,%s" alt="screenshot" style="width:600px;height:300px;" ' \
                       'onclick="window.open(this.src)" align="right"/></div>' % screen_img
                extra.append(pytest_html.extras.html(html))
        report.extra = extra
        report.description = str(item.function.__doc__)

def _capture_screenshot():
    return driver.get_screenshot_as_base64()

@pytest.fixture(scope='session', autouse=True)
def browser(request):
    global driver
    if driver is None:
        driver = webdriver.Firefox()

    def end():
        driver.quit()
    request.addfinalizer(end)
    return driver
# test_1.py
import time
def test_yoyo_01(browser):
    browser.get("https://www.cnblogs.com/qmm-1000/")
    time.sleep(2)
    t = browser.title
    assert t == "乌醍"
# test_02.py
def test_02(browser):
    browser.get("https://www.cnblogs.com/qmm-1000/")
    time.sleep(2)
    t = browser.title
    assert '乌醍' in t
0

pytest 失败重跑

  失败重跑需要借助pytest-rerunfailures插件   下载指令:     pip install pytest-rerunfailures   失败重跑命令:     pytest --rerun 1 --html=report.html --self-contained-html (rerun后写几次运行几次) 0  

标签:报告,--,driver,html,pytest,report,browser
From: https://www.cnblogs.com/qmm-1000/p/17079836.html

相关文章

  • 电动自行车亚马逊UL2849测试报告
    UL2849测试报告流程1、申请人向五祥检测提出申请。2、申请人填写申请表,说明书和技术文件一并提供给五祥检测。3、五祥检测确定测试标准及测试项目并报价。4、申请人确认报价......
  • 电动自行车CE认证EN15194测试报告
    2009年欧盟推出了新的电动助力自行车标准EN15194,EN15194标准为国际第一个针对电动助力自行车的安全标准,产品通过EN15194检测可以证明产品符合国际一流水平,并且对企业开拓市......
  • 初识pytest
    安装pytestpipinstallpytest检查安装的pytest版本信息是否正确pytest--version创建测试deffunc(x):returnx+1deftest_answer():assertfunc(3)==5运行......
  • HTML标签
    HTML标签(上)1.1语法规范:标签是由尖括号包围的关键词,eg:<html>通常是成对出现的,eg:<html></html>称为双标签有特殊的标签是单个标签,<br/>单标签1.2标签关系双......
  • 一个简单的pytest例子
    1、安装pytestpipinstallpytest2、发现用例规则   3、运行方式   4、运行参数   5、pytest框架结构   6、fixture    forexamp......
  • HTML5新标签
      最近在学习Vue的基础知识,发现有关H5的新内容不是很熟悉,再次整理一下1.头部标签<header><header></header> 2.导航标签<nav><nav>导航</nav> 3.......
  • Codeforces Round #846 (Div. 2) 解题报告
    前情提要:我是沙币比赛链接A.Hayatoand贪心,不大想讲代码写的很丑voidsolve(){ vector<int>a; intn,x; cin>>n; a.push_back(0); for(inti=1;i<=n;++i)......
  • HTML5实现动态视频背景
    HTML5实现动态视频背景html代码<videoid="v1"autoplayloopmuted><sourcesrc="https://wallpaperm-mp4.duba.com/scene/preview_video/97ba6b60662ab4f31ef0......
  • Html 页面 如何等比例缩小 放大
    Html页面如何等比例缩小放大<!--缩小0.8倍-->style="transform:scale(0.8,0.8);"......
  • 解决html2canvas.js和pdf.js导出页面问题
    最近在做项目时有这么一个需求,需要将当前html页面导出pdf到本地。由于之前是做过类似的功能的借助了两个插件分别是html2canvas.js和pdf.js,本以为是非常顺利就能完成的,实......