Temporarily set js_errors to false in Poltergeist

寵の児 提交于 2019-12-04 01:52:15

Thanks to Roman Pominov's comment I was able to find a solution. It was actually quite simple:

I just added rescue Capybara::Poltergeist::JavascriptError after the statement in question, and then it worked like a charm. My initial idea was too complicated ;)

This makes the trick:

page.driver.browser.js_errors = false

You may also add around callback:

# spec_helpers.rb
config.around(:each) do |example|
  original_value = page.driver.browser.instance_variable_get(:@js_errors)
  if example.metadata.has_key?(:js_errors)
    page.driver.browser.js_errors = example.metadata[:js_errors]
  end

  example.run

  page.driver.browser.js_errors = original_value
end

In your tests:

# my_feature_spec.rb
it "should ignore errors", js_errors: false do
  ...
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!