简体   繁体   English

如何在Capybara 2.4.1中访问cookie和会话

[英]How to access cookies and session in Capybara 2.4.1

I'm using rails 4 with the following gems: 我正在使用带有以下宝石的rails 4:

  • guard-rspec (4.3.1) guard-rspec(4.3.1)
  • rspec (3.0.0) rspec(3.0.0)
  • rspec-core (3.0.3) rspec-core(3.0.3)
  • rspec-expectations (3.0.3) rspec-expectations(3.0.3)
  • rspec-mocks (3.0.3) rspec-mocks(3.0.3)
  • rspec-rails (3.0.2) rspec-rails(3.0.2)
  • rspec-support (3.0.3) rspec-support(3.0.3)
  • capybara (2.4.1) 水豚(2.4.1)
  • capybara-webkit (1.1.0) capybara-webkit(1.1.0)

Capybara works as expected in normal scenarios/examples, but when I want access to a cookie or session, I get a NameError: Capybara在正常场景/示例中按预期工作,但是当我想要访问cookie或会话时,我得到一个NameError:

undefined local variable or method `session'

I have a custom class I'm using that stores cookie data and retrieves it to remember things about the user and then present certain things on the screen. 我有一个我正在使用的自定义类存储cookie数据并检索它以记住用户的事情,然后在屏幕上显示某些内容。

But I can't seem to get the tests to pass and I can't view the cookie or session. 但我似乎无法通过测试,我无法查看cookie或会话。

Does it need to be mocked? 是否需要嘲笑? How can I do this? 我怎样才能做到这一点?

Capybara.current_session.driver.request.session works in 2.17.0. Capybara.current_session.driver.request.session工作在2.17.0。 I'm assuming much hasn't changed though since 2.4. 我假设自2.4以来没有多少变化。

Webkit exposes cookies like this: Webkit公开这样的cookie:

page.driver.browser.manage.all_cookies

Reference here: https://github.com/thoughtbot/capybara-webkit/issues/168 参考这里: https//github.com/thoughtbot/capybara-webkit/issues/168

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM