Eugenio Laghi
Eugenio Laghi

Reputation: 701

How can I log javascript errors with Poltergeist/Capybara/Rspec?

I'm using Rspec/Capybara with Poltergeist as a driver to write tests for some large web applications.

My issue is that I would like to record the messages that appear on the console, but so far I've been unable to do so.

I am aware of the options js_errors and phantomjs_logger, but I have had some issues with them:

Any idea on how I can save the console messages while not breaking specs on every js error?

CLARIFICATION: I have no control over the development, my task is to check the stability of the whole stack of the applications in the various environments, accessing from the front-end, so clearing out all the javascript errors is out of the question. The specs I'm writing are also supposed to ignore javascript errors if they don't impair the usage of the interface.

Upvotes: 2

Views: 2171

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49870

You can't. The PhantomJS client catches javascript error messages and adds them to an array. Then when a command completes, if js_errors == true, that array is checked and if not empty the javascript errors are returned and trigger an error in the test. There is no other API in poltergeist for accessing those errors. It sounds like you need to have a discussion with your manager about the wisdom of just ignoring JS errors if they apparently don't impair usage - it's a potentially dangerous development practice

Upvotes: 5

Related Questions