【问题标题】:rails, rspec, capybara, webkit/selenium, devise, logged out after every requestrails,rspec,capybara,webkit/selenium,devise,每次请求后注销
【发布时间】:2015-09-27 13:56:19
【问题描述】:

我在我的 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

我该如何解决这个问题?

【问题讨论】:

  • 您是否尝试过跟踪 log/test.log 文件以查看测试期间有哪些请求进入?如果有,可以分享一下吗?
  • 我也可以回答。此指定测试的 log/test.log。 pastie.org/10447426 - 看起来很正常
  • Capybara 调试输出没有显示任何有用的信息或向我们提供任何信息,为什么他应该放弃会话

标签: ruby-on-rails selenium rspec devise webkit


【解决方案1】:

我遇到了完全相同的问题,最终遇到了几乎相同的问题:Why is Capybara discarding my session after one event?

解决方案是将找到的 sn-p here 包含在您的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多