繁体   English   中英

rails,rspec,capybara,webkit / selenium,devise,在每次请求后退出

[英]rails, rspec, capybara, webkit/selenium, devise, logged out after every request

我在我的rails项目中使用rspec / capybara进行测试,这对于默认驱动程序工作正常。 但是当我切换到webkit或selenium时,我会在每次发出请求后退出。 此代码按预期工作,我看到登录页面2次:

require 'rails_helper'

feature 'test' do
  scenario 'this' do
    user = FactoryGirl.create :user
    login_as(user)
    visit root_path
    save_and_open_page
    visit root_path
    save_and_open_page
  end
end

当我将webkit或selenium设置为驱动程序时,第一页是登录版本,在第二页上我已注销:

require 'rails_helper'

feature 'test' do
  scenario 'this', driver: :webkit do
    user = FactoryGirl.create :user
    login_as(user)
    visit root_path
    save_and_open_page
    visit root_path
    save_and_open_page
  end
end

我怎样才能解决这个问题?

我遇到了同样的问题,最终遇到了同样的问题: 为什么Capybara在一次事件后放弃我的会话?

解决方案是在rails_helper中包含此处的代码段

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || retrieve_connection
  end
end

# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM