Created
August 13, 2014 19:09
-
-
Save mars/e9b538fb5699096cd325 to your computer and use it in GitHub Desktop.
Capybara patch to avoid `@browser.navigate.to('about:blank')` which hangs sometimes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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