Reputation: 14726
We use :cookie_store
for our Rails sessions (Rails 5.1.3), see http://api.rubyonrails.org/classes/ActionDispatch/Session/CookieStore.html
Using Capybara::RackTest::Driver
in a test, I can get the current session and cookies using
page.driver.request.session
page.driver.request.cookies
But when I use Capybara::Selenium::Driver
I only have access to the cookies, not the session, e.g.
page.driver.browser.manage.all_cookies
Is there a way to access the session of the browser using Selenium?
Upvotes: 2
Views: 853
Reputation: 49850
You can access the apps session by installing rack middleware in the test environment. One gem that provides this feature is rack_session_access, however you should really ask yourself why you want to access the session in the first place. Feature/System tests (where Capybara is used) are intended to test the app end-to-end and accessing the session directly is usually a bad smell in those types of tests.
Upvotes: 1