How to Add Headless Functionality to My Cucumber Testing Stack

  • Install these packages

      $ sudo apt-get install xvfb         ;# a framebuffer, the magic behind headless
      $ sudo apt-get install firefox      
      $ sudo apt-get install ffmpeg       ;# take care of video conversion
    
  • In a CI script, do this:

      #!/bin/bash
      echo "gem 'headless'" >> ./Gemfile
      read -d '' cucumber_append <<EOF
    
      if Capybara.current_driver == :selenium
    
        require 'headless'
        headless = Headless.new(:dimentions => "1366x768x24")
        headless.start
    
        at_exit do
          headless.destroy
        end
    
        Before do
          headless.video.start_capture
        end
    
        After do |scenario|
          if scenario.failed?
            headless.video.stop_and_save(video_path(scenario))
          else
            headless.video.stop_and_discard
          end
        end
    
        def video_path(scenario)
          "#{scenario.name.split.join("_")}.mov"
        end
    
      end
      EOF
      echo "" >> ./features/support/env.rb
      echo "$cucumber_append" >> ./features/support/env.rb
      echo "" >> ./Gemfile
      echo "gem 'capistrano_colors'" >> ./Gemfile
    
      rvm use 1.9.3-p286
      bundle install
      bundle exec rake db:migrate RAILS_ENV=test
    
      #bundle exec cucumber features/userstory/a -r features/
      bundle exec cucumber --color