我在FreeBSD服务器上的Jenkins中运行play框架测试时遇到 Error: no display specified
错误 . 所以每次我都面临超时
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox
詹金斯有:
1)安装Xvfb插件
2)安装了Play Framework
使用硒化物库和硒化物模块为游戏框架编写测试 .
在作业配置中配置并启用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]
2 回答
selenium任务需要知道它应连接的DISPLAY . 你可以设置它,例如作为环境变量(不要忘记导出它,如果你在.profile中这样做)
这是针对bash的,其他shell可能需要两个步骤:
您还可以在命令行之前在命令行中指定变量:
您可以通过使用Selenoid项目来避免所有这些问题,该项目在Docker容器中并行启动无头浏览器 . 通过考虑webdriver和浏览器的兼容版本来创建容器映像 . 它们还包括字体,flashplayer等 . 只需选择一个已存在的images并运行测试 . 无需安装Java即可运行Selenium测试 .