Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cookie to track session requests and errors when sharing server b… #1639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

twalpole
Copy link
Member

…etween sessions. When using multiple sessions with the same app Capybara, by default, reuses the server. This means when errors are raised in a session, or requests are made from the browser (ajax, etc) we have no way of knowing which session they are associated with, and therefore errors get raised in only the first session. A setting Capybara.reuse_server was recently merged into Capybara, but that has the downside of using another port, more memory usage, etc. This PR adds another method of tracking the session by adding a cookie to the browser and using that to track the session id. Unfortunately with selenium we can't add a cookie to a domain unless the browser is already on a page on that domain (other drivers can, so it may be worth moving this functionality into a method that can be overridden). To get around that I added a query parameter to every call to #visit which is stripped out by the middleware, used to identify the session, and then set as a cookie in the browser with the response so further requests should pass it back. Another thought was to have the browser visit a page in the middleware (like identify) before every #visit to set the cookie. Any thoughts anyone reading this has would be great.

@@ -5,6 +5,16 @@
module Capybara
class Server
class Middleware
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should # @api private be added for Capybara::Server::Middleware (or Capybara::Server)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably - I'm just not convinced I like the whole solution - would much prefer if selenium allowed us to preset a cookie before the first visit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants