Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check for Javascript errors using capybara and poltergeist?

I'm trying to figure out how exactly to implement this functionality of Poltergeist into my existing Capybara tests, and I'm not having any luck after reading the documentation here: https://github.com/teampoltergeist/poltergeist

I have included the below code, but when I run my tests I'm not seeing any warning about JS errors when I know there are JS errors in the console. Am I missing something? Do I have to pass in a specific command in the terminal in order to make sure this checks for JS errors? Thanks!

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

options = {js_errors: true}
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, options)
end
like image 782
Chris Vannithone Avatar asked Apr 17 '15 19:04

Chris Vannithone


People also ask

How do I check for JavaScript errors?

Right-click anywhere in the webpage and then select Inspect. Or, press F12 . DevTools opens next to the webpage. In the top right of DevTools, the Open Console to view errors button displays an error about the webpage.


1 Answers

I ran into your posting after I googled a similar question. In my case I had started with webkit as driver in capybara. I had read a blog post that suggested the following code , which used "have_errors" matcher to capture any js error.

it 'should not have JavaScript errors', js: true do     
 visit(root_path)       
 expect(page).to_not have_errors        
end

In the event you are referring to something similar, you do not need to use any specific method to check when you are using poltergeist. You can see my code that shows what I have switched.

https://github.com/alaghu/learn_jquery/compare/dev...1d6be6dfd500

Basically, every test will automatically check if the page has errors. I only had to introduce js: true in my tests. I have verified this by intentionally erroring js files to validate these tests.

Hope this was helpful.

like image 165
Anand Avatar answered Sep 29 '22 12:09

Anand