Skip to content

Instantly share code, notes, and snippets.

@mars
Created August 13, 2014 19:09
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 mars/e9b538fb5699096cd325 to your computer and use it in GitHub Desktop.
Save mars/e9b538fb5699096cd325 to your computer and use it in GitHub Desktop.
Capybara patch to avoid `@browser.navigate.to('about:blank')` which hangs sometimes.
# Monkey-patch on Capybara!!!
#
class Capybara::Selenium::Driver < Capybara::Driver::Base
# Patch to avoid `@browser.navigate.to('about:blank')` which hangs sometimes.
#
def reset!
# Use instance variable directly so we avoid starting the browser just to reset the session
if @browser
begin @browser.manage.delete_all_cookies
rescue Selenium::WebDriver::Error::UnhandledError
# delete_all_cookies fails when we've previously gone
# to about:blank, so we rescue this error and do nothing
# instead.
end
# about:blank is broken for this purpose. Use app's /ping
@browser.navigate.to("#{Capybara.app_host}/ping")
end
end
end
@mars
Copy link
Author

mars commented Aug 13, 2014

Note the "#{Capybara.app_host}/ping" URL should be revised to use a page in your subject app.

This was applied successfully with Capybara 2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment