In order to set up headless tests on RHEL 6.7, you will need Xvfb, which is a virtual framebuffer that performs the graphical operations without showing anything on the screen. The browser that I chose to use for my headless tests was Firefox. In order to install Xvfb on RHEL use yum:
yum install xorg-x11-server-Xvfb
If this command does not work or is outdated, simply use yum search:
yum search xvfb
Then install the package that the yum search command returns. Once you have Xvfb installed, you can install Firefox by using yum, as well:
yum install firefox
The next thing you need to do is make sure Xvfb and Firefox can, and know how to communicate to each other. There are a couple things that you need to do, the first being to make sure your “/etc/hosts” file is correct. In order for the two to communicate to each other, you need to make sure the following line is the leading line of your “/etc/hosts” file: localhost
It is very important that this is the first entry. For example, if your “/etc/hosts” file has something like this: localhost.localdomain localhost
Your headless tests will NOT work. The next thing you need to do before starting Xvfb is set the display for Firefox, which can be easily done as a system variable:
export DISPLAY=:99
This line will tell Firefox to open up on display :99.
Tip: if you do not want to set this variable every time you login, you can add the command to the end of your “/etc/profile” file.
The next thing we want to do is start the Xvfb server with the SAME DISPLAY NUMBER we chose for Firefox to run on. The easiest way this is done run the command: /path/where/it/is/installed/Xvfb :99'
This will simply start the Xvfb server on the display :99. There are a lot of other flags that can be set, just check the ‘man’ page.
Once the Xvfb server is started, all you have to do is run your Selenium tests and they are now headless!

One thought to “Setting Up Headless Selenium Tests On RHEL 6.7”

  • Pedro Fernández Montesino

    Hi Marco,

    I’m trying to test a maven proyect with Jenkins/Selenium/Chromedriver/Xvfb. I’ve followed your steps without luck.

    I’ve tried with export DISPLAY=:1208 and with export DISPLAY=:99 with the same result.

    This is the console output from Jenkins:

    No changes for since the previous build
    Xvfb starting$ /usr/bin//Xvfb :1208 -fbdir /home/adminam/.jenkins/xvfb-23-1588636031041454648.fbdir
    [Prueba Selenium] $ /bin/sh -xe /apps/apache-tomcat-7.0.73/temp/
    + export DISPLAY=:1208
    + DISPLAY=:1208
    [Prueba Selenium] $ /apps/apache-maven-3.3.9/bin/mvn test
    [INFO] Scanning for projects…
    [INFO] ————————————————————————
    [INFO] Building PruebasRegresionLotChrome 0.0.1-SNAPSHOT
    [INFO] ————————————————————————

    [INFO] ——————————————————-
    [INFO] T E S T S
    [INFO] ——————————————————-
    [INFO] Running
    Starting ChromeDriver 2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351) on port 17692
    Only local connections are allowed.
    [ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.957 s <<< FAILURE! – in
    [ERROR] testRecuperarPnr( Time elapsed: 1.823 s <<< ERROR!
    unknown error: cannot find Chrome binary
    (Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 3.10.0-327.36.3.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 54 milliseconds
    Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
    System info: host: 'EALLDW02', ip: '', 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.36.3.el7.x86_64', java.version: '1.8.0_111'
    Driver info: driver.version: ChromeDriver

    [ERROR] testRecuperarPnr( Time elapsed: 1.824 s << [Help 1]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1]
    Build step ‘Invoke top-level Maven targets’ marked build as failure
    Xvfb stopping
    unlink: No such file or directory
    unlink /home/adminam/.jenkins/xvfb-23-1588636031041454648.fbdir/Xvfb_screen0 failed, Invalid argumentFinished: FAILURE

    Can you help me with this?


Leave a comment

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