当前位置:首页 > Web开发 > 正文

pointer);$(#collapser).click(function() {$(SCENARIOS).sibli

2024-03-31 Web开发

后台处事是 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 =http://www.mamicode.com/ 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(/&lt;span class=http://www.mamicode.com/&quot;(.*?)&quot;&gt;/, '<span class="1">').gsub(/&lt;/span&gt;/, '</span>’) # 包罗 '.json’ 部分的 param 做 UrlEncode ,不包罗的删去<a>标签 if step_name.include? '.json' name << h(step_name).gsub(/&lt;span class=http://www.mamicode.com/&quot;(.*?)&quot;&gt;/, '<span class="1">').gsub(/&lt;/span&gt;/, '</span>').gsub(/&lt;a href=http://www.mamicode.com/&quot;(.*?)&quot; target=&quot;_blank&quot;&gt;/, '<a href="1" target="_blank">').gsub(/&lt;/a&gt;/, '</a>') else name << h(step_name).gsub(/&lt;span class=http://www.mamicode.com/&quot;(.*?)&quot;&gt;/, '<span class="1">').gsub(/&lt;/span&gt;/, '</span>').gsub(/&lt;a href=http://www.mamicode.com/&quot;(.*?)&quot; target=&quot;_blank&quot;&gt;/, '').gsub(/&lt;/a&gt;/, '') end end end step_file =http://www.mamicode.com/ step_match.file_colon_line step_file.gsub(/^([^:]*.rb):(d*)/) do if ENV['TM_PROJECT_DIRECTORY'] step_file =http://www.mamicode.com/ "<a href=http://www.mamicode.com/"txmt://open?url=file://#{File.expand_path($1)}&line=http://www.mamicode.com/#{$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

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30784.html