[英]Can I get timestamps for each step in cucumber?
In cucumber past, I seem to remember an option to get the time it took for each step to complete 在过去的黄瓜中,我似乎记得有一种选择来获取完成每个步骤所花费的时间
And I navigate to a widget with widget form
#features/step_definitions/common_sd.rb:26
### STEP COMPLETED 9.634963s
Thinking this functionality went away from cucumber, my work around was to add time stamp functionality to every snippet which feels clunky 认为此功能已脱离黄瓜,我的工作是将时间戳功能添加到每个感觉很笨拙的代码段
st = Time.now
...
step_end(st)
and 和
def step_end(st)
puts "### STEP COMPLETED #{(Time.now - st)}s"
end
I could use the env.rb
if I wanted universal hooks for the beginning and end of each scenario, but not steps as far as I can tell. 如果我想在每种情况的开始和结束时都使用通用钩子,则可以使用
env.rb
,但就我所知,不应该使用任何步骤。
I can craft some sort of global step wrapper that adds the time metrics and calls each step. 我可以设计某种全局步骤包装器,以添加时间指标并调用每个步骤。
Any ideas on the most elegant way to get time to complete for a step? 您有什么想法可以以最优雅的方式完成工作吗?
This is copy-paste from my features/support/env.rb . 这是从我的features / support / env.rb复制粘贴。 I quit using cucumber years ago and hence I can't provide a sophisticated answer, since I have almost everything forgotten, but I hope this snippet might led you towards right direction:
几年前我退出使用黄瓜,因此我无法提供一个复杂的答案,因为我几乎忘记了所有事情,但是我希望这段代码可以引导您朝正确的方向前进:
# encoding: utf-8
require 'bundler/setup'
require 'rspec/expectations'
MAX_SCENARIOS = 10
scenario_times = {}
Around() do |scenario, block|
start = Time.now
block.call
sc = if scenario.respond_to?(:scenario_outline)
scenario.scenario_outline
else
scenario
end
t = scenario_times["#{sc.feature.file}::#{scenario.name}"] = Time.now - start
# puts "### STEP COMPLETED #{t}s"
end
# print top 10 sorted by execution time
at_exit do
max_scenarios = if scenario_times.size > MAX_SCENARIOS
MAX_SCENARIOS
else
scenario_times.size
end
puts '—'*20 + " top #{max_scenarios} slowest " + '—'*20
sorted_times = scenario_times.sort { |a, b| b[1] <=> a[1] }
sorted_times[0..max_scenarios - 1].each do |key, value|
puts "#{value.round(5)} #{key}"
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.