与黄瓜轨道的数据库清洁交易

Ani*_*uja 2 selenium ruby-on-rails cucumber capybara

我正在为注册表单编写一个场景.

     @abc

     @selenium

     Scenario:Non registered user signs up
        Given I am on the sign-up page
        When I fill in the following:
          |first_name|Anidhya|
          |last_name|Ahuja|
          |email|anidhya@gmail.com|
          |password|123456|
        And I press "submit"
        Then I should see "Registration complete"
Run Code Online (Sandbox Code Playgroud)

我希望在此方案之后使用数据库清理程序回滚测试数据库,以便我可以一次又一次地使用此方案.

对于我在env.rb文件中的内容,我写道:

begin
  require 'database_cleaner'
  require 'database_cleaner/cucumber'
  DatabaseCleaner.strategy = :transaction

  Cucumber::Rails::World.use_transactional_fixtures = true

rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end 


Before('@abc') do
  DatabaseCleaner.start
end
After('@abc') do
  DatabaseCleaner.clean
end
Run Code Online (Sandbox Code Playgroud)

现在,当我运行场景时,用户将被保存在数据库中,并且数据库清理器将失败.我没有看到任何错误消息

  • 您能否澄清一下如何仅在一种情况下使用数据库清理程序.我只想在这种情况下使用清理程序.
  • 还请你提供截断和事务之间的重要区别.我认为截断清除了整个数据库,但我不想这样做.
  • 是否有更好的方法进行注册测试?

ore*_*ake 5

您无法使用selenium运行事务,因为测试在应用程序AFAIK的两个单独实例上运行

  • [这个答案](http://stackoverflow.com/a/5525526/418819) 有一个使用 Selenium 测试的事务装置的技巧。 (2认同)