Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 含水豚的硒罐头';t使用designe登录/注册_Ruby On Rails_Selenium_Rspec_Devise - Fatal编程技术网

Ruby on rails 含水豚的硒罐头';t使用designe登录/注册

Ruby on rails 含水豚的硒罐头';t使用designe登录/注册,ruby-on-rails,selenium,rspec,devise,Ruby On Rails,Selenium,Rspec,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:

我正在尝试使用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
我检查最后的步骤是否在测试数据库中创建了客户用户,,但无法自动登录

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

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

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

我尝试登录Desive helpers,但没有成功。

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

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)

test env的
主机名
与selenium server主机不同,因此未设置
会话cookie

您如何知道测试未登录?我没有看到任何断言。为您的问题添加更多信息。我在问题之后使用sleep()函数并手动检查网页状态。检查消息状态(“成功登录”等)的所有断言都失败。您是否可以发布测试、测试输出,然后尝试保存和打开页面以查看根目录的结果(检查输入字段及其ID等),以及单击提交后的结果?@HannesFostie-此时更新为保存和打开页面,我知道会话cookie设置不正确。