我一直使用Selenium Server 2.32和Firefox 24.4(在CentOS 5上)运行单元测试 - 刚刚更新了Firefox,并转移到Selenium 2.41,现在Selenium不会打开URL。我假设在我需要适应的Firefox或Selenium中发生了一些变化,但无法弄清楚是什么。
我尽可能地创建了一个干净的测试程序,紧随其后。它的工作原理(在Firefox窗口中打开google.com)使用Selenium 2.32,但不在Selenium 2.41中。从查看Selenium输出中我可以看出它是404错误,但不知道。
感谢任何帮助!
php中的测试用例:
$seleniumUrl = "http://mydomain.com:4444/wd/hub";
$desired_capabilities = array('browserName' => 'firefox');
$results = mycurl(
$seleniumUrl,
'POST',
'/session',
array('desiredCapabilities' => $desired_capabilities),
array(CURLOPT_FOLLOWLOCATION => true));
$seleniumUrl = $results['info']['url'];
$goToUrl = "http://google.com";
mycurl($seleniumUrl, 'POST', '/url', array('url' => $goToUrl));
以下是mycurl函数的来源:
function mycurl(
$seleniumUrl,
$http_method,
$command,
$params = null,
$extra_opts = array()) {
if ($params && is_array($params) && $http_method !== 'POST') {
throw new Exception(sprintf(
'The http method called for %s is %s but it has to be POST' .
' if you want to pass the JSON params %s',
$command,
$http_method,
json_encode($params)));
}
$url = sprintf('%s%s', $seleniumUrl, $command);
if ($params && (is_int($params) || is_string($params))) {
$url .= '/' . $params;
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json;charset=UTF-8',
'Accept: application/json'));
if ($http_method === 'POST') {
curl_setopt($curl, CURLOPT_POST, true);
if ($params && is_array($params)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
}
} else if ($http_method == 'DELETE') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
}
foreach ($extra_opts as $option => $value) {
curl_setopt($curl, $option, $value);
}
$raw_results = trim(curl_exec($curl));
$info = curl_getinfo($curl);
if ($error = curl_error($curl)) {
$msg = sprintf(
'Curl error thrown for http %s to %s',
$http_method,
$url);
if ($params && is_array($params)) {
$msg .= sprintf(' with params: %s', json_encode($params));
}
throw new Exception($msg . "\n\n" . $error);
}
curl_close($curl);
$results = json_decode($raw_results, true);
$value = null;
if (is_array($results) && array_key_exists('value', $results)) {
$value = $results['value'];
}
$message = null;
if (is_array($value) && array_key_exists('message', $value)) {
$message = $value['message'];
}
return array('value' => $value, 'info' => $info);
}