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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)