Step through your cucumber features interactively
NOTE: This is probably only useful for features that run in browser mode i.e. NOT headless. Using Rails 3 and Capybara, these would be features tagged as @javascript.
Do you find yourself using the save_and_open_page method to debug your cucumber features? Or how about raising exceptions to break the scenario execution? I guess it works, but not very elegant…
One easy way to pause the scenario execution after each step is to use the cucumber callbacks.
Start by creating a hooks.rb file in your features/support folder. You can name the file whatever you want, but it must have a .rb extension. Then add the following snippet to your new file:
AfterStep('@pause') do
print "Press Return to continue..."
STDIN.getc
end
What we’re doing here is using the AfterStep callback to execute our code after each cucumber steps has finished. The parameter is telling cucumber to only do this for features that have the @pause tag. We then wait for a carriage return from the console before moving to the next step.
Now all you have to do is tag a feature with @pause and you will have to press Return after each step to walk through the scenario. This makes debugging a snap when you’re using something like Firebug etc.
Try it out for yourself.
Latest tweets
- RT @tobypinder: Gotta love it when the sysadmin yells "NO NO NO NO STOP STOP STOP STOP" while audibly mashing the keyboard! 2 days ago
- Not thinking about work at all. 3 weeks ago
- RT @luke_ar: Repeat after me: red, green, refactor. RED, GREEN, REFACTOR. Not "red, refactor, red, red, undo, red, undo, panic, git chec ... 1 month ago
Tag Cloud
Recent Posts
Archive
- February 2012 (2)
- December 2011 (1)
- November 2011 (7)
- October 2011 (1)
- August 2011 (4)
- July 2011 (2)
- June 2011 (2)
- May 2011 (4)
- April 2011 (3)
- March 2011 (7)
- February 2011 (3)
- January 2011 (4)
- December 2010 (1)
- November 2010 (8)