我希望有一个黄瓜功能来测试devise的记忆功能(一个记住我的cookie)。
使用水豚选中“记住我”复选框很容易,但我应该如何模拟用户在关闭窗口后返回站点?
发布于 2010-08-27 20:50:59
我想出了以下机架测试技巧,并使用稍微更干净的selenium api来测试cucumber/capybara中的设计记住我的功能。它只是告诉驱动程序手动擦除会话cookie。并不是所有的驱动都被支持,我只实现了我用过的两个驱动:
http://gist.github.com/484787
这假设会话的cookie存储。从场景中删除@announce标记,以消除冗长。
马特·韦恩在the mailing list discussion中提出的另一种选择可能是寻找其他cookie存储,并通过查询或文件删除来删除它们:
摘自agile rails书籍:
config.action_controller.session_store = CGI::Session::PStore (or just :p_store)
config.action_controller.session_options[:tmpdir] = "/Users/dave/tmp"
config.action_controller.session_options[:prefix] = "myapp_session_"或
rake db:sessions:create
config.action_controller.session_store = :active_record_storeRails也有一个重置会话的方法,但我相信我们不能访问它,因为在使用水豚进行测试时,我们不能连接到rails会话。
希望这能帮上忙
尼克
发布于 2010-12-17 11:57:35
nruth的要点真的很有帮助,但我觉得按名称删除cookie是作弊。我创建了一个步骤,删除浏览器关闭和重启时将删除的cookie (任何未设置和设置过期日期的cookie)。
您可以在this commit中看到它(尽管我只为RackTest驱动程序这样做过,因为我没有Selenium设置)。您还可以在this commit中看到我的登录/remember_me功能。并且我在this commit中重构了这些类以分离文件。
我希望这对你有帮助。
发布于 2010-08-12 22:42:47
我使用email-spec来完成这项工作。我的场景如下所示:
@allow-rescue
Scenario: Create New Account (Everything cool)
Given I am not authenticated
When I go to register
And I fill in "Name" with "bill"
And I fill in "Email" with "bill@example.com"
And I fill in "Password" with "please"
And I fill in "Password Confirmation" with "please"
And I press "Sign up"
Then "bill@example.com" should receive an email
And I open the email
And I should see "Confirm my account" in the email body
When I follow "Confirm my account" in the email
Then I should see "Your account was successfully confirmed. You are now signed in."注意场景上面的@allow-rescue装饰,这在使用Devise时是必要的。
希望这能有所帮助。
https://stackoverflow.com/questions/3467963
复制相似问题