Set cookie to track session requests and errors when sharing server b… #1639
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…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.