Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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服务器无法连接到主机,未指定显示-旧:无法启动新浏览器会话_Php_Selenium_Phpunit_Centos6 - Fatal编程技术网

Php Selenium服务器无法连接到主机,未指定显示-旧:无法启动新浏览器会话

Php Selenium服务器无法连接到主机,未指定显示-旧:无法启动新浏览器会话,php,selenium,phpunit,centos6,Php,Selenium,Phpunit,Centos6,我正在centOs服务器6.5(redhat)上使用Selenium服务器(2.39.0) 使用phpUnit在PHP中开发测试(我也通过pear安装了phpUnit) 但每次我遇到这个错误: Invalid response while accessing the Selenium Server at 'http://localhost:4444/selenium-server/driver/': Failed to start new browser session: org.openqa

我正在centOs服务器6.5(redhat)上使用Selenium服务器(2.39.0) 使用phpUnit在PHP中开发测试(我也通过pear安装了phpUnit)

但每次我遇到这个错误:

Invalid response while accessing the Selenium Server at 'http://localhost:4444/selenium-server/driver/': 
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException:
Error while launching browser
Caused by
RuntimeException: 
Invalid response while accessing the Selenium Server at 'http://localhost:4444/selenium-server/driver/': 
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException:
Error while launching browser
这是我正在尝试执行的测试:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
   function setUp()
  {
    $this->setBrowser("*firefox");
    $this->setBrowserUrl("http://www.google.com/");
  }

  function testMyTestCase()
  {
    $this->open("/");
    $this->type("q", "selenium rc");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
    $this->assertTrue($this->isTextPresent("Results * for selenium rc"));
  }
}
?>
在conf.xml中,我得到了:

<browser name="Firefox" browser="*firefox" host="IPHOST" port="4444" timeout="30000" />
给出:

tcp        0      0 :::4444                     :::*                        LISTEN 
我做错了什么

编辑:

@你的意思是改变剧本吗

无论如何,我不知道我是否走对了方向,但我改变了一些事情: 首先,脚本不同:

<?php
class Example extends PHPUnit_Extensions_Selenium2TestCase
{
  protected function setUp()
  {
    $this->setBrowser('firefox');
    $this->setBrowserUrl('http://www.example.com/');
  }

  public function testTitle()
  {
    $this->url('http://www.example.com/');
    $this->assertEquals('Example WWW page', $this->title());
  }
}
?>
我已经试过了:

Xvfb :99 -ac -screen 0 1280x1024x24 &
以及:

我已经修复了“未指定显示”错误,错误是启动Xvfb时selenium服务器已经在运行, 以下是步骤(在Xvfb和selenium安装之后):

  • 运行Xvfb(Xvfb:99-ac-screen 0 1280x1024x24&)
  • 导出显示(导出显示=:99)
  • 运行selenium(java-jar selenium-server-standalone-versionNumber.jar)
  • 运行脚本(phpunit namefile.php)
如果selenium已经在运行,您可以通过以下方式停止它:

localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
现在脚本工作了

我已经修复了“未指定显示”错误,错误是当我启动Xvfb时selenium服务器已经在运行, 以下是步骤(在Xvfb和selenium安装之后):

  • 运行Xvfb(Xvfb:99-ac-screen 0 1280x1024x24&)
  • 导出显示(导出显示=:99)
  • 运行selenium(java-jar selenium-server-standalone-versionNumber.jar)
  • 运行脚本(phpunit namefile.php)
如果selenium已经在运行,您可以通过以下方式停止它:

localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

现在脚本开始工作了

对于初学者,您可以转到Selenium WebDriver而不是WebDriverBackedSelenium您的服务器上有Firefox吗?它在那里工作吗?@rNix,是的,firefox正在工作。对于初学者,您可以使用Selenium WebDriver而不是WebDriverBackedSelenium。您的服务器上有firefox吗?它在那里工作吗?@rNix,是的,firefox正在工作
Xvfb :99 -ac -screen 0 1280x1024x24 &
export DISPLAY=:99
localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer