-
Notifications
You must be signed in to change notification settings - Fork 49
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
Better way to set Cookie before visiting a page #122
Comments
In real browser you can't set cookie before visiting the page, because the cookie domain must match to page you set them on for page itself to recognize them. Why you need to set cookie before visiting a page? |
Also documentation http://mink.behat.org/en/latest/guides/session.html says that before you do anything you must visit a page first. |
No matter which approach you decide to implement keep in mind, that new behavior must be implemented in all other Mink drivers as well. |
Setting cookies on other domains will be impossible on Selenium or Sahi. This is why the Mink API does not allow it |
Maybe you can create wrapper page or pass some flag to a page, that when used will set cookie and redirect to correct page. |
@aik099 , i don't think it is a good solution, this makes my tests/implementation depend on ZombieJs driver restrictions. Possible solution would be allow to set domain without visiting a pageand then you can set cookie. |
@eugef it would make your test depend on the Mink API itself |
@eugef , aren't you trying to set session id in that cookie? I know there is an approach to create session and then inject it's ID in cookie so user would be logged-in on website. I recommend you performing login each time instead. |
@aik099, no it is not a session cookie. Cookie is used by JS to hide/show some elements on the page. |
This worked for me:
|
@TerjeBr I'm getting this
|
For now it is impossible to set cookie before visiting the page.
The reason is that
ZombieDriver::setCookie()
usesbrowser.window.location.hostname
which is undefined before you actually visit the page.My workaround was to use the code which allows to specify domain explicitly:
So my questions are
browser.window.location.hostname
before visiting the page?ZombieDriver::setCookie()
so it accepts custom domain?The text was updated successfully, but these errors were encountered: