MiniTest,水豚,夹具,Database_Cleaner在第二次未通过 [英] MiniTest, Capybara, Fixture, Database_Cleaner not passing at second time

查看:109
本文介绍了MiniTest,水豚,夹具,Database_Cleaner在第二次未通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下测试第一次通过(在 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

我的理论是


  1. database_cleaner 无法正常工作。 (尽管我在 test.log 文件中看到了DB清理sql命令,但我看到数据仍保留在数据库中)

  1. database_cleaner not functioning as expected. (Although I see DB cleaning sql commands on test.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
  • Database Cleaner not working in minitest rails
  • Rails minitest, database cleaner how to turn use_transactional_fixtures = false

推荐答案

我已确认问题是我的 database_cleaner

:交易策略不适用于我的设置黄瓜 + 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.


  1. 有人问为什么数据库清洁器交易策略不适用于Cucumber和Selenium?-没有答案

如何使用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




  • 其他值得阅读的东西



    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆