# Borrowed from https://github.com/y310/rspec-retry/blob/master/lib/rspec/retry.rb | |
CAPYBARA_TIMEOUT_RETRIES = 3 | |
RSpec.configure do |config| | |
config.around(:each, type: :feature) do |ex| | |
example = RSpec.current_example | |
CAPYBARA_TIMEOUT_RETRIES.times do |i| | |
example.instance_variable_set('@exception', nil) | |
self.instance_variable_set('@__memoized', nil) # clear let variables | |
ex.run | |
break unless example.exception.is_a?(Capybara::Poltergeist::TimeoutError) | |
puts("\nCapybara::Poltergeist::TimeoutError at #{example.location}\n Restarting phantomjs and retrying...") | |
restart_phantomjs | |
end | |
end | |
end | |
def restart_phantomjs | |
puts "-> Restarting phantomjs: iterating through capybara sessions..." | |
session_pool = Capybara.send('session_pool') | |
session_pool.each do |mode,session| | |
msg = " => #{mode} -- " | |
driver = session.driver | |
if driver.is_a?(Capybara::Poltergeist::Driver) | |
msg += "restarting" | |
driver.restart | |
else | |
msg += "not poltergeist: #{driver.class}" | |
end | |
puts msg | |
end | |
end |
This comment has been minimized.
This comment has been minimized.
Very handy! Thanks for sharing, and thanks for taking such a deep and public dive into trying to fix this issue. |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks! I was able to re-use the restart_phantomjs method to fix the same issue when running jasmine specs over HTTP. |
This comment has been minimized.
This comment has been minimized.
This is amazing. It's like a hidden gem of source code. |
This comment has been minimized.
This comment has been minimized.
It is not working for me with RSpec 3.3.0, I got the following error when running
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks guys! |
This comment has been minimized.
This comment has been minimized.
I pasted the above code in support directoryThe above code didnt work. Still I can see I have set the |
This comment has been minimized.
Very nice, thanks for sharing.