I want to keep on using the same session and by that I mean Rails\' session between various Test::Unit
integration tests that use Capybara. The Capybara::Sess
You can prevent the call to @browser.manage.delete_all_cookies
that happens between tests by monkey patching the Capybara::Selenium::Driver#reset!
method. It's not a clean way of doing it, but it should work...
Add the following code to your project so that it is executed after you require 'capybara'
:
class Capybara::Selenium::Driver < Capybara::Driver::Base
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 <= cookie deletion is commented out!
rescue Selenium::WebDriver::Error::UnhandledError => e
# delete_all_cookies fails when we've previously gone
# to about:blank, so we rescue this error and do nothing
# instead.
end
@browser.navigate.to('about:blank')
end
end
end
For interest's sake, the offending line can be seen in Capybara's codebase here: https://github.com/jnicklas/capybara/blob/master/lib/capybara/selenium/driver.rb#L71