带有水豚的硒无法使用设备登录/注册

jus*_*sti 5 selenium rspec ruby-on-rails devise

我正在尝试使用 rspec 通过登录或注册测试。所有配置工作正常,所有先前的集成测试都已通过。

规格代码如下:

visit "/"
save_and_open_page
expect(page).to have_no_selector '#register-dialog'

find(:css, 'a.button.signup').click
expect(page).to have_selector '#register-dialog'
fill_in 'customer_name', with: "abcde"
fill_in 'customer_email', with: "name@email.com"
fill_in 'customer_password', with: "abcdef"
find(:css, "input#customer_terms").set(true)
find(:css, 'input[type=\'submit\']').click

expect(page).to have_no_selector '#register-dialog'
expect(page).to have_selector '#after-register' # fails
# expected to find css "#after-register" but there were no matches
Run Code Online (Sandbox Code Playgroud)

我检查最后一步是否在测试数据库中创建了一个客户用户,但无法自动登录

问题是为什么?开发环境一切正常。

我使用数据库清理器,配置如下:

RSpec.configure do |config|
  config.use_transactional_examples = false
  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.clean_with :truncation
    DatabaseCleaner.strategy = :transaction
  end

  config.around(:each) do |spec|
    if spec.metadata[:js] || spec.metadata[:test_commit]
      spec.run
      DatabaseCleaner.clean_with :deletion
    else
      DatabaseCleaner.start
      spec.run
      DatabaseCleaner.clean
      begin
        ActiveRecord::Base.connection.send(:rollback_transaction_records, true)
      rescue
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我尝试使用设计助手登录/注册,但没有成功。

jus*_*sti 4

好吧,我找到了问题的核心:

MyApp::Application.config.session_store :cookie_store, key: '_myapp_session', expire_after: 7.days, domain: {
  ...
  test: AppConfig.host_name
}.fetch(Rails.env.to_sym, :all)
Run Code Online (Sandbox Code Playgroud)

for host_nametest env 与 selenium 服务器主机不同,因此session_cookie未设置。