5

Error: no display specified在 FreeBSD 服务器上的 Jenkins 中运行播放框架测试时遇到错误。所以每次我面对超时

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox

詹金斯有:

1) 安装了 Xvfb 插件

2) 安装播放框架

测试是使用 selenide 库和用于 play 框架的 selenide 模块编写的。

Xvfb 在作业配置中配置和启用。

作业控制台输出为:

Checking out Revision 3f485bd2e3dbcfa058fc19f89ab18020e36707d8 (origin/trunk)
...
Xvfb starting$ /usr/local/bin//Xvfb :1 -screen 0  -fbdir /usr/local/jenkins/xvfb-9-786185694297443042.fbdir
...
Command detected: clean
Command detected: deps --sync
Command detected: precompile
Command detected: auto-test
[YalsTests] $ /srv/java/play/play clean
...
~ using java version "1.8.0_72"
[YalsTests] $ /srv/java/play/play auto-test
~ 14 tests to run:
~
~ selenium/front/CorrectInput...         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

    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)

作业配置:

[X] Start Xvfb before the build, and shut it down after.
Xvfb specific display name  1
Xvfb display name offset 0

Invoke Play Framework       
Command set     Play 1.x 
Goals   
    Clean project [clean]
    Custom parameter
         Custom command deps --sync
    Precompile all Java sources and templates [precompile]
    Automatically run all application tests [auto-test]
4

3 回答 3

1

selenium 任务需要知道它应该连接到的 DISPLAY。您可以将其设置为例如环境变量(如果您在 .profile 中执行此操作,请不要忘记导出它)

export DISPLAY=:10

这适用于 bash,其他 shell 可能需要 2 步过程:

DISPLAY=:10
export DISPLAY

您还可以在命令之前的命令行中指定变量:

DISPLAY=:10 java -jar mySelenium.jar
于 2016-06-01T09:01:38.063 回答
0

您可以通过使用Selenoid项目来避免所有这些问题,该项目在Docker容器中并行启动无头浏览器。容器镜像是通过考虑 webdriver 和浏览器的兼容版本来创建的。它们还包括字体、flashplayer 等。只需选择一个已经存在的图像并运行您的测试。无需安装 Java 即可运行 Selenium 测试。

于 2017-05-27T08:40:28.130 回答
0

如果我通过 Jenkins 运行测试,我倾向于提供这个:

xvfb-run --server-args="-screen 0, 1920x1080x16" mvn clean install...

过去让我感到困惑的一件事是,虽然 xvfb-run 会创建一个虚拟显示,但如果大小不正确,它真的会搞砸你的屏幕截图和网络交互,所以通常建议提供一个分辨率大小将适当地显示您的浏览器。

于 2021-10-05T14:41:09.917 回答