Skip to content

Commit

Permalink
Merge pull request #348 from aik099/session-unique-id-feat
Browse files Browse the repository at this point in the history
Session driver-independent way to make sessions unique
  • Loading branch information
everzet committed Jun 11, 2013
2 parents 0afca9c + 953c8a8 commit eca086e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Behat/Mink/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Session
private $driver;
private $page;
private $selectorsHandler;
private $uniqueId;

/**
* Initializes session.
Expand All @@ -42,6 +43,7 @@ public function __construct(DriverInterface $driver, SelectorsHandler $selectors
$this->driver = $driver;
$this->page = new DocumentElement($this);
$this->selectorsHandler = $selectorsHandler;
$this->uniqueId = uniqid('mink_session_');
}

/**
Expand Down Expand Up @@ -97,6 +99,17 @@ public function getDriver()
return $this->driver;
}

/**
* Returns session unique id.
*
* @return string
* @access public
*/
public function getUniqueId()
{
return $this->uniqueId;
}

/**
* Returns page element.
*
Expand Down Expand Up @@ -205,7 +218,7 @@ public function getCurrentUrl()
/**
* Capture a screenshot of the current window.
*
* @return string screenshot of MIME type image/* depending
* @return string screenshot of MIME type image/* depending
* on driver (e.g., image/png, image/jpeg)
*/
public function getScreenshot()
Expand Down
21 changes: 21 additions & 0 deletions tests/Behat/Mink/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class SessionTest extends \PHPUnit_Framework_TestCase
{
private $driver;
private $selectorsHandler;

/**
* Session.
*
* @var Session
* @access private
*/
private $session;

protected function setUp()
Expand Down Expand Up @@ -114,4 +121,18 @@ public function testWait()

$this->session->wait(1000, 'function() {}');
}

/**
* Testing that 2 sessions created with same parameters have different IDs.
*
* @return void
* @access public
*/
public function testUniqueId()
{
$session = new Session($this->driver, $this->selectorsHandler);

$this->assertNotEquals($session->getUniqueId(), $this->session->getUniqueId());

}
}

0 comments on commit eca086e

Please sign in to comment.