当前位置: 首页 > news >正文

自己做网站想更换网址石碣东莞网站建设

自己做网站想更换网址,石碣东莞网站建设,山东建大建设集团有限公司,素马设计顾问讲解价格前言 pytest-html 是一个用于生成漂亮的 HTML 测试报告的 pytest 插件。它可以方便地将 pytest 运行的测试结果转换为易于阅读和理解的 HTML 报告#xff0c;提供了丰富的测试结果展示功能和交互性。 一、安装 # 版本查看命令 pytest版本#xff1a; pytest --version pyte…前言 pytest-html 是一个用于生成漂亮的 HTML 测试报告的 pytest 插件。它可以方便地将 pytest 运行的测试结果转换为易于阅读和理解的 HTML 报告提供了丰富的测试结果展示功能和交互性。 一、安装 # 版本查看命令 pytest版本 pytest --version pytest-html版本 pip show pytest-html# 安装指定版本在V3.2.0版本报告中中文显示乱码目前不知道什么原因 卸载pytest-html pip uninstall pytest-html 安装指定版本 pip install pytest-html3.1.1# 当前演示环境版本 pytest版本7.4.0 pytest-html版本3.1.1二、生成方法 1、生成默认报告 # test_run.py import pytestdef test_A():执行A测试用例assert Truedef test_B():执行B测试用例assert Truedef test_C():执行C测试用例assert Falseif __name__ __main__:pytest.main([test_run.py, -v, --html./directory/report.html,--self-contained-html]) # --html./directory/report.html 在当前directory目录下生成普通HTML报告CSS是独立的 # --self-contained-html合并CSS的HTML报告默认报告样式 2、修改报告样式   在测试用例的同目录下新建conftest.py文件并复制以下内容 # conftest.py import pytest from py._xmlgen import html from time import strftime# 一、修改测试报告标题 # 使用带有optionalhookTrue的hookimpl装饰器 pytest.hookimpl(optionalhookTrue) def pytest_html_report_title(report):# 设置报告标题report.title 自动化测试报告# 二、修改Summary部分的信息 pytest.mark.parametrize def pytest_html_results_summary(prefix, summary, postfix):# 添加自定义的段落信息prefix.extend([html.p(所属部门测试组)])prefix.extend([html.p(测试人员张三)])# 三、修改Results部分的信息 def pytest_html_results_table_header(cells):# 在索引1处插入“描述”列标题cells.insert(1, html.th(Description))# 在索引2处插入“任务完成时间”列标题cells.insert(2, html.th(TaskCompleteTime))# 删除最后一列“link列”cells.pop(-1)def pytest_html_results_table_row(report, cells):# 在索引1处插入报告的描述信息cells.insert(1, html.td(report.Description))# 在索引2处插入报告的任务完成时间信息cells.insert(2, html.td(report.TaskCompleteTime))# 删除最后一列“link”cells.pop(-1)pytest.hookimpl(hookwrapperTrue) def pytest_runtest_makereport(item, call):outcome yieldreport outcome.get_result()# 将报告的描述信息设置为测试项的文档字符串report.Description str(item.function.__doc__)# 将报告的任务完成时间设置为当前时间report.TaskCompleteTime str(strftime(%Y-%m-%d %H:%M:%S))运行test_run.py生成报告 3、用例失败自动截图 # test_run.py import pytest from selenium import webdriver from time import sleeppytest.fixture(scopefunction) def setup_browser():设置和关闭浏览器的测试夹具driver webdriver.Chrome()driver.maximize_window()yield driver # 返回driver对象供测试使用driver.quit() # 测试结束后关闭浏览器pytest.fixture(params[(https://www.baidu.com/, 百度一下你就知道),(https://www.csdn.net/, CSDN - 专业开发者社区),(https://www.youdao.com/, 网易有道失败)],ids[百度网址验证用例, CSDN网址验证用例, 网易网址验证用例]) def parametrize_search_engine(request):参数化的搜索引擎测试夹具return request.paramdef test_navigation(setup_browser, parametrize_search_engine):测试网页是否能正常打开并显示内容driver setup_browser # 获取浏览器驱动对象keyword, engine parametrize_search_engine# 请求网址driver.get(keyword)# 等待2秒sleep(2)assert driver.title engine # 检查打开的页面标题是否与期望结果一致if __name__ __main__:pytest.main([test_run.py, -v, --html./directory/report.html,--self-contained-html])# conftest.py import pytest import pyautogui import base64 import iopytest.hookimpl(hookwrapperTrue) def pytest_runtest_makereport(item):pytest_runtest_makereport是一个钩子函数用于在每个测试用例执行完成后生成测试报告item参数表示当前正在执行的测试用例# 获取pytest-html插件实例用于生成HTML格式的测试报告pytest_html item.config.pluginmanager.getplugin(html)# yield语句暂停函数的执行并返回给调用方一个值被yield关键字后面的值# 当函数恢复执行时outcome变量将接收到yield语句后面yielded的值outcome yield# 从outcome中获取测试用例的结果报告report outcome.get_result()# 获取report对象的extra属性如果不存在则返回一个空列表extra getattr(report, extra, [])# 如果测试用例是在call或setup阶段执行时# 也就是在测试用例被调用执行或设置阶段出现问题时if report.when call or report.when setup:# 检查报告对象中是否有wasxfail属性表示测试用例是否被标记为预期失败xfailxfail hasattr(report, wasxfail)# 如果测试用例被跳过且是预期失败或者测试用例执行失败且不是预期失败if (report.skipped and xfail) or (report.failed and not xfail):# 使用pyautogui库进行屏幕截图screenshot pyautogui.screenshot()# 创建一个BytesIO对象用于存储屏幕截图的二进制数据screenshot_buffer io.BytesIO()# 将屏幕截图保存到BytesIO对象中格式为PNGscreenshot.save(screenshot_buffer, formatPNG)# 使用base64对屏幕截图的二进制数据进行编码得到base64编码后的字符串screenshot_base64 base64.b64encode(screenshot_buffer.getvalue()).decode(utf-8)# 构建一个HTML的div元素其中包含一个img元素用于显示屏幕截图# 图片源使用base64编码的字符串点击图片时可以在新窗口打开原始截图# div元素的样式设置了图片的宽度和高度并将其右对齐html divimg srcdata:image/png;base64,{} altscreenshot stylewidth:500px;height:260px; \οnclickwindow.open(this.src) alignright//div.format(screenshot_base64)# 将构建的HTML字符串添加到extra列表中作为测试报告的额外信息extra.append(pytest_html.extras.html(html))# 将extra列表设置为报告对象report的extra属性更新测试报告的额外信息report.extra extra运行test_run.py生成报告 4、完整代码 # conftest.py import pytest from py._xmlgen import html from time import strftime import pyautogui import base64 import io# 一、修改测试报告标题 pytest.hookimpl(optionalhookTrue) def pytest_html_report_title(report):report.title 自动化测试报告# 二、修改Summary部分的信息 pytest.mark.parametrize def pytest_html_results_summary(prefix, summary, postfix):prefix.extend([html.p(所属部门测试组)])prefix.extend([html.p(测试人员张三)])# 三、修改Results部分的信息并自动截取错误截图 def pytest_html_results_table_header(cells):cells.insert(1, html.th(Description))cells.insert(2, html.th(TaskCompleteTime))cells.pop(-1)def pytest_html_results_table_row(report, cells):cells.insert(1, html.td(report.Description))cells.insert(2, html.td(report.TaskCompleteTime))cells.pop(-1)pytest.hookimpl(hookwrapperTrue) def pytest_runtest_makereport(item):pytest_html item.config.pluginmanager.getplugin(html)outcome yieldreport outcome.get_result()report.Description str(item.function.__doc__)report.TaskCompleteTime str(strftime(%Y-%m-%d %H:%M:%S))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):screenshot pyautogui.screenshot()screenshot_buffer io.BytesIO()screenshot.save(screenshot_buffer, formatPNG)screenshot_base64 base64.b64encode(screenshot_buffer.getvalue()).decode(utf-8)html divimg srcdata:image/png;base64,{} altscreenshot stylewidth:500px;height:260px; \οnclickwindow.open(this.src) alignright//div.format(screenshot_base64)extra.append(pytest_html.extras.html(html))report.extra extra
http://www.zqtcl.cn/news/134478/

相关文章:

  • 制作属于自己的app教程北京和隆优化招聘
  • wordpress会员卡系统青岛百度优化
  • 网站的管理系统网站权限配置
  • 龙岗高端网站建设在进行网站设计时
  • 网站制作定制浙江交工宏途交通建设有限公司网站
  • 域名网站计划怎么写高端网站建设 引擎技
  • 做自己的网站流量怎么桂林人论坛桂林板路
  • 上海制作网站多少钱wordpress主题站主题
  • 企业网站开发软件WordPress访问者ip
  • 视频网站dedecms在源码之家下载的网站模板可以作为自己的网站吗
  • 西宁好的网站建设公司怎样将视频代码上传至网站
  • 内网网站开发专业建站公司报价
  • 做地方网站需要什么部门批准天津专业做标书
  • 域名注册信息查询网站推广seo是什么
  • 做外贸网站哪家公司好常见的管理系统
  • 网站设计报价方案微信公众号外包
  • 网站设计遇到难题wordpress qq 微博
  • 网站模板种类长沙seo推广优化
  • 郑州网络建站公司wordpress安装及配置
  • 福州移动网站建设公司注册地址怎么写
  • 网站线上投票怎样做做铁艺需要什么网站
  • 襄阳营销型网站建设网站开发语言排行榜
  • 网站架构演变流程淄博亿泰
  • 电子商务网站功能介绍招商网站建设
  • 哈尔滨模板网站建站市场监督管理局12315
  • 做网站图片处理问题淘宝客推广
  • 科目一速成网站建设适合网络科技的公司名字
  • 解决网站兼容性问题网站关于我们怎么做
  • 网站建设教学视频百度云盘wap什么意思网络语言
  • 做psd模板下载网站搜索网站哪个好