thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 427 forks source link

Session cookie timeout #978

Closed jogaco closed 7 years ago

jogaco commented 7 years ago

Alas! I am trying to write an scenario where a user gets a page, waits for the session to timeout then submits some request, but cannot find how to do it. reset_session! seems to clear all session data but navigates to a blank page so this is not what I need. clear_cookies does not work either. The user can submit info and there is no problem with the session cookie.

Is there support for this?

jferris commented 7 years ago

There currently isn't a way to simulate a timeout.

Internally, we're using setAllCookies with an empty list to clear the cookies. It's possible that the cookies don't take effect until the next request is performed, particularly if the followup request is being made using AJAX rather than a full page load. If you can figure out a way to make clear_cookies take effect immediately, I'd be interested in a pull request.

For what it's worth, it's probably better to test this kind of edge case from some kind of a unit test (request spec, JavaScript unit test, etc) rather than running the entire page using Capybara.

I'm going to close this issue, as there isn't a change we plan on making in capybara-webkit, but if you'd like to discuss further, feel free to comment.