Pregunta

I am trying to write code to log in a user, a prerequisite for the scenario. I don't want to actually have the browser visit the login page, fill in fields and submit, that seems like a waste of time for each and every scenario. I figured I would just use the behind-the-scenes code that logs in the user and sets his session variable. Like this...

$fr_user = new User();
$user_id = 0;
$fr_user->loginUser($email,$pwd);
$user_id = $_SESSION['fr_id'];
$user = new User($user_id);

<some checks to make sure the $user_id set properly...>

$this->getSession()->visit($url."?".SID);

If I do a var_dump of the $_SESSION variable inside the step definition, I can see it's working great, the fr_id is getting set.

I even had it send the php session ID over to the web page I am visiting, but when i do a var_dump onto the actual webpage, the session is totally blank, even with the same session id. (there is no code in between that would erase anything)

So, what am I missing? Is there a separate session happening in the behat code and in the selenium browser window? How do I get them to communicate?

Thanks

¿Fue útil?

Solución

I am not positive, but I think you are trying to access the $_SESSION variable data from the client side. That variable is only accessible from the server side code.

The session_id is passed back and forth to the browser, but the actual data is not.

If you want the data to be accessible on the client side, you need to convert the $_SESSION values to raw cookies with the function setcookie() on the server side.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top