Is there a standard way of printing the duration of every step in the terminal, during a watir-cucumber execution?
It might be possible to make some kind of invention, using the "after step" and a global variable. But, there is a proper way?
You can use hooks like this:
Before do
@last_time = Time.new
end
AfterStep do
now = Time.new
puts "Step duration: #{((now - @last_time)*100).round} ms" # if (now-@last_time) > 10
@last_time = now
end
This is more verbose by outputting the duration on a new line, but unless you want to get more in-depth (by creating your own formatter), you cannot output stuff where you indicated it.
Uncomment the if
if you are only interested in steps that take longer than a certain threshold.
The simplest way to do this would be using Ruby's built in Time class. Using Time.new we can record the current time into a local variable before and after the code within the step definition is executed. Then we work out the duration by subtracting start_time from end_time.