修改 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 ...
随机推荐
- Hard Disk Driver(GPT)
GUID磁盘分区表(GUID Partition Table,缩写:GPT)其含义为“全局唯一标识磁盘分区表”,是一个实体硬盘的分区表的结构布局的标准.它是可扩展固件接口(EFI)标准(被Intel用 ...
- sql server2008 装上后,总是出现machine.config line136,或者 出现 配置错误 无法识别的配置节 system.serviceModel 。
怀疑问题是vs 和 sql server2008安装冲突的问题造成, 有一个这样的说法: 用win8.1的64位 的系统,如果先装vs2010,再装sql server 2008 r2,根本就不行,一 ...
- Prometheus监控系统之入门篇(一)续
在上篇Prometheus监控系统之入门篇(一)中我们讲解了Prometheus的基本架构和工作流程, 并从0到1搭建了Prometheus服务,pushgateway以及告警系统. 本篇我们主要介绍 ...
- Linux实验总结(第二周)
测试一--vi 每个.c一个文件,每个.h一个文件,文件名中最好有自己的学号 用Vi输入图中代码,并用gcc编译通过 在Vi中使用K查找printf的帮助文档 提交vi编辑过程截图,要全屏,包含自己的 ...
- SQLite-外键约束/表链接查询
外键约束: 表一的某个字段关联到表二的某个字段 例子: 国家表:t_country
- matlab2016b
http://www.cnblogs.com/CQBZOIer-zyy/p/5933954.html
- VUEJS文件扩展名esm.js和common.js是什么意思
vue.js : vue.js则是直接用在<script>标签中的,完整版本,直接就可以通过script引用. vue.common.js :预编译调试时,CommonJS规范的格式,可以 ...
- C# 基类派生类构造函数执行顺序分析
using System; namespace ConsoleApp1 { class Program{ static void Main(string[] args){ B b = new B(); ...
- 用windows下的Anaconda搭建Django虚拟环境
Django 是一个Python定制框架,可用于简便.快速的开发数据库驱动的web站点. 要使用Django,首先要建立一个虚拟工作环境. 那么,为什么要搭建虚拟环境呢?我们来看以下的开发场景: 假设 ...
- Java集合源码剖析——ArrayList源码剖析
ArrayList简介 ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,类似于C语言中的动态申请内存,动态增长内存. ArrayList不是线程安全的,只能用在单线程环境下,多线 ...