Read more

Single step and slow motion for cucumber scenarios using @javascript selenium

Christoph Beck
October 07, 2011Software engineer

Single step and slow motion for Cucumber scenarios can come in handy, especially in @javascript scenarios.

# features/support/examiners.rb
AfterStep('@slow_motion') do
  sleep 2
end

AfterStep('@single_step') do
  print "Single Stepping. Hit enter to continue"
  STDIN.getc
end
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

If you're using spreewald Show archive.org snapshot , these tags are available as @slow-motion and @single-step (with dashes instead of underscores).

Note: You can also prevent the selenium webbrowser window from closing after a failed @javascript step.

Fixing out-of-sync Cucumber output

The problem with the @slow_motion step above is that the console output of Cucumber will always be one step behind the Selenium window. This is because the sleep is blocking the completion of the step.

To fix this, you can use this (much more verbose and performance-eating!) code:

Before('@slow_motion') do
  @slow_motion = true
end

After('@slow_motion') do
  @slow_motion = false
end

Transform /.*/ do |match|
  if @slow_motion
    sleep 1.5
  end
  match
end
Posted by Christoph Beck to makandra dev (2011-10-07 09:31)