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.
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 . 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.