与黄瓜轨道的数据库清洁交易
我正在为注册表单编写一个场景。
@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"
我希望在此方案之后使用数据库清理程序回滚测试数据库,以便我可以一次又一次地使用此方案。
对于我在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
现在,当我运行场景时,用户将被保存在数据库中,并且数据库清理器将失败。 我没有看到任何错误消息
- 您能否澄清一下如何仅在一种情况下使用数据库清理程序。我只想在这种情况下使用清理程序。
- 还请你提供截断和事务之间的重要区别。我认为截断清除整个数据库,但我不想这样。
- 是否有更好的方法进行注册测试?
您无法使用selenium运行事务,因为测试在应用程序AFAIK的两个单独实例上运行