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

Capybara.reset_sessions! doesn't clear cookies. #535

Closed
uahmed opened this issue Oct 31, 2011 · 22 comments
Closed

Capybara.reset_sessions! doesn't clear cookies. #535

uahmed opened this issue Oct 31, 2011 · 22 comments

Comments

@uahmed
Copy link

uahmed commented Oct 31, 2011

I am using Capybara with selenium driver, and doing require 'capybara/cucumber' to reset my session after every scenario. I am running tests in FireFox.

If I debug I can trace that after every scenario Capybara calls the Capybara.reset_sessions! in After do hook, which further down calls @browser.manage.delete_all_cookies in selenium/driver.rb. However it doesn't seem to actually clear the cookies and no exception is thrown as well.

Could this be because Capybara doesn't launch FireFox with Administrator privilege? or there is something else wrong, any ideas?

OS: Windows 7 64 bit.
My gem versions

  • capybara (1.1.1)
  • cucumber (1.1.0)
  • selenium-webdriver (2.8.0)
@cldwalker
Copy link

I'm also seeing this issue with the same selenium-webdriver and capybara for firefox 7 on a mac

@uahmed
Copy link
Author

uahmed commented Oct 31, 2011

Yeah forgot to mention, mine is Firefox 7.0.1 as well.

@jnicklas
Copy link
Collaborator

Could you try updating to the latest selenium-webdriver and see if the issue persists?

@uahmed
Copy link
Author

uahmed commented Nov 17, 2011

Yes, problem still persists with selenium-webdriver 2.12.2.

@jnicklas
Copy link
Collaborator

Very odd, I can't replicate this, can you provide a repeatable test case that fails for you, and I will try and see if it breaks for me as well?

@uahmed
Copy link
Author

uahmed commented Nov 18, 2011

I will try to over the weekend. Thanks.

@cldwalker
Copy link

The latest webdriver does delete all cookies. However, I noticed that for webdriver doesn't detect all cookies, which gave me the impression that #delete_all_cookies doesn't work. @uahmed you may want to check that you're not running into the same issue. Seems the issues I have now are more with selenium webdriver + firefox itself

@uahmed
Copy link
Author

uahmed commented Nov 19, 2011

@cldwalker do you mean it works for you with latest release of selenium web driver? The problem as I described was always with selenium + firefox.

@cldwalker
Copy link

Yes, the latest selenium + firefox 7 works in that the driver deletes
all the cookies it knows about. However, what seems to be buggy is
that the selenium web driver isn't returning all the cookies I see.
I'll have to file that bug in selenium, not here.

On Fri, Nov 18, 2011 at 7:12 PM, Usman Ahmed
[email protected]
wrote:

@cldwalker do you mean it works for you with latest release of selenium web driver? The problem as I described was always with selenium + firefox.


Reply to this email directly or view it on GitHub:
#535 (comment)

@uahmed
Copy link
Author

uahmed commented Nov 19, 2011

Okay, Kindly post a link here after you file the bug with selenium. Thanks
I also found this issue http://code.google.com/p/selenium/issues/detail?id=615 not sure if that is different?

@jnicklas
Copy link
Collaborator

jnicklas commented Jan 3, 2012

Since this is a Selenium issue, I will close it here.

@jnicklas jnicklas closed this as completed Jan 3, 2012
@BrandonMathis
Copy link

Why would reset_sessions reset the cookies also? Cookies != Sessions. What if I want to just reset my session but not my cookies to simulate a browser window being closed and then reopen.

You would need to do this to test a cart or login persistance across multiple sessions of the app within the same browser?

@mgogov
Copy link

mgogov commented Jan 30, 2013

I would just like to add that there are other cases where you can't clear all the cookies by directly using Capybara.reset_session!

If you're authenticating against an OAuth provider such as Facebook, Google, Twitter, etc. you need to first visit their respective website and while there you should call Capybara.reset_session! since there are some "invisible" cookies which can only be cleared with Capybara.reset_session! while on the OAuth provider's website (no idea why). It doesn't look like a Capybara issue, not sure if it's a driver issue (tried both with Selenium and Webkit drivers, same result) but I spent a few hours pulling my hair on this. I hope I save you precious hours of your life with this and it'd be great if someone could explain more about why this happens at all.

I found about this here: http://www.glennposton.com/posts/cant_delete_cookies_with_cucumber_capybara_and_selenium

@jarl-dk
Copy link
Contributor

jarl-dk commented Nov 15, 2013

like @mgogov I would also like to add another case that have similar symptoms as this bug (user is not logged out between scenarios). Namely the case where the web app is using HTML5 local storage instead of ordinary cookies to store sessions. In such case there is another bug for that situation: #1001

@espen
Copy link
Contributor

espen commented Jul 26, 2014

reset_session! : "Reset sessions, cleaning out the pool of sessions. This will remove any session information such as cookies."

I on the other hand is looking for a way to clear the session and not the cookies.

@twalpole
Copy link
Member

@espen Adding a request for how to do something to an issue that was closed over 2 years ago is unlikely to get you help. Try posting to the mailing list as indicated in the README

@espen
Copy link
Contributor

espen commented Jul 27, 2014

Was mainly just wanting to clarify what the code does as this issue was the first result on Google. I did however find a solution to my problem using this gem which clears expired cookies include session cookie but keeps other cookies. https://github.com/nruth/show_me_the_cookies

@georgeu2000
Copy link

Ran into this issue, after all this time. As @mgogov mentioned, you must visit the site to access the cookie for that site, before calling reset_session!

For my use case, it looks like:

visit '/'
Capybara.reset_session!

@wrtsprt
Copy link

wrtsprt commented Nov 28, 2016

@georgeu2000's point seems very important and fixed the problem for us. Could that be documented somewhere?

@georgeu2000
Copy link

@wrtsprt @twalpole - I would be happy to update the docs, if that is desired.

@twalpole
Copy link
Member

twalpole commented Nov 29, 2016

@georgeu2000 The behavior is driver dependent - selenium only allowa to clear cookies for the current domain, other drivers allow to just clear all cookies IIRC. Therefore this should not be documented in Capybara.reset_session!. Not sure where would be correct currently though. Maybe just a gotchas section in the README

@franzliedke
Copy link

This is part of the webdriver spec, unfortunately. So this definitely occurs for all drivers using Selenium's W3C bridge.

We might want to consider navigating to Capybara's app_host (unless already there) when calling reset_session!

Here is a similar discussion on the cypress repo: cypress-io/cypress#408

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests