使用 Cucumber Rails 进行数据库清理事务
我正在为注册表单编写一个场景。
@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|[email protected]|
|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
现在,当我运行场景时,用户将保存在数据库中,并且数据库清理器会失败。我没有看到任何错误消息
- 您能否澄清如何仅在一种情况下使用数据库清理器。我只想在这种情况下使用清理器。
- 此外,您还可以提供一下吗?使用截断和事务之间的重要区别。我认为截断会清除整个数据库,但我不希望这样。
- 还有比这更好的注册测试方法吗?
I am writing a scenario for signup form.
@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|[email protected]|
|password|123456|
And I press "submit"
Then I should see "Registration complete"
I want to use database cleaner to roll back the test database after this scenario so that I can use this scenario again and again.
For that inside my env.rb file I wrote:
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
Now when I run the scenario , the user gets saved in the database and the database cleaner fails. I dont see any error messages
- Could you please clarify how to use database cleaner for only one scenario.I only want to use cleaner for this scenario.
- Also could you please also provide the vital difference between using truncation and transaction.I think truncation clears the whole database but I dont want that.
- Is there a better method of doing signup testing than this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用 selenium 运行事务,因为测试在应用程序的两个单独的实例上运行 AFAIK
You can't run transactions with selenium because the test runs on two separate instances of the app AFAIK