【问题标题】:Model not being saved using Selenium but saved using Rack::Test模型没有使用 Selenium 保存,而是使用 Rack::Test 保存
【发布时间】:2012-08-07 22:50:52
【问题描述】:

我有以下测试在 Rack::Test 中有效,但不使用 Selenium。 IE。如果我将, js: true 添加到describe 块中,我会在Firefox 中收到一条错误消息,指出它couldn't find the License with id=(@l 的id)

describe "should hide allocation rule # for pdf & clickthrough licenses" do

  it "reads current state and shows/hides fields appropriately" do                                     
    @l = FactoryGirl.create(:license:,
                          way: License::CLICK_WAY)                                                                                      
    visit edit_admin_license_path(@l)                                                                                           
  end
end

为什么?我一定错过了一些东西。我可以使用 Sequel Pro 验证在使用 js: true 时记录没有被保存。

我需要这个规范在 Selenium 中运行,因为我要测试 javascript。

【问题讨论】:

  • 尝试检查log/test.log 并确认正在执行正确的操作。您还可以在visit 之后添加save_and_open_page 以在浏览器中显示页面。
  • 可能与您的数据库策略有关,您能否包括spec_helper.rb

标签: ruby selenium rspec capybara activeadmin


【解决方案1】:

简单的解决方案是关闭事务性固定装置。

Why does my Cucumber test fail when run with Selenium?

在规范/spec_helper.rb 中:

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

  config.before :each do
    if Capybara.current_driver == :rack_test
      DatabaseCleaner.strategy = :transaction
    else
      DatabaseCleaner.strategy = :truncation
    end
    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end
end

在 Gemfile 中,测试部分

gem 'database_cleaner'

【讨论】:

猜你喜欢
  • 2011-01-14
  • 1970-01-01
  • 2021-03-17
  • 2014-07-12
  • 1970-01-01
  • 2019-12-30
  • 1970-01-01
  • 1970-01-01
  • 2020-05-11
相关资源
最近更新 更多