5

I face with Error: no display specified error when running play framework tests in Jenkins at FreeBSD server. 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:

1) Xvfb plugin installed

2) Play Framework installed

Tests are written using selenide library and selenide module for play framework.

Xvfb configured and enabled in job configuration.

Job console output is:

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]
kyberorg
  • 637
  • 1
  • 8
  • 22

3 Answers3

1

The selenium tasks needs to know the DISPLAY that it shall connect to. You can set it e.g. as an environment variable (don't forget to export it, if you do that in .profile)

export DISPLAY=:10

This is for bash, other shells might need a 2 step process:

DISPLAY=:10
export DISPLAY

You can also specify the variable at the command line before the command:

DISPLAY=:10 java -jar mySelenium.jar
lilalinux
  • 2,903
  • 3
  • 43
  • 53
  • "DISPLAY=:10 java -jar mySelenium.jar" , my question is on this command. Is this for GRID execution? If I need to execute a test on WebDriver on a remote machine via Jenkins, how do it? – Afsal Sep 18 '20 at 09:39
  • @Afsal Maybe this helps? https://stackoverflow.com/questions/44057317/how-do-i-set-environment-variables-for-selenium-java-firefoxdriver – lilalinux Sep 18 '20 at 11:26
  • 1
    So the idea is to set the display variable in Selenium code and use the same display number for Xvfb. Right? I use Chrome. I'll check for a similar capability in Chrome. – Afsal Sep 18 '20 at 11:43
0

You could avoid all these issues by using Selenoid project which starts headless browsers in parallel in Docker containers. Container images are created by considering compatible version of webdriver and browser. They also include fonts, flashplayer and so on. Just choose one of already existing images and run your tests. No need to install Java to run Selenium tests.

vania-pooh
  • 2,933
  • 4
  • 24
  • 42
0

I tend to supply this if I'm running my tests via 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.

Michael Dally
  • 195
  • 3
  • 12