Skip to content

Commit 31da8b2

Browse files
committed
fixes #107 - update status/error/ready handling
1 parent 70c9785 commit 31da8b2

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
@@ -215,7 +215,7 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
215215
);
216216
}
217217

218-
if (is_array($result) && ! array_key_exists('status', $result)) {
218+
if (is_array($result) && ! array_key_exists('status', $result) && ! isset($result['value']['ready']) && ! isset($result['value']['error'])) {
219219
throw WebDriverException::factory(
220220
WebDriverException::CURL_EXEC,
221221
'Payload received from webdriver is valid but unexpected json: ' . substr($rawResult, 0, 1000)
@@ -226,8 +226,25 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
226226
$message = (is_array($value) && array_key_exists('message', $value)) ? $value['message'] : null;
227227

228228
// if not success, throw exception
229-
if ((int) $result['status'] !== 0) {
230-
throw WebDriverException::factory($result['status'], $message);
229+
if (isset($result['status']) && (int) $result['status'] !== 0) {
230+
throw WebDriverException::factory(
231+
$result['status'],
232+
'WebDriver response "status"'
233+
);
234+
}
235+
236+
if (isset($value['error'])) {
237+
throw WebDriverException::factory(
238+
$value['error'],
239+
$message ?: 'WebDriver response "error"'
240+
);
241+
}
242+
243+
if (isset($value['ready']) && $value['ready'] !== true) {
244+
throw WebDriverException::factory(
245+
WebDriverException::CURL_EXEC,
246+
$message ?: 'WebDriver session not "ready"'
247+
);
231248
}
232249

233250
$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', $w3c = false)
46+
public function __construct($url, $w3c)
4747
{
4848
parent::__construct($url, $w3c);
4949

0 commit comments

Comments
 (0)