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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)