selenium - run tests on a virtual display

Selenium tests require browser to run, so usually we run them on the X-server enabled machine. But in some cases, like CI system running on the headless EC2 instance, we want to run it on the virtual display. This can be done using xvfb (X virtual framebuffer).

Set up

Install xvfb

    sudo apt-get install xvfb

Install x11vnc

    sudo apt-get install x11vnc

Run tests on virtual display

Start xvbf (virtual display number 99)

    Xvfb -ac :99

Tell tests to run on virtual display

    export DISPLAY=:99

Or inside the test code (python)

    os.environ['DISPLAY'] = ':99'
    ...
    selenium = webdriver.Firefox(firefox_profile=ffp, firefox_binary=ffb)
    ...

Watch tests running on virtual display

Start x11vnc server on the same display:

    x11vnc -display :99

Use vnc client (for example, gtkvncviewer) to connect to the localhost and watch how tests are running.

Stackoverflow

Xvfb + Firefox

Hudson Ci Server Running Selenium/Webdriver Cucumber In Headless Mode Xvfb

profile for Boris Serebrov on Stack Exchange, a network of free, community-driven Q&A sites