Running headless firefox Xvfb with Jenkins to run selenium tests Running headless firefox Xvfb with Jenkins to run selenium tests selenium selenium

Running headless firefox Xvfb with Jenkins to run selenium tests


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=:10export 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. 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.


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.