gpt4 book ai didi

firefox - Selenium 错误 : no display specified

转载 作者:行者123 更新时间:2023-11-28 19:45:25 25 4
gpt4 key购买 nike

我已经在 debian 虚拟机中安装了 selenium-server-standalone-2.42.2.jar

并安装了 Firefox 29.0

并尝试使用目录中唯一的文件 phpunit 运行以下脚本:

<?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

这是什么意思?

我已经红色了几个线程,显然我必须尝试执行以下操作:

1)在命令shell中输入这个

export PATH=:0;

结果:我得到了同样的错误。

2) 我已经安装了 vnc4server 并将 debian-vm:1 作为应用程序,然后设置 export PATH=debian-vm:1 使用 realvnc 运行它并在查看器中运行它(有效)我遇到了同样的问题。

最佳答案

您收到此错误,因为您尚未设置 DISPLAY 变量。以下是如何在 headless 机器上执行测试的指南。

您必须安装 Xvfb首先是浏览器:

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

然后启动Xvfb:

Xvfb &

设置DISPLAY并启动Selenium:

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

然后您就可以运行测试了。

关于firefox - Selenium 错误 : no display specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24653127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com