-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 driver for Selenium needs to clean localStorage between tests #1702
Comments
This has been discussed previously and the performance hit for doing this every test when most apps don't depend on localStorage was decided to be not worth it. If you have a need for it adding an after block as you have works fine. This is documented in the Session#reset method - http://www.rubydoc.info/gems/capybara/Capybara/Session#reset%21-instance_method - PRs documenting it in the README would be considered |
This feels like a very bad decision. What developer sees without this reset is tests failing randomly (based on random seed) on CI, but every one of them working just fine when ran individually every time - and none of the standard ways to debug it are going to be helpful. This hacky This is a bug in capybara, there's really no other way to look at it. The only reasonable alternative to cleaning And for that matter, does it really have significant performance impact? It feels unlikely compared with tons of setup being ran for every test. |
@taw The fact that this has come up a couple of times in the last 3 years shows how little it actually affects people. The "hacky"??? after hook is exactly how it would be implemented in Capybara if it ever was, so I'm not really sure what your issue with that is. As stated in the Session#reset documentation - the decision was made not to reset localstorage since Capybara has no way of knowing everything that an app would need to have reset between tests, so the developer has to make that decision. If that doesn't work for you, you are free to use any other free testing framework you feel like. If instead you want to make it clearer to others by submitting a PR for the README about session resets that would be considered. |
Considering how difficult to debug problems like this are, the fact that it showed up multiple times suggest it probably affects a lot of people, but they just shrug it off with "capybara is inherently unreliable" (a very common attitude). |
@taw Thanks for script
|
Just letting ya'll know that I'm running into this right now. |
@liapretorius Yeah, the more people use |
@liapretorius This has been available since Capybara 2.11.0 via the |
This is not done by default as it is said to incur a performance hit, paired with local storage not always being used by the site being tested. (teamcapybara/capybara#1702 (comment)) GitLab uses localStorage, for things like remembering which tab you used last (on the login page for example, between sign-in, ldap, and register) Fixes: https://gitlab.com/gitlab-org/gitlab-qa/issues/303
@twalpole how do you feel about making |
@rbu Not great because it has a few edge cases that will just lead to more confusion - It's probably possible to make it work fully properly with Chrome via direct CDP calls but not with any other browser at the moment. I did some work to make it a bit more robust in #1853 but never really finished that up |
@rbu Thinking about this more - it's probably fine to make it the default since it shouldn't really break anything, is easy enough to disable, and the edge cases still exist anyway. |
I had cross-contamination between tests, which was a real hell to debug.
For workaround I ended up doing this:
But it's really a bug in capybara that it allows this cross-test contamination, and it should clear
localStorage
as well as any other kind of HTML5 browser state between tests.Presumably this kind of code ought to go to
Capybara::Selenium::Driver#reset!
, and to similar places in other drivers supporting such storage mechanisms.The text was updated successfully, but these errors were encountered: