Skip to content

Commit 98306de

Browse files
committed
fixes #107 - update status/error/ready handling
1 parent c81f054 commit 98306de

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/WebDriver/AbstractWebDriver.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
142142
);
143143
}
144144

145-
if (is_array($result) && !array_key_exists('status', $result)) {
145+
if (is_array($result) && !array_key_exists('status', $result) && !isset($result['value']['ready']) && ! isset($result['value']['error'])) {
146146
throw WebDriverException::factory(
147147
WebDriverException::CURL_EXEC,
148148
'Payload received from webdriver is valid but unexpected json: ' . substr($rawResult, 0, 1000)
@@ -153,8 +153,25 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
153153
$message = (is_array($value) && array_key_exists('message', $value)) ? $value['message'] : null;
154154

155155
// if not success, throw exception
156-
if ((int) $result['status'] !== 0) {
157-
throw WebDriverException::factory($result['status'], $message);
156+
if (isset($result['status']) && (int) $result['status'] !== 0) {
157+
throw WebDriverException::factory(
158+
$result['status'],
159+
'WebDriver response "status"'
160+
);
161+
}
162+
163+
if (isset($value['error'])) {
164+
throw WebDriverException::factory(
165+
$value['error'],
166+
$message ?: 'WebDriver response "error"'
167+
);
168+
}
169+
170+
if (isset($value['ready']) && $value['ready'] !== true) {
171+
throw WebDriverException::factory(
172+
WebDriverException::CURL_EXEC,
173+
$message ?: 'WebDriver session not "ready"'
174+
);
158175
}
159176

160177
$sessionId = isset($result['sessionId'])

lib/WebDriver/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class Container extends AbstractWebDriver
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function __construct($url = 'http://localhost:4444/wd/hub')
46+
public function __construct($url)
4747
{
4848
parent::__construct($url);
4949

0 commit comments

Comments
 (0)