I am using Cucumber, Capybara and Capybara-webkit for testing different scenarios in my Ruby on Rails app.
Is there a way I can detect any JavaScript error on the page while the scenarios are running and fail the test? We are using these tests to make sure we don't break the functionality (including JavaScript) between changes as part of our automated test runs.
I can see the failures in the test output, but it doesn't fail the test:
http://127.0.0.1:54928/...|16|ReferenceError: Can't find variable: $
http://127.0.0.1:54928/...|16|ReferenceError: Can't find variable: $
...
Thanks!
Update: one way I have found is to have a step that tries to execute some JavaScript that would only be possible if previous errors had not happened. In that case, I would get an error like this:
Javascript failed to execute (Capybara::Driver::Webkit::WebkitInvalidResponseError)
./features/step_definitions/....rb:19:in `/^I should not see any JavaScript errors$/'
features/....feature:34:in `Then I should not see any JavaScript errors'
Is there a better way?