Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily set js_errors to false in Poltergeist

I have a set of tests which lead to a Facebook page where the user logs in. Unfortunately, this page has some JavaScript errors which I can't influence, so my tests would never finish.

Is there any way to temporarily disable the check for JS errors? I was thinking about something like: Capybara.javascript_driver.js_errors = false and then setting it to true later, but unfortunately this doesn't work. I have tried variations of this to no avail.

Any ideas on how my problem could be solved?

like image 326
TrashyMcTrash Avatar asked Feb 25 '14 16:02

TrashyMcTrash


2 Answers

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 ;)

like image 173
TrashyMcTrash Avatar answered Nov 05 '22 07:11

TrashyMcTrash


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
like image 38
Pavel Evstigneev Avatar answered Nov 05 '22 06:11

Pavel Evstigneev