黄瓜不尊重服务器设置的cookie

发布于 2024-12-01 08:24:45 字数 718 浏览 1 评论 0原文

我正在努力将大量 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文