dqpfl2508589 2014-02-14 16:04
浏览 241
已采纳

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

I'm using Selenium server (2.39.0) on centOs server 6.5 (redhat) developing tests in PHP, using phpUnit (i installed phpunit by pear as well)

but everytime i get this error:

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

this is the test that i'm trying to execute:

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

i'm trying also to run the script using :

phpunit --configuration conf.xml example.php

where in conf.xml i've got:

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

but i receive the same error

and the door 4444 is free:

netstat -anp | grep 4444

gives:

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

what am i doing wrong?

EDIT:

@sircapsalot: do you mean to change the script?

anyway i don't know if i'm going to the right direction but i changed something: first of all the script is different:

<?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());
  }
}
?>

and i installed Xvfb so now i don't have the error that selenium has failed to start new browser session, but i'm having another error

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

and i already tried with:

Xvfb :99 -ac -screen 0 1280x1024x24 &

and:

export DISPLAY=:99
  • 写回答

1条回答 默认 最新

  • duancan2539 2014-02-17 15:36
    关注

    i've fixed the "no display specified" error, the mistake was that selenium server was already running when i was starting Xvfb, so this are the steps (after Xvfb and selenium installation):

    • run Xvfb ( Xvfb :99 -ac -screen 0 1280x1024x24 & )
    • export display ( export DISPLAY=:99 )
    • run selenium ( java -jar selenium-server-standalone-versionNumber.jar )
    • run script ( phpunit namefile.php )

    if selenium is already running you can stop it by:

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

    now the script works

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)