修改 Cucumber HTML 报告
后台服务是 JSON-RPC 风格的,所以 Scenario 都是这样的
Scenario: login successful
When I set request body from "features/examples/login.json”
When I send a POST request to "/app_api/session/authenticate/“
Then the response status should be "200"
Then the JSON response should follow "features/schemas/login_response.schema.json"
Then the JSON response should have key "$.result.username" with "cucumbertest”
HTML 报告是这样的
项目目录结构是这样的
.
└── features
├── examples
│ └── login.json
├── schemas
│ └── login_response.schema.json
├── step_definitions
│ └── setp.rb
├── support
│ └── env.rb
└── user.feature
现在想把 features/examples/login.json 和 features/schemas/login_response.schema.json 这部分加上超链接,点击后显示相应文件内容,把
<span class="param">features/examples/login.json</span>
改为
<a href="features/examples/login.json" target="_blank">features/examples/login.json</a>
在源码里搜索span class="param”
,发现拼接这部分 HTML 的是 lib/cucumber/formatter/html.rb 文件里的 build_step 方法
在 features/support 目录下新建 html_with_link.rb 文件,输入
require 'cucumber/formatter/html'
module Cucumber
module Formatter
class HtmlWithLink < Html
def build_step(keyword, step_match, status)
# step_name = step_match.format_args(lambda{|param| %{<span class="param">#{param}</span>}})
# 加上<a>标签
step_name = step_match.format_args(lambda{|param| %{<span class="param"><a href="#{param}" target="_blank">#{param}</a></span>}})
@builder.div(:class => 'step_name') do |div|
@builder.span(keyword, :class => 'keyword')
@builder.span(:class => 'step val') do |name|
# name << h(step_name).gsub(/<span class="(.*?)">/, '<span class="1">').gsub(/</span>/, '</span>’)
# 包含 '.json’ 部分的 param 做 UrlEncode ,不包含的删去<a>标签
if step_name.include? '.json'
name << h(step_name).gsub(/<span class="(.*?)">/, '<span class="1">').gsub(/</span>/, '</span>').gsub(/<a href="(.*?)" target="_blank">/, '<a href="1" target="_blank">').gsub(/</a>/, '</a>')
else
大专栏 修改 Cucumber HTML 报告class="nb">name << h(step_name).gsub(/<span class="(.*?)">/, '<span class="1">').gsub(/</span>/, '</span>').gsub(/<a href="(.*?)" target="_blank">/, '').gsub(/</a>/, '')
end
end
end
step_file = step_match.file_colon_line
step_file.gsub(/^([^:]*.rb):(d*)/) do
if ENV['TM_PROJECT_DIRECTORY']
step_file = "<a href="txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}">#{$1}:#{$2}</a> "
end
end
@builder.div(:class => 'step_file') do |div|
@builder.span do
@builder << step_file
end
end
end
end
end
end
执行cucumber -f Cucumber::Formatter::HtmlWithLink -o result.html
,新的报告里有链接了
另一种改法
require 'cucumber/formatter/html'
module Cucumber
module Formatter
class HtmlWithLink < Html
def inline_js_content
<<-EOF
SCENARIOS = "h3[id^='scenario_'],h3[id^=background_]";
$(document).ready(function() {
$(SCENARIOS).css('cursor', 'pointer');
$(SCENARIOS).click(function() {
$(this).siblings().toggle(250);
});
$("#collapser").css('cursor', 'pointer');
$("#collapser").click(function() {
$(SCENARIOS).siblings().hide();
});
$("#expander").css('cursor', 'pointer');
$("#expander").click(function() {
$(SCENARIOS).siblings().show();
});
// 下面是新加的
$("span.param").each(function(index,element){
if ($(element).text().indexOf(".json") > 0) {
text = $(element).text()
href = "<a>" + text + "</a>"
$(element).html(href)
$(element).children("a").attr({
"href" : text,
"target" : "_blank"
});
}
});
// 上面是新加的
})
function moveProgressBar(percentDone) {
$("cucumber-header").css('width', percentDone +"%");
}
function makeRed(element_id) {
$('#'+element_id).css('background', '#C40D0D');
$('#'+element_id).css('color', '#FFFFFF');
}
function makeYellow(element_id) {
$('#'+element_id).css('background', '#FAF834');
$('#'+element_id).css('color', '#000000');
}
EOF
end
end
end
end
参考文章:Is it possible to generate cucumber html reports with only scenario titles with out steps?
Til next time,
黑水
at 09:45
修改 Cucumber HTML 报告的更多相关文章
- 48.Odoo产品分析 (五) – 定制板块(3) – 修改文件和报告(1)
查看Odoo产品分析系列--目录 不管ERP系统中的内置报表有多完善,大多数的公司仍然需要对文档和报表进行一些自定义的修改. 这一章节将介绍如何对报表的页眉和页脚做自定义修改:odoo框架如何组织报 ...
- ddt源码修改:HtmlTestRunner报告依据接口名显示用例名字
背景是这样的: 自己写了一套接口自动化的框架,其中使用unittest + ddt + excel作为数据驱动模式的应用,使用HtmlTetstRunner来生成测试用例. 一切看起来很完美. 但是, ...
- Jenkins传参修改jmeter的报告名称和详细报告地址
目前已经可以发送邮件了,我已经配置了Jenkins,但是有几个显示问题,待处理1.报告名称地址, 2详细报告地址没有做跳转 更改后为: 修改url 1.打开样式的jmeter-results-deta ...
- pytest-html报告修改与汉化
前言 Pytest框架可以使用两种测试报告,其中一种就是使用pytest-html插件生成的测试报告,但是报告中有一些信息没有什么用途或者显示的不太好看,还有一些我们想要在报告中展示的信息却没有,最近 ...
- 关于如何自定义修改pytest-html报告深度学习总结
第一.pytest-html执行命令总结: pytest test_case.py --html=report.html --self-contained-html 直接html独立显示pytest ...
- Cucumber(4)——jenkins的集成
目录 回顾 必备知识 集成方法 回顾 在上几节中,关于cucumber的知识我已经全部的介绍完了,但是近期,jenkins大行其道,在工作上面能为我们节省大量的时间. 所以在本节中,我会介绍cucum ...
- Jmeter默认报告优化
一.本文目的: 之前写了两篇文章搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)和ANT批量执行Jmeter脚本,功能实现上都没有什么问题,但是最后生成的报告有一点小问题,虽然不影响使 ...
- Week1项目报告
1. 预测时间 Personal Software Process Stages Time(h) 计划 · 估计这个任务需要多少时间 16.5 开发 · 需求分析 (包括学习新技术) 4 · 生成设计 ...
- 行为驱动:Cucumber + Selenium + Java(二) - extentreports 测试报告+jenkins持续集成
1.extentreports 测试报告 pom文件 <dependency> <groupId>com.vimalselvam</groupId> <art ...
随机推荐
- Python笔记_第四篇_高阶编程_GUI编程之Tkinter_5.鼠标事件
1. 鼠标点击事件: 图示: 实例: import tkinter from tkinter import ttk # 创建主窗口__编程头部 win = tkinter.Tk() # 设置标题 wi ...
- linux 中的.so和.a文件
Linux下的.so是基于Linux下的动态链接,其功能和作用类似与windows下.dll文件. 下面是关于.so的介绍: 一.引言 通常情况下,对函数库的链接是放在编译时期(compile tim ...
- [Python] 关于__init__.py
当目录结构为下面这样└── utils/│ ├── __init__.py│ └── config.py├── test.py 每个文件夹下都有__init__.py,一个目录如果包含了__init_ ...
- 翻译——1_Project Overview, Data Wrangling and Exploratory Analysis-checkpoint
为提高提高大学能源效率进行建筑能源需求预测 本文翻译哈佛大学的能源分析和预测报告,这是原文 暂无数据源,个人认为学习分析方法就足够 内容: 项目概述 了解数据 探索性分析 使用不同的机器学习方法进行预 ...
- 关于富文本字段问题(mysql)
1.表字段字符集建议使用: utf8mb4.utf8mb4_general_ci 2.保险起见spring-boot配置: spring:datasource:connection-init-sqls ...
- mysql 视图 事务 索引
为什么需要有视图 * 对于复杂的查询,往往是有多个数据表进行关联查询而得到,而这种语句往往比较复杂,也可能非常频繁的使用. 比如这样的SQL语句 select goods.name,goods_cat ...
- ZJNU 1138 - 小兔的棋盘——中级
二维图的动态规划因为不能穿越对角线,则选取对角线的一边dp即可选取对角线右下侧则x轴上每个点只能由其左侧的点走过去(只有1条)对角线上的点只能由对角线下方的点走过去其他点可以由左侧和下侧两种方式到达因 ...
- web前端——CSS详解
简介 CSS(Casading Style Sheet)是一组HTML元素外观的设置规则,用于控制web页面的表现形式,一般被翻译为"级联样式表"或"层叠样式表" ...
- 发生 Configuration system failed to initialize 错误的一个特例
一般情况下,.net 程序启动时发生 Configuration system failed to initialize 错误, 大都与 config 文件中 <configSections&g ...
- 基础篇五:Nginx的目录和基础配置
Yum安装目录:yum的方式安装 rpm -ql nginx 下面开始安装目录详解