Skip to content

Commit

Permalink
Support new way of returning session ids in Selenium >= 2.34.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chibimagic committed Oct 11, 2013
1 parent c66282b commit cb8eb41
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions WebDriver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ protected function __construct($server_url, $capabilities) {
$payload = array("desiredCapabilities" => $capabilities);
$response = $this->execute("POST", "/session", $payload);

// Parse out session id
// Parse out session id for Selenium <= 2.33.0
$matches = array();
preg_match("/Location:.*\/(.*)/", $response['header'], $matches);
if (count($matches) === 2) {
$this->session_id = trim($matches[1]);
} else {
// The new Chrome driver returns the session id in the body instead
}
if (!$this->session_id) {
// Starting with Selenium 2.34.0, the session id is in the body instead
if (isset($response['body'])) {
$capabilities = json_decode(trim($response['body']), true);
if ($capabilities !== null && isset($capabilities['sessionId'])) {
$this->session_id = $capabilities['sessionId'];
}
}
}
if (!$this->session_id) {
// The Chrome driver returns the session id in the value array
$this->session_id = WebDriver::GetJSONValue($response, "webdriver.remote.sessionid");
}
PHPUnit_Framework_Assert::assertNotNull($this->session_id, "Did not get a session id from $server_url\n" . print_r($response, true));
Expand Down

0 comments on commit cb8eb41

Please sign in to comment.