2
votes

I'm running some tests with Cucumber/Capybara. I've got one scenario where the user goes to the homepage, fills his/her username and password and clicks "Enter". This should log in the user. When using the default Capybara driver, rack_test, this works: the user gets logged in and moved to other page. When using the Selenium driver, this does not work at all. The user submits his/her username and password, but doesn't get logged in.

I'm talking about the very same test. The only thing that changes is the Capybara Driver. I also think it's important to know that I'm using Authlogic for my authentication logic.

Can you help me with this? Thanks!

This is my Capybara configuration file (support/env.rb):

require 'cucumber/rails'
require 'capybara/session'
require 'capybara/dsl'

Capybara.default_selector = :css
Capybara.run_server = false
ActionController::Base.allow_rescue = false
Capybara.javascript_driver = :selenium
Capybara.server_port = 3000

Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
  Cucumber::Rails::World.use_transactional_fixtures = false
  Capybara.reset_sessions! 
  DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
  DatabaseCleaner.start
  activate_authlogic
  Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
end

After('@no-txn,@selenium,@culerity,@celerity,@javascript') do
  DatabaseCleaner.clean
end

Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
  DatabaseCleaner.strategy = :transaction
end
1

1 Answers

0
votes

I had a very similar issue, but this explanation pointed me in the right direction. Also my features/support/env.rb looks like this:

require 'cucumber/rails'

Capybara.run_server = false
Capybara.default_selector = :css
Capybara.server_port = 3000
Capybara.default_driver = :selenium

Cucumber::Rails::Database.javascript_strategy = :truncation

ActionController::Base.allow_rescue = false

DatabaseCleaner.strategy = :truncation

Before('@wip') do
ActiveRecord::Base.shared_connection = nil
end

Notice that the Before block is only for the @wip tag. Change this to the tags you will be testing with this config. Hope this helps