capybara-envjs
capybara-envjs copied to clipboard
Cookies missing?
I'm trying to access cookies that are set by my application in some js, but envjs does not seem to be aware of them. I checked the cookies on both request and response side in rails and the data is there as it should be. The cookies work fine in the browser, and through selenium, so not sure what the disconnect is with envjs. My site does use subdomains, but I don't know if that makes any difference given that the behavior works as expected in other places.
Do you have an example of this? envjs does have some cookie support, but as you mention, there may be holes.
Not sure how best to show the example I have as it's made up of a lot of small pieces of code in multiple places.
I'm using capybara with cucumber(the scenario is tagged with @javascript), and as mentioned my app makes use of subdomains. So things go kind of like this:
When a request is made through cucumber I set the following: Capybara.default_host = "#{subdomain}.myappdomain.local" Capybara.app_host = "http://#{subdomain}.myappdomain.local" if Capybara.current_driver == :envjs
A user is then logged in, and at this point the Rails code sets a cookie named "current_person" containing the user information.
I then go to a page and perform some action that needs to make use of the cookie such as 'click_link "Add Me"'. This action will then trigger code using the jquery.cookie plugin to execute:
var cookie = $.cookie("current_person");
after this call, 'cookie' is null and the subsequent javascript operation fails because it's expecting that to not be null. As mentioned the exact same code works fine through my own use of the browser, as well as selenium.
It's been a while since this happened, and I had to work around it and move past it so I'm sorry I'm not super sharp on the details. I do need to get it working ultimately, so if there's more information you need let me know and I'll start trying to dig back into it.
I'm fairly certain the problem has something to do with my use of subdomains. One thing that I seem to recall before was a difference in the cookie domain being used. I think it was that the cookie was being written when envjs was in use without the subdomain, so it was just at the root myappdomain.local, and selenium and regular browsing would write the cookie at smithco.myappdomain.local. Either that or I found out that the cookie was being lost. Hopefully this gives you something to go on, let me know what else I can provide.
Okay.
I'll see if I can track it down. It could take me some time to get to it. I'm not that familiar with the cookie code in envjs either. I've touched it on occasion, but minimally.
At this point, I don't think I'm going to be able to look at this without a test that I can easily reproduce it with. Time's really tight. If you can build a test, or want to jump in yourself ...