merlin2011
merlin2011

Reputation: 75545

How do I get cookies from a capybara-webkit session?

I have already looked this question and grepped through the documentation for the word cookie. However, I am working with legacy code that looks like the following.

require 'capybara'
require 'amatch'

Capybara.register_driver :chrome do |app|                             
    Capybara::Selenium::Driver.new(app, :browser => :chrome)          
end                                                                   

session = Capybara::Session.new(:chrome)                              
session.visit("http://facebook.com")                                  

How can I pull the cookies out of the session object?

I am using capybara 2.1.0 and capybara-webkit 1.1.1. Note that I need to use chrome because I need the full JS support that chrome provides for my use case.

The duplicate question contains the solution but the answer is obscured by a lot of content that is not relevant to this question. The duplicate also does not include a reproducible minimum working example.

Upvotes: 2

Views: 2148

Answers (1)

merlin2011
merlin2011

Reputation: 75545

The duplicate question pointed me in the right direction but it was too noisy and I eventually consulted the docs for Selenium::WebDriver::Options and Selenium::WebDriver::Driver

The following is how we get cookies out.

puts session.driver.browser.manage.all_cookies

Upvotes: 5

Related Questions