MiniTest,水豚,夹具,Database_Cleaner在第二次未通过 [英] MiniTest, Capybara, Fixture, Database_Cleaner not passing at second time
问题描述
以下测试第一次通过(在 rake db:test:prepare
之后),但 failed 在随后的运行中给出了错误。
The following test passed first time (after rake db:test:prepare
) but failed gave error on subsequent run.
Capybara :: ElementNotFound:无法找到CSS #sale_payment_btn
Capybara::ElementNotFound: Unable to find css "#sale_payment_btn"
require "test_helper"
DatabaseCleaner.strategy = :transaction
class SaleFeatureTest < Capybara::Rails::TestCase
include Warden::Test::Helpers
Warden.test_mode!
self.use_transactional_fixtures = false
setup do
login_as users(:admin), scope: :user
Capybara.current_driver = :selenium #:webkit
DatabaseCleaner.start
end
teardown do
DatabaseCleaner.clean
Warden.test_reset!
end
test "Sale" do
visit(new_sale_path) # create new sale and redirect to it
assert page.has_css?('#sale_payment_btn') # gave error at second time
find(:css, '#sale_payment_btn').click # this create payment
end
当我将硒和铬一起使用时,我可以看到销售的ID。我注意到该ID对于后续测试是相同的。即 980190963
As I used selenium with chrome, I could see the ID of the sale. I noticed that the ID was the same for subsequent test. i.e. 980190963
我的理论是
-
database_cleaner
无法正常工作。 (尽管我在test.log
文件中看到了DB清理sql命令,但我看到数据仍保留在数据库中)
database_cleaner
not functioning as expected. (Although I see DB cleaning sql commands ontest.log
file, I saw data remained in database)
访问
不会创建新的 @sale
(如此处,尽管我使用的是minitest),因为 #sal_payment_btn
不呈现(销售在第一次运行时已经有个付款
)。
visit
does not create new @sale
(as stated here though I use minitest) because #sal_payment_btn
is not rendered (sale already has payment
on first run).
我现在把头发拉了半天。我已经尝试过
I'm pulling my hair around for half day now. I have tried
-
webkit
驱动程序 - 不同的清理策略
截断
,删除
webkit
driver- different cleaning strategy
truncation
,deletion
,但我仍然无法通过第二次测试。
and I still can't pass the test on second run. It is running okay on manual test.
我在哪里做错了什么?
P.S。我正在使用以下宝石
P.S. I'm using the following gems
minitest-rails-capybara
selenium-webdriver
chromedriver-helper
database_cleaner
minitest-around
pg
我已阅读以下
- http://blog.berylliumwork.com/2013/07/rails-4-devise-3-minitest-and-capybara.html
- 数据库清洁器无法在minitest导轨中工作
- 将minitest引导到数据库清洁程序,如何将use_transactional_fixtures = false 设为
- http://blog.berylliumwork.com/2013/07/rails-4-devise-3-minitest-and-capybara.html
- Database Cleaner not working in minitest rails
- Rails minitest, database cleaner how to turn use_transactional_fixtures = false
推荐答案
我已确认问题是我的 database_cleaner $ c设置$ c>。
:交易
策略不适用于我的设置黄瓜
+ webkit
/ 硒
。更改为:删除
策略。
:transaction
strategy was not working for my setup cucumber
+webkit
/selenium
. Changed to :deletion
strategy.
看来我学习不够。我在寻找答案的过程中发现了以下内容。
It seemed I didn't study enough. I found out the following during my search for answer.
如何使用Cucumber和RSpec为Rails设置database_cleaner 指出
:transaction
策略不适用于硒
database_cleaner
自述文件表示:transaction
策略会增加工作量
database_cleaner
readme stated that :transaction
strategy imposes bit more working
但是,如果您最终需要使用多个数据库连接在您的测试中(即您的测试在与应用程序不同的过程中运行),则使用此策略会变得更加困难
However, if you wind up needing to use multiple database connections in your tests (i.e. your tests run in a different process than your application) then using this strategy becomes a bit more difficult
其他值得阅读的东西
- 为什么您应该使用Database Cleaner的
删除
策略 - 最推荐的方式使用
rails
,rspec
,<$ c设置database_cleaner
$ c>水豚和硒
- http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and -selenium / - 第4轨,Devise 3,MiniTest和Capybara用于用户登录
- Why you should be using Database Cleaner's
deletion
strategy - most recommended way to set up
database_cleaner
withrails
,rspec
,capybara
andselenium
- http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/ - Rails 4, Devise 3, MiniTest and Capybara for user login
Other worthy reading
这篇关于MiniTest,水豚,夹具,Database_Cleaner在第二次未通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!