Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

firefox - Selenium Error: no display specified

I've installed selenium-server-standalone-2.42.2.jar in a debian virtual box

and installed Firefox 29.0

and trying to run the following script with phpunit which is the only file in the directory:

<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase{

    public function setUp()
    {
            $this->setHost('localhost');
            $this->setPort(4444);
            $this->setBrowser('firefox');
            $this->setBrowserUrl('http://debian-vm/phpUnitTutorial');
    }

    public function testHasLoginForm()
    {
            $this->url('index.php');

            $username = $this->byName('username');
            $password = $this->byName('password');

            $this->assertEquals('', $username->value());
            $this->assertEquals('', $password->value());
    }
}

I get the following error:

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

What does this mean?

I've red several threads and apparently I had to do the following which I tried:

1)to type this in the command shell

export PATH=:0;

Result: I got the same error.

2) I've installed vnc4server and getting debian-vm:1 as a application I then set export PATH=debian-vm:1 run it with realvnc and in the viewer (which works) I got the same problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You receive this error, because you have not set the DISPLAY variable. Here is a guide how to perform the test on a headless machine.

You have to install Xvfb and a browser first:

apt-get install xvfb
apt-get install firefox-mozilla-build

then start Xvfb:

Xvfb &

set DISPLAY and start Selenium:

export DISPLAY=localhost:0.0
java -jar selenium-server-standalone-2.44.0.jar

and then you will be able to run your tests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...