Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 Rails/RSpec/Capybara-无事务数据库清理可以与Selenium一起使用,但不能与Webkit一起使用_Ruby On Rails_Selenium_Rspec_Webkit_Database Cleaner - Fatal编程技术网

Ruby on rails Rails/RSpec/Capybara-无事务数据库清理可以与Selenium一起使用,但不能与Webkit一起使用

Ruby on rails Rails/RSpec/Capybara-无事务数据库清理可以与Selenium一起使用,但不能与Webkit一起使用,ruby-on-rails,selenium,rspec,webkit,database-cleaner,Ruby On Rails,Selenium,Rspec,Webkit,Database Cleaner,因此,我已经设置了我的RSpec环境,以便在RSpec-Capybara测试中使用截断清理策略,但当我使用Webkit作为Javascript驱动程序时,我仍然发现仍有一些东西在事务中包装我的测试 我没有硒的问题,这让我很困惑 以下是webkit的相关RSpec配置: Capybara.javascript_driver = :webkit Capybara.register_driver :webkit do |app| Capybara::Webkit::Driver.new(app)

因此,我已经设置了我的RSpec环境,以便在RSpec-Capybara测试中使用截断清理策略,但当我使用Webkit作为Javascript驱动程序时,我仍然发现仍有一些东西在事务中包装我的测试

我没有硒的问题,这让我很困惑

以下是webkit的相关RSpec配置:

Capybara.javascript_driver = :webkit

Capybara.register_driver :webkit do |app|
  Capybara::Webkit::Driver.new(app).tap do |driver|
    driver.allow_url "fonts.googleapis.com"
    driver.allow_url "dl.dropboxusercontent.com"
  end
end

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

config.after(:each) do
  ActionMailer::Base.deliveries.clear
end

config.around(:each, type: :feature, js: true) do |ex|
  DatabaseCleaner.strategy = :truncation
  DatabaseCleaner.start
  self.use_transactional_fixtures = false
  ex.run
  self.use_transactional_fixtures = true
  DatabaseCleaner.clean
end
我的功能测试如下所示:

feature "profile", js: true do
  describe "a confirmed user with a valid profile" do
    before(:each) do
      @user = FactoryGirl.create :user
      signin(@user.email, @user.password)
    end

    scenario 'can edit name' do
      visit edit_user_profile_path

      fill_in :user_name, with: 'New name'
      click_button :Submit
      @user.reload

      expect(@user.name).to eq('New name')
      expect(current_path).to eq show_user_path
    end
  end
end
如果我用Webkit运行这个测试,它会失败,但用Selenium它会通过

我试过一些调试。如果我在#update操作中放入调试器语句,我会看到它正确地更新了数据库。如果我当时连接到测试数据库,我可以在数据库中看到新信息,这意味着此更新不能包装在事务中。但是,在.spec@user的调试器中仍然可以看到由FFaker在factory\u中生成的原始名称。这让我相信测试是在事务内部运行的

当我将JavaScript驱动程序更改为Selenium时,一切正常


有什么想法吗?

哇。发布问题后,我几乎立即发现了问题。没有涉及任何交易

这是后端和webkit/selenium前端之间的竞争问题。使用Webkit,测试在控制器有机会更新数据库之前执行@user.reload和expect语句。硒的情况正好相反

诀窍是让水豚等待页面重新加载。我将测试更改为:

scenario 'can edit name' do
  visit edit_user_profile_path

  fill_in :user_name, with: 'New name'
  click_button :Submit

  expect(current_path).to eq show_user_path
  @user.reload
  expect(@user.name).to eq('New name')
end

哇!发布问题后,我几乎立即发现了问题。