黄瓜不尊重服务器设置的cookie
我正在努力将大量 Cucumber 功能从 Webrat 迁移到 Capybara,但遇到了很多问题。主要的(也是最痛苦的)问题是关于 cookie 的。
第一个问题是“如何设置 cookie”,因为有多种功能可以设置 cookie(有些用于登录,有些用于设置推荐代码等)。我们通过从 向我展示 cookies gem 中借用一些代码来解决这个问题。
下一个问题是,有时服务器会删除 cookie,但我们发现的问题是 Cucumber(或者 Capybara 对此负责吗?)不会将 cookie 重置为服务器在后续请求中返回的内容。
起初我以为我可以通过执行 AfterStep
来解决这个问题,清除 cookie 并将它们设置为服务器在标头“Set-Cookie”中返回的内容。
不幸的是,这在处理重定向时不起作用,因为 Cucumber/Capybara 在调用我的 AfterStep
之前遵循重定向,从而导致功能失败。
这非常困难,任何帮助将不胜感激。以下是一些相关环境信息:
gem 'rails', '2.3.10'
gem 'cucumber', '0.10.7'
gem 'cucumber-rails', '0.3.2'
gem 'capybara', '0.4.1.2'
I'm working on migrating a large set of cucumber features from Webrat to Capybara and I'm running into quite a few issues. The primary (and most painful) issue is around cookies.
First problem was "how to set cookies" as there are various features that set cookies (some for logging in, some for setting referral codes, etc). We solved this by borrowing some code from the show me the cookies gem.
The next problem is that sometimes the server deletes cookies, but the problem we've found is that Cucumber (or is Capybara responsible for this?) doesn't reset the cookies to what was returned by the server on subsequent requests.
At first I thought I could hack around this by doing an AfterStep
that cleared the cookies and set them to what was returned by the server in the headers 'Set-Cookie'.
Unfortunately this won't work when dealing with a redirect, because Cucumber/Capybara follows the redirect before calling my AfterStep
, thus causing failing features.
This has been quite difficult and any help would be greatly appreciated. Here is some relevant environment information:
gem 'rails', '2.3.10'
gem 'cucumber', '0.10.7'
gem 'cucumber-rails', '0.3.2'
gem 'capybara', '0.4.1.2'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论