Selenium 错误:未指定显示 [英] Selenium Error: no display specified
问题描述
我已经在 debian 虚拟机中安装了 selenium-server-standalone-2.42.2.jar
I've installed selenium-server-standalone-2.42.2.jar in a debian virtual box
并安装了 Firefox 29.0
and installed Firefox 29.0
并尝试使用目录中唯一的文件 phpunit 运行以下脚本:
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());
}
}
我收到以下错误:
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
这是什么意思?
我已经红色了几个线程,显然我必须执行以下我尝试过的操作:
I've red several threads and apparently I had to do the following which I tried:
1) 在命令 shell 中输入这个
1)to type this in the command shell
export PATH=:0;
结果:我遇到了同样的错误.
Result: I got the same error.
2) 我已经安装了 vnc4server 并将 debian-vm:1 作为应用程序我然后设置 export PATH=debian-vm:1
使用 realvnc 和在查看器中运行它(有效)我遇到了同样的问题.
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.
推荐答案
您收到此错误,因为您尚未设置 DISPLAY
变量.这是如何在无头机器上执行测试的指南.
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.
您必须先安装 Xvfb 和浏览器:
You have to install Xvfb and a browser first:
apt-get install xvfb
apt-get install firefox-mozilla-build
然后启动Xvfb:
Xvfb &
设置DISPLAY
并启动Selenium:
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.
这篇关于Selenium 错误:未指定显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!