Ruby on rails 3.2 Rails-调试selenium webdriver 404错误
我正在使用Rspec、Capybara和Selenium(WebDriver)来测试我的Rails应用程序,这是一个简单的在线商店。以下是失败的规范的简化版本:Ruby on rails 3.2 Rails-调试selenium webdriver 404错误,ruby-on-rails-3.2,selenium-webdriver,Ruby On Rails 3.2,Selenium Webdriver,我正在使用Rspec、Capybara和Selenium(WebDriver)来测试我的Rails应用程序,这是一个简单的在线商店。以下是失败的规范的简化版本: describe 'Team Order' do let(:product) { Product.last } before do create :product_with_color_and_size end it 'goes to product page', js: true do visit
describe 'Team Order' do
let(:product) { Product.last }
before do
create :product_with_color_and_size
end
it 'goes to product page', js: true do
visit add_team_order_path(product)
expect(page).to have_content(product.name)
end
end
具体来说,Selenium驱动的Firefox窗口显示我的应用程序的404页面,导致产品名称检查失败
当我从it
块中调用debugger
并查询产品时。最后一次
我可以在测试数据库中看到有问题的产品。所以我怀疑Selenium打错了我应用程序的实例…或者别的什么
不确定这是否相关,但浏览器指向http://127.0.0.1:49736/products/product-10/添加团队订单
(尽管端口在rspec运行之间发生变化)
我的问题是,我能做什么来验证它是否命中了正确的实例?如果不是,我可以采取什么步骤来修复它
编辑:
spec_helper.rb中的数据库\u清理器配置:
RSpec.configure do |config|
config.before :suite do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
问题是数据库清理器与我的
js:true
规范冲突。一个很好的总结:
问题总是一样的:测试被包装在数据库事务中,因此在实际测试过程之外运行的任何代码(比如说,为Selenium驱动的浏览器请求提供服务的服务器过程)都看不到我精心组装的数据库装置
更多信息以及我的解决方案,请参见: