From cb8eb416c046cbc9d089e23e654a133231e5587e Mon Sep 17 00:00:00 2001 From: chibimagic Date: Fri, 11 Oct 2013 14:57:43 -0700 Subject: [PATCH] Support new way of returning session ids in Selenium >= 2.34.0 --- WebDriver/Driver.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index b14fad1..5345b5a 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -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));