Managing Sessions

Although the session object is already usable enough, it’s not as easy to write multisession (multidriver/multibrowser) code. Yep, you’ve heard right, with Mink you can manipulate multiple browser emulators simultaneously with a single consistent API:

// init sessions
$session1 = new \Behat\Mink\Session($driver1);
$session2 = new \Behat\Mink\Session($driver2);

// start sessions



The state of a session is actually managed by the driver. This means that each session must use a different driver instance.

Isn’t it cool? But Mink makes it even cooler:

$mink = new \Behat\Mink\Mink();
$mink->registerSession('goutte', $goutteSession);
$mink->registerSession('sahi', $sahiSession);

With such configuration, you can talk with your sessions by name through one single container object:



Mink will even lazy-start your sessions when needed (on the first getSession() call). So, the browser will not be started until you really need it!

Or you could even omit the session name in default cases:


This call is possible thanks to $mink->setDefaultSessionName('goutte') setting previously. We’ve set the default session, that would be returned on getSession() call without arguments.


The Behat\Mink\Mink class also provides an easy way to reset or restart your started sessions (and only started ones):

// reset started sessions

// restart started sessions