function AbstractWebDriver::curl
Curl request to webdriver server.
Parameters
string $requestMethod HTTP request method, e.g., 'GET', 'POST', or 'DELETE':
string $command If not defined in methods() this function will throw.:
array|integer|string $parameters If an array(), they will be posted as JSON parameters: If a number or string, "/$params" is appended to url
array $extraOptions key=>value pairs of curl options to pass to curl_setopt():
Return value
array array('value' => ..., 'info' => ...)
Throws
\WebDriver\Exception if error
36 calls to AbstractWebDriver::curl()
- AbstractStorage::delete in vendor/
lullabot/ php-webdriver/ lib/ WebDriver/ Storage/ AbstractStorage.php - Delete storage or a specific key
- AbstractStorage::get in vendor/
lullabot/ php-webdriver/ lib/ WebDriver/ Storage/ AbstractStorage.php - Get all keys from storage or a specific key/value pair
- AbstractStorage::set in vendor/
lullabot/ php-webdriver/ lib/ WebDriver/ Storage/ AbstractStorage.php - Set specific key/value pair
- AbstractWebDriver::__call in vendor/
lullabot/ php-webdriver/ lib/ WebDriver/ AbstractWebDriver.php - Magic method that maps calls to class methods to execute WebDriver commands
- Container::element in vendor/
lullabot/ php-webdriver/ lib/ WebDriver/ Container.php - Find element: /session/:sessionId/element (POST) Find child element: /session/:sessionId/element/:id/element (POST) Search for element on page, starting from the document root.
File
-
vendor/
lullabot/ php-webdriver/ lib/ WebDriver/ AbstractWebDriver.php, line 144
Class
- AbstractWebDriver
- Abstract WebDriver\AbstractWebDriver class
Namespace
WebDriverCode
protected function curl($requestMethod, $command, $parameters = null, $extraOptions = array()) {
if ($parameters && is_array($parameters) && $requestMethod !== 'POST') {
throw WebDriverException::factory(WebDriverException::NO_PARAMETERS_EXPECTED, sprintf('The http request method called for %s is %s but it has to be POST if you want to pass the JSON parameters %s', $command, $requestMethod, json_encode($parameters)));
}
$url = sprintf('%s%s', $this->url, $command);
if ($parameters && (is_int($parameters) || is_string($parameters))) {
$url .= '/' . $parameters;
}
$this->assertSerializable($parameters);
list($rawResult, $info) = $this->curlService
->execute($requestMethod, $url, $parameters, array_replace($extraOptions, $this->transientOptions));
$this->transientOptions = array();
$httpCode = $info['http_code'];
if ($httpCode === 0) {
throw WebDriverException::factory(WebDriverException::CURL_EXEC, $info['error']);
}
$result = json_decode($rawResult, true);
if (!empty($rawResult) && $result === null && json_last_error() != JSON_ERROR_NONE) {
// Legacy webdriver 4xx responses are to be considered a plaintext error
if ($httpCode >= 400 && $httpCode <= 499) {
throw WebDriverException::factory(WebDriverException::CURL_EXEC, 'Webdriver http error: ' . $httpCode . ', payload :' . substr($rawResult, 0, 1000));
}
throw WebDriverException::factory(WebDriverException::CURL_EXEC, 'Payload received from webdriver is not valid json: ' . substr($rawResult, 0, 1000));
}
if (is_array($result) && !array_key_exists('status', $result) && !array_key_exists('value', $result)) {
throw WebDriverException::factory(WebDriverException::CURL_EXEC, 'Payload received from webdriver is valid but unexpected json: ' . substr($rawResult, 0, 1000));
}
$value = $this->offsetGet('value', $result);
if (($message = $this->offsetGet('message', $result)) === null) {
$message = $this->offsetGet('message', $value);
}
// if not success, throw exception
if (isset($result['status']) && (int) $result['status'] !== 0) {
throw WebDriverException::factory($result['status'], $message);
}
if (($error = $this->offsetGet('error', $result)) === null) {
$error = $this->offsetGet('error', $value);
}
if (isset($error)) {
throw WebDriverException::factory($error, $message);
}
$sessionId = ($this->offsetGet('sessionId', $result) ?: $this->offsetGet('sessionId', $value)) ?: $this->offsetGet('webdriver.remote.sessionid', $value);
return array(
'value' => $value,
'info' => $info,
'sessionId' => $sessionId,
'sessionUrl' => $sessionId ? $this->url . '/session/' . $sessionId : $info['url'],
);
}