问题描述
我正在尝试为依赖于某些会话存储数据的功能编写测试,我的场景如下所示:
I'm trying to write a test for a feature that relies on some session stored data and my scenario looks like this:
Scenario: Create offer
Given I am on the start offer page
When I select "Foo" from "bar"
And I press "Go on"
Then I should see "You are going to offer foo"
通过使用调试器,我发现信息正确地存储在会话中,但在每个新请求上我都会获得一个新会话.
By using the debugger I found out, that the information is stored in the session correctly, but on every new request I get a fresh session.
至少每个场景都应该有一个工作会议吗?任何想法为什么不是这种情况?
Should'nt there be a working session for at least every scenario? Any ideas why this isn't the case?
提前致谢,乔
版本:在 rails 2.3.10、cucumber 0.10.0、cucumber-rails 0.3.2、capybara 0.4.1.2 上运行
Versions: Running on rails 2.3.10, cucumber 0.10.0, cucumber-rails 0.3.2, capybara 0.4.1.2
推荐答案
由于 capybara 在测试中切换主机名,我们遇到了丢失会话的问题.场景类似于以下内容:
We had the problem with loosing the session due to capybara switching the host name in mid-test. The scenario was something like the following:
# Good
When I visit some page
# will call 'http://capybarawhatever/some_page
And I click the the button
# will call 'http://capybarawhatever/some_new_page'
Then I still have the session
# Failing
When I visit some page
# will call 'http://capybarawhatever/some_page'
And I do something that redirects me to "http://newhost.org/new_page"
And I visit some page
# No this may go to 'http://newhost.org/some_page
Then I have lost my session
这可能值得研究.您可以在会话中获取 current_url
,并且可以使用 host 为 capybara 设置新主机!'newhost.org'
This may be worth investigating. You can get the current_url
in your session, and you may set a new host for capybara using host! 'newhost.org'
这篇关于Rails、Cucumber、Capybara:会话不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!