Igor Afonov

Setting up Jenkins CI to run selenium tests and record video in three easy steps

[2 Sep 2011]
  1. Add headless gem to test environment dependencies in your Gemfile:

     group :cucumber, :test do
       gem 'headless', '~> 0.2.1'

    Headless is a wrapper for Xvfb - X Window virtual frame buffer. Also it supports video capturing from virtual screen using ffmpeg utility.

  2. Put this into features/support folder. I prefer to call this file headless.rb but you can name it yourself:

     if ENV['BUILD_NUMBER'].present?
       require 'headless'
       headless = Headless.new(:display => SERVER_PORT)
       at_exit do
       Before do
       After do |scenario|
         if scenario.failed?
       def video_path(scenario)

    Xvfb instance will be started before execution of all tests. I set display number to a constant to support parallel execution of tests SERVER_PORT is shared only inside one process. If you don’t need parallel execution - you can just set it to predefined number.

    Video recording would start before each scenario and would be saved only if scenario has failed.

    ENV['BUILD_NUMBER'] is one of several environment variables that is set by Jenkins CI when it runs builds. If you’ll need to run test manually in headless environment just supply it in command.

     BUILD_NUMBER=1 bundle exec cucumber features/
  3. Setup Jenkins to archive videos of failed tests:

    Add this before step to remove files of previous tests run (yes I’m lazy:):

    alt text

    Check Archive the artifacts checkbox in Post-build Actions, and set it to archive mov files:

    alt text


    After each build on build’s page you’ll see list of videos of failed scenarios. Most modern browsers support direct video playback of mov format which is used by headless by default.

    alt text

[<< Back]
blog comments powered by Disqus