capybara-envjs icon indicating copy to clipboard operation
capybara-envjs copied to clipboard

Cookies missing?

Open dnd opened this issue 14 years ago • 4 comments

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.

dnd avatar Jul 12 '10 23:07 dnd

Do you have an example of this? envjs does have some cookie support, but as you mention, there may be holes.

smparkes avatar Aug 19 '10 17:08 smparkes

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.

dnd avatar Aug 21 '10 00:08 dnd

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.

smparkes avatar Aug 21 '10 02:08 smparkes

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 ...

smparkes avatar Sep 02 '10 17:09 smparkes