我有一个大型测试套件,使用了poltergeist和capybara。我一直收到以下错误:
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).
我很确定我已经设置了js_errors:false但我仍然遇到错误。我意识到最佳解决方案是修复JS但我继承遗留代码并修复错误超出了我的角色范围。我的规范帮助文件如下所示:
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
我很困惑到哪里去或者我是否适当地忽略了JS错误。如果有其他任何我可能忽略或忽略的信息,请告诉我。谢谢你的时间。
答案 0 :(得分:27)
我不确定为什么你的代码不起作用。我刚刚有一个类似的JS错误,并做了以下(如this page上所述(搜索js_errors)) - 基本上莱昂纳多加拉尼提出的建议(我赞成莱昂纳多的答案,从-1到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
我也测试了这种风格,它也很有效:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: false})
end
FWIW:我的错误(在Cucumber测试中)看起来像这样:
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
答案 1 :(得分:3)
@Leonardo Galani
根据ruby样式指南,您的语法注释不正确。所以答案也可能是{js_errors:false}。
答案 2 :(得分:3)
我遇到了同样的问题,js_errors: false
不能解决问题,但是phantomjs_logger: "/dev/null"
是!
答案 3 :(得分:-3)
如果您只使用register_driver的一个选项,则不需要哈希值。
你还不是js_errors:false
而是:js_errors => false
或者您可以在外部设置散列,以便在将来需要时添加更多选项。
options = {:js_errors => false}
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, options)
end