/**
* Send a command to the Selenium RC server (via curl).
*
* @param string $command
* @param array $arguments
* @return string
* @author Seth Casana <*****@*****.**>
*/
protected function doCommand($command, array $arguments = array())
{
$url = sprintf('http://%s:%s/selenium-server/driver/?cmd=%s', $this->host, $this->port, urlencode($command));
$numArguments = count($arguments);
for ($i = 0; $i < $numArguments; $i++) {
$argNum = strval($i + 1);
$url .= sprintf('&%s=%s', $argNum, urlencode(trim($arguments[$i])));
}
if (isset($this->sessionId)) {
$url .= sprintf('&%s=%s', 'sessionId', $this->sessionId);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
$response = curl_exec($curl);
$info = curl_getinfo($curl);
if (!$response) {
throw new RuntimeException(curl_error($curl));
}
curl_close($curl);
if ($info['http_code'] != 200) {
$this->stop();
throw new RuntimeException('The response from the Selenium RC server is invalid: ' . $response);
}
if (!preg_match('/^OK/', $response)) {
throw new PHPUnit_Framework_ExpectationFailedException('Non-Ok response from Selenium RC server was received', PHPUnit_Framework_ComparisonFailure::diffEqual('OK', $response), sprintf("Response from Selenium RC server for %s(%s).\n%s.\n", $command, implode(', ', $arguments), $response));
}
return $response;
}