Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用最新的selenium服务器(2.41)无法在Firefox中打开url_Php_Firefox_Selenium - Fatal编程技术网

Php 使用最新的selenium服务器(2.41)无法在Firefox中打开url

Php 使用最新的selenium服务器(2.41)无法在Firefox中打开url,php,firefox,selenium,Php,Firefox,Selenium,我一直在使用Selenium Server 2.32和Firefox 24.4(在CentOS 5上)运行单元测试——刚刚更新了Firefox,并移动到Selenium 2.41,现在Selenium不会打开URL。我假设Firefox或Selenium中发生了一些我需要适应的变化,但不知道发生了什么 我创建了一个尽可能干净的测试程序,如下所示。它使用Selenium 2.32工作(在Firefox窗口中打开google.com),但不使用Selenium 2.41。从Selenium的输出可以

我一直在使用Selenium Server 2.32和Firefox 24.4(在CentOS 5上)运行单元测试——刚刚更新了Firefox,并移动到Selenium 2.41,现在Selenium不会打开URL。我假设Firefox或Selenium中发生了一些我需要适应的变化,但不知道发生了什么

我创建了一个尽可能干净的测试程序,如下所示。它使用Selenium 2.32工作(在Firefox窗口中打开google.com),但不使用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);
  }

除了将变量命名为“seleniumUrl”之外,我在上面的示例中没有看到任何实际的Selenium代码。那么,这是一个PHP问题还是一个Selenium问题?这里包含的所有额外内容都会产生相当多的噪音。您能否将其简化为Hello World风格的示例?我将通过curl向独立的Selenium服务器发送两个命令:/session和/url。后者应该在firefox浏览器中打开url(本例中为google.com)。但是,在最新版本的Selenium server中,浏览器窗口会打开,但不会转到url。Selenium日志显示404错误。我想弄明白的是,为什么这适用于较旧版本的Selenium server(2.32),而不是2.41。我不知道如何进一步降低这一点。curl()代码本身可能与此无关,但问题似乎有可能(如果不太可能的话)存在,因为向Selenium发送命令的代码本身非常简单。听起来您可以通过比较curl方法的Wireshark跟踪与典型Java/Python编码方法中的Selenium事件来找出问题所在。