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

1

7

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
Advise answered 17/4, 2015 at 19:40 Comment(2)
Why have you set js_errors to false?Extender
Ah, sorry I copy/pasted this from the source I found it on (another SO thread). I did change it to true in my code, and I'm still not seeing warnings about JS errors when I runAdvise
A
2

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.

Appearance answered 2/12, 2015 at 6:4 Comment(1)
This does not work in Poltergeist. expected #<Capybara::Session:0x007f8d4390e750> to respond to 'has_errors?' additionally the link is broken.Sha

© 2022 - 2024 — McMap. All rights reserved.