jnicklas/capybara — Issue #545: Switching between drivers in cucumber scenarios
Author: rb2k
Created: 2011-11-18 12:29:40+00:00
State: open

I have a very strange problem with capybara at the moment. My situation is the following:
1. I run my tests using cucumber
2. My default driver is akephalos
3. For some of the tests, I added a @selenium tag
4. I use this before hook to start a XVFB using the headless gem:

Before do
if [:selenium, :webkit, :poltergeist].include?(Capybara.current_driver)
puts "Launching XVFB instance because the current driver is #{Capybara.current_driver.inspect}"
require 'headless'
headless = Headless.new
headless.start
puts headless.inspect
end
end

This seems to work fine initially.
When my first @selenium scenario comes up, I get this output:

Launching XVFB instance because the current driver is :selenium
#

After the scenario, firefox will still stay launched (as seen in ps aux), but akephalos will be the default driver again.
A few scenarios later, often when calling "Capybara.reset!", I will receive an exception.
I caught this exception and added some additional output:

puts "Error while trying to reset the session: #{e.message}"
puts "The current driver is: #{Capybara.current_driver}"
puts "The default driver is: #{Capybara.default_driver}"

The result:

Error while trying to reset the session: Connection refused - connect(2)
The current driver is: akephalos
The default driver is: akephalos

The full stacktrace looks like this:

/usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
/usr/lib/ruby/1.8/net/http.rb:560:in `open'
/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:101:in `timeout'
/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
/usr/lib/ruby/1.8/net/http.rb:542:in `start'
/usr/lib/ruby/1.8/net/http.rb:1035:in `request'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/default.rb:81:in `response_for'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/default.rb:43:in `request'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/common.rb:39:in `call'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/bridge.rb:450:in `raw_execute'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/bridge.rb:428:in `execute'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/bridge.rb:260:in `deleteAllCookies'
[...]/workspace/vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/common/options.rb:67:in `delete_all_cookies'
[...]/workspace/vendor/bundle/ruby/1.8/gems/capybara-1.1.2/lib/capybara/selenium/driver.rb:81:in `reset!'
[...]/workspace/vendor/bundle/ruby/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:70:in `reset!'
[...]/workspace/vendor/bundle/ruby/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:87:in `reset_sessions!'
[...]/workspace/vendor/bundle/ruby/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:87:in `each'
[...]/workspace/vendor/bundle/ruby/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:87:in `reset_sessions!'
[...]/workspace/vendor/bundle/ruby/1.8/gems/capybara-1.1.2/lib/capybara/cucumber.rb:10:in `After'

This DOESN'T happen during a @selenium scenario. This is in an akephalos one!
Any idea why the after hook in cucumber might try to call the non-current driver?