Xvfb plugin for Jenkins

Problem: Error while running Selenium tests via Jenkins on a Ubuntu machine.

WebDriverException(“The browser appears to have exited ”
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


Why this post?

We faced this issue when we were trying to run our Selenium tests using Jenkins on an Ubuntu system. The same tests were working fine when we ran it through the terminal. We figured out that this was probably because Jenkins user did not have access to the appropriate display.

We solved the issue at first by making changes to the Jenkins start script. You can refer to this link for details. Then the client suggested (thanks, Prashanth!) using Xvfb. In rest of the post we will explain in detail how we solved this issue using Xvfb.

1. Xvfb installation:
Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in memory without showing any screen output.
Make sure you have Xvfb installed in your Ubuntu system if not Install xvfb in ubuntu using below code

sudo apt-get install xvfb

2. Install Xvfb Plugin for Jenkins:

Xvfb Plugin for jenkins lets you control Xvfb virtual frame buffer X11 server with each build. It starts Xvfb before the build starts, and stops it with the build.
Xvfb plugin

3. Configure Jenkins:
Start by going to Manage Jenkins / Configure System and setup your Xvfb installation. You need to give it a arbitrary name like default Xvfb and directory in which the Xvfb executable is located. Eg:/usr/bin.

Jenkins Configuration

4. Project Configuration:
On the job configuration page, enable the “Start Xvfb before the build, and shut it down after.” under the Build Environment. In case need you can customize defaults by clicking on Advanced… button.

Project Configuration

5. Re-running the test:
After making the above changes the test ran fine. Note that the plugin starts Xvfb before the build starts, and stops it with the build
Rerun the Jenkins test

Well, that was cool. As always, we are happy to answer any questions you may have.

Note: We think you would be interested in our open-sourced Selenium + Python test automation framework based on the page object pattern.

Subscribe to our weekly Newsletter

View a sample

8 thoughts on “Xvfb plugin for Jenkins

  1. Hi, I am facing the same issue, but unable to resolve the problem on following the steps you mentioned. I added the plugin on the jenkins and installed xvfb on the jenkins machine as well.

    1. I’ll take a shot in the dark. Can you make sure that the path for your xvfb executable is correct in Step 3? To find your xvfb executable, type in ‘which xvfb’ on your command prompt.

      If the path to your xvfb executable is set correctly, can you post the Jenkins console output?

      1. Hi, Could you please elaborate. I am not getting ,in which directory is that xvfb executable. And unable to set directory path while installing xvfb. Thanks in Advance.

      2. If you have installed xvfb in your machine and if you run ‘which xvfb’ on your command prompt, you should see the path where xvfb is installed.

  2. Great article, Put me into the correct path.
    xvnc plugin is not working properly in mac slaves and was struggling a bit..and the find the solution with xvfb

  3. Getting an error while running test on jenkins

    Xlib: extension “RANDR” missing on display “:51”.
    Xlib: extension “RANDR” missing on display “:51”.

Leave a Reply

Your email address will not be published. Required fields are marked *