简体   繁体   English

使用 Jenkins 运行 headless firefox Xvfb 以运行 selenium 测试

[英]Running headless firefox Xvfb with Jenkins to run selenium tests

I face with Error: no display specified error when running play framework tests in Jenkins at FreeBSD server.在 FreeBSD 服务器上运行 Jenkins 中的播放框架测试时,我遇到Error: no display specified错误。 So every time I face with timeout所以每次我遇到超时

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

Jenkins has: Jenkins 有:

1) Xvfb plugin installed 1)安装了Xvfb插件

2) Play Framework installed 2) 安装播放框架

Tests are written using selenide library and selenide module for play framework.测试是使用 selenide 库和用于 play 框架的 selenide 模块编写的。

Xvfb configured and enabled in job configuration. Xvfb 在作业配置中配置并启用。

Job console output is:作业控制台 output 是:

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)

Job configuration:作业配置:

[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]

The selenium tasks needs to know the DISPLAY that it shall connect to. selenium任务需要知道它应连接的DISPLAY。 You can set it eg as an environment variable (don't forget to export it, if you do that in .profile) 您可以将其设置为例如环境变量(如果您在.profile中执行此操作,请不要忘记将其导出)

export DISPLAY=:10

This is for bash, other shells might need a 2 step process: 这是针对bash的,其他shell可能需要两个步骤:

DISPLAY=:10
export DISPLAY

You can also specify the variable at the command line before the command: 您还可以在命令行之前在命令行中指定变量:

DISPLAY=:10 java -jar mySelenium.jar

You could avoid all these issues by using Selenoid project which starts headless browsers in parallel in Docker containers. 您可以通过使用Selenoid项目来避免所有这些问题, 项目在Docker容器中并行启动无头浏览器。 Container images are created by considering compatible version of webdriver and browser. 通过考虑webdriver和浏览器的兼容版本来创建容器映像。 They also include fonts, flashplayer and so on. 它们还包括字体,flashplayer等。 Just choose one of already existing images and run your tests. 只需选择一个已存在的图像并运行测试即可。 No need to install Java to run Selenium tests. 无需安装Java即可运行Selenium测试。

I tend to supply this if I'm running my tests via Jenkins:如果我通过 Jenkins 运行我的测试,我倾向于提供这个:

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

One thing that has tripped me up in the past is that while xvfb-run will create a virtual display, it can really screw up your screenshots and web interactions if it isn't sized correctly, so it's usually advisable to supply a resolution size which will suitably display your browser.过去让我感到困惑的一件事是,虽然 xvfb-run 会创建一个虚拟显示,但如果大小不正确,它确实会搞砸你的屏幕截图和 web 交互,因此通常建议提供一个分辨率大小将适当地显示您的浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM