Skip to content

Instantly share code, notes, and snippets.

@msp
Created February 8, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msp/cbf3537dc856fd7a3f80 to your computer and use it in GitHub Desktop.
Save msp/cbf3537dc856fd7a3f80 to your computer and use it in GitHub Desktop.
This is hacked from the link on line 1 and not really tested but, breadcrumbs! Stick in env.rb (Cukes) or spec_helper.rb
# https://github.com/ariya/phantomjs/issues/12234
CAPYBARA_TIMEOUT_RETRIES = 3
Around do |scenario, block|
CAPYBARA_TIMEOUT_RETRIES.times do |i|
begin
block.call
break
rescue => Capybara::Poltergeist::StatusFailError
puts("\nCapybara::Poltergeist::StatusFailError\n Restarting phantomjs and retrying...")
restart_phantomjs
end
end
end
# https://gist.github.com/afn/c04ccfe71d648763b306
def restart_phantomjs
puts "-> Restarting phantomjs: iterating through capybara sessions..."
session_pool = Capybara.send('session_pool')
puts "session_pool length:#{session_pool.length}"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment