
Spanner in the works
If you are just using plain old Webrat you can pepper your code with puts statements so you can check the value of variables, the existence of HTML elements and the flow of code as it happens. But with Selenium or Watir, you need to run your app separately to Cucumber, normally in a hidden, background, process, so the output of your puts statements is lost in the ether (or an empty pipe).
After having a particularly annoying and hard to trace bug, that was related to an interaction between form content and javascript, I came up with an extremely simple debugging tool.
Just add the following into one of your steps files:
When /^I pause$/ do
STDIN.gets
end
Then, find the feature that is causing you grief and insert a “when I pause” step at the appropriate time.
When I do this
And I do that
And I pause
And I press "Save"
Then I see my newly created object
Cucumber will power your app, poking it until it gets to the “when I pause” step. It will then pause, waiting on STDIN for you to hit return – giving you time to open your inspector window and poke around in the form as the tests see it.
In this particular case, my steps file had an incorrectly named element within it – all it took was an inspection of the element in question and I saw the error. Hours of frustration wiped out by one of the simplest commands there is.
Spanners by woodsy
Nice write up.
In case you haven’t seen it, Webrat has a save_and_open_page for debugging scenarios, which is especially helpful when not using Selenium.
Cheers,
-Bryan