2

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?

23tux
  • 14,104
  • 15
  • 88
  • 187

1 Answers1

1

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.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • thanks for your answer! I need access to the session to provide a convenient way to check if a user is logged in, that will be used in multiple tests. Of course I could check some interface hints if a user is logged in, but they are not always there, and the only reliable way would be to visit the users profile. – 23tux Apr 12 '18 at 06:01