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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。