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



我在 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"));
  }
}
?>

我也在尝试使用以下方法运行脚本:

phpunit --configuration conf.xml example.php

在会议中.xml我得到了:

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

但是我收到同样的错误

门 4444 是免费的:

netstat -anp | grep 4444

给:

tcp        0      0 :::4444                     :::*                        LISTEN 

我做错了什么?

编辑:

@sircapsalot:你的意思是改变剧本吗?

无论如何,我不知道

我是否走向正确的方向,但我改变了一些东西:首先脚本不同:

<?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所以现在我没有出现硒无法启动新浏览器会话的错误,但是我遇到了另一个错误

PHPUnit_Extensions_Selenium2TestCase_WebDriverException: 
Unable to connect to host 127.0.0.1 on port 7055 after 45000ms. 
Firefox console output:
Error: no display specified

我已经尝试过:

Xvfb :99 -ac -screen 0 1280x1024x24 &

和:

export DISPLAY=:99

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

  • 运行 Xvfb ( Xvfb :99 -ac -screen 0 1280x1024x24 & )
  • 导出显示
  • ( 导出显示=:99 )
  • 运行硒 ( java -jar Selenium-server-standalone-versionNumber.jar )
  • 运行脚本 ( phpunit 名称文件.php )

如果硒已经在运行,你可以通过以下方式停止它:

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

现在脚本可以工作了

最新更新