firefox - Selenium 错误 : no display specified

标签 firefox testing selenium

我已经在 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/

相关文章:

python - Chrome 的 Selenium 驱动程序在 Python 中抛出 WebDriverException

javascript - alert() 和 console.log() 在 Firefox 26 中不起作用

css - 表单字段概述

java - 如何让Selenium等待页面上的元素被替换(java)

testing - 如何不到处放 "use strict"

java - Travis yml运行Selenium Java Gradle Docker构建

html - 图像已加载但未显示在 Firefox 上的本地主机应用程序中

jquery - 将图像/文本/文件名拖到 Firefox 页面上

c++ - 我应该如何在不同的操作系统上测试独立的应用程序

python-3.x - 使用 chrome canary 执行 selenium python 脚本时如何抑制控制台错误/警告/信息消息