【问题标题】:Error: cannot open display: :0 for Selenium tests错误:无法打开显示:Selenium 测试:0
【发布时间】:2015-08-19 18:45:11
【问题描述】:

首先我收到以下错误:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified

所以我使用export DISPLAY=:0 来规避这个问题。随后我发现 Selenium 测试正在使用 root 用户运行,一切都很好。

但是现在我可以看到当这些测试从 Jenkins 执行时出现以下错误:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
No protocol specified
Error: cannot open display: :0

我在 Redhat 6 机器上运行它。

【问题讨论】:

  • 你能补充更多信息吗,什么操作系统?它是否在可以访问 X 会话的计算机和帐户上?

标签: selenium jenkins


【解决方案1】:

您可以下载Jenkins xvnc plugin 并使该插件启动(并导出)一个虚拟显示供 selenium 使用。 jenkins 用户可能无权访问 :0 显示。

【讨论】:

    【解决方案2】:

    解决此问题的最佳方法是更改​​ jenkins 启动脚本。

    在 Ubuntu 上对我来说正确的解决方案如下:

    1.打开位于 /etc/init.d/jenkins 的 Jenkins shell 脚本。

    2.在PATH变量前添加如下几行:

    /usr/bin/X :0 vt7 -ac
    export DISPLAY=:0
    xhost +
    

    【讨论】:

    • sudo service jenkins restart 现在给我以下错误:(EE) Fatal server error: (EE) Server is already active for display 0 If this server is no longer running, remove /tmp/.X0-lock and start again. (EE) (EE) Please consult the The X.Org Foundation support at http://wiki.x.org for help. (EE) No protocol specified xhost: unable to open display ":0"
    • 您的 Xorg 配置中可能存在错误。此处详细介绍了解决方案:askubuntu.com/questions/69896/…。但是,我建议您使用 Amey 建议的插件。
    • @sjmach,我的 jenkins 服务器安装在 Windows 机器上。在那种情况下,这相当于什么。我的意思是我需要使用您建议的更改来更新哪个文件。
    • @TDHM:您是在本地使用 Windows 机器还是在云提供商 (VM) 上使用?
    • 对于我们的项目,它在 VM 上,但我也在本地机器上准备了 Jenkins master。第一个更重要。如果您有第二个解决方案,请同时提出建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 2020-07-28
    • 1970-01-01
    相关资源
    最近更新 更多