gpt4 book ai didi

capybara - 当 js_errors : false 时,Poltergeist 会抛出 JS 错误

转载 作者:行者123 更新时间:2023-12-02 18:29:51 25 4
gpt4 key购买 nike

我有一个使用 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 错误。如果我可能忽略或忽略了任何其他信息,请告诉我。谢谢你的时间。

最佳答案

我不确定为什么你的代码不起作用。我刚刚遇到了类似的 JS 错误,并执行了以下操作(如 this page (搜索 js_errors)中提到的)——基本上就是 Leonardo Galani 的建议(我赞成 Leonardo 的答案,将其从 -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

关于capybara - 当 js_errors : false 时,Poltergeist 会抛出 JS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com