Poltergeist throws JS errors when js_errors: false
Asked Answered
W

3

19

I have a large test suite that is using poltergeist and capybara. I keep getting the following error:

One or more errors were raised in the Javascript code on the page. If you don't care about
these errors, you can ignore them by setting js_errors: false in your Poltergeist
configuration (see documentation for details).

I am pretty sure I have set js_errors: false but I am still getting the errors. I realize that the optimal solution is to fix the JS but I am inheriting legacy code and fixing the errors is out of scope for my role. My spec helper file looks like this:

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, {js_errors: false})
end

Capybara.current_driver = :poltergeist

Capybara.configure do |config|
  config.match = :one
  config.exact_options = true
  config.ignore_hidden_elements = true
  config.visible_text_only = true
end

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}



RSpec.configure do |config|
  config.infer_base_class_for_anonymous_controllers = false
  config.order = "random"
end

I am confused as to where to go or if I am ignoring the JS errors appropriately. Let me know if there is any other information I may have overlooked or neglected to include. Thanks for your time.

Willms answered 4/9, 2014 at 19:50 Comment(0)
S
29

I am not sure why your code doesn't work. I just had a similar JS error and did the following (as mentioned on this page (search for js_errors)) -- and basically what Leonardo Galani suggested (I upvoted Leonardo's answer to take it from -1 to 0):

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

options = {js_errors: false}
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, options)
end

I also tested this style, and it worked as well:

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, {js_errors: false})
end

FWIW: My error (in Cucumber test) looked like this:

Capybara::Poltergeist::JavascriptError: One or more errors were raised in the 
Javascript code on the page. If you don't care about these errors, you can ignore 
them by setting js_errors: false in your Poltergeist configuration (see 
documentation for details).

TypeError: Unable to delete property.
TypeError: Unable to delete property.
    at :84
    at http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/20/%7Bmain,geometry%7D.js:19 in Ke
    at http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/20/%7Bmain,geometry%7D.js:19 in Ke
    at http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/20/%7Bmain,geometry%7D.js:18
Silvanus answered 30/12, 2014 at 1:5 Comment(0)
A
3

@Leonardo Galani

According to the ruby style guide, your syntax comment isn't true. So the answer could be {js_errors: false} too.

https://github.com/bbatsov/ruby-style-guide#hash-literals

Archle answered 20/2, 2015 at 9:14 Comment(2)
add as a comment next time :)Tuberculous
@Tuberculous this isn't possible due lack of reputation, but thanks for noticing. (minimal 50, for commenting on other people's posts)Archle
F
3

I had the same issue, js_errors: false did not solve the problem, but phantomjs_logger: "/dev/null" yes!

Freewill answered 26/7, 2018 at 22:22 Comment(1)
This gave me undefined method 'write' for "dev/null":String (NoMethodError), but phantomjs_logger: File.open('/dev/null', 'a') did the trick. FWIW it was a Poltergeist issue: github.com/teampoltergeist/poltergeist/issues/436Iata

© 2022 - 2024 — McMap. All rights reserved.