Starting Xvfb for Selenium




I’ve been trying to migrate our build to 2.0 but seem to have issues with Wvfb: its always exits with code 1 so any rspec test run after that will hang on timeout… :confused:

Here is our current build configuration:

version: 2
      - image: ruby:2.3.3
      - image: redis:3.0.7
      - image: postgres:9.4.10
          POSTGRES_USER: root
      - image: selenium/standalone-chrome
    working_directory: /cyb
      RAILS_ENV: test
      RACK_ENV: test

      - checkout
      - run:
          name: Install System Dependencies
          command: apt-get update -qq && apt-get install -y apt-transport-https build-essential postgresql-contrib software-properties-common memcached unzip xvfb

      - run:
          name: Install Node
          command: |
            curl -sL | bash -
            apt-get install -y nodejs
      - run:
          name: Install Foreman
          command: |
            gem install foreman
      - run:
          name: Bundling and NPM install
          command: |
            bundle install
            npm install
            npm run webpack:build
      - run:
          name: Create & migrate DB
          command: |
            export RAILS_ENV="test"
            export RACK_ENV="test"
            bundle exec rake db:create db:schema:load --trace
            bundle exec rake db:migrate
      - run:
          name: Install latest version of Chrome
          command: |
            wget -q -O - | apt-key add -
            echo "deb [arch=amd64] stable main" >> /etc/apt/sources.list.d/google.list
            apt-get update -qq
            apt-get install -y google-chrome-stable
      - run:
          name: Install latest version of ChromeDriver
          command: |
            mv chromedriver /usr/bin/
      - run:
          name: Running X virtual framebuffer
          command: Xvfb -ac :99 -screen 0 1280x1024x16 +extension RANDR > /dev/null 2>&1
          background: true
      - run:
          name: Run Tests
          command: |
            export DISPLAY=:99
            bundle exec rspec

This configuration works as a Docker/docker-compose environment :confused:

Any idea on what is causing Xvfb to fail or how I can debug this ?

Thanks in advance


I recommend SSHing in to run some commands manually.
Removing > /dev/null 2>&1 from your command will allow you to see STDOUT and STDERR - is it running properly?

An alternative is to use on of our prebuilt images, like circleci/ruby:2.3-node-browsers.


So, it turns out that I was including the selenium image in plus of our installation in the project: removing the image: selenium/standalone-chrome line in the docker section got the Xvfb task running ok.


Thanks for the fast response, sorry, I hadn’t seen it before :confused:


I finally got it to work but it took way to long :confused:

Given that it works “out of the box” in 1.0, not being helped on the 2.0 migration for this kind of “ordinary Rails project” (Rails, Postgres, Redis, Capybara) makes it a very steep price to pay (and I haven’t even try to use parallelism that we use a lot in 1.0, so build is 4 times slower in 2.0 for us right now…).

I would recommend a working example 2.0 configuration with a few comments allowing the migrating user to understand “globally” why all this is necessary:

  • 2.0 is based on docker so everything is virtualized

  • so you have to use xfvb to simulate a screen that will host the browser in your in-browser tests

  • here are the tasks necessary to run before running your tests:

  • install Chrome at least version 56 for --headless option

  • install ChromeDriver version 2.29 (so it’s compatible with latest Chrome)

  • run Xfvb with these option…

  • export an env var to let other software (selenium) know that display is virtualized

  • finally… run your tests !


This is excellent. Please could this be added to the documentation as running Selenium tests is such a common task.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.