Headless and Cucumber

The other day I came across an incredibly useful github project by Leonid Shevtsov called Headless. It's an easy to configure plugin that hooks into your cucumber tests and makes a screen recording using Xvfb and ffmpeg. Firefox is opened in a virtual framebuffer and will hereby run headlessly; There is no visible browser. I tried it out today and it seems to work in a very stable way.

Using just a few lines of code, I could record failing tests on a cucumber environment. A simple and lightweight movie is generated and there's just enough detail to be readable.

Underneath is an example inspired from the link above:

require 'headless'
 
headless = Headless.new
headless.start
 
Before do
  headless.video.start_capture
end
 
After do |scenario|
  if scenario.failed?
    headless.video.stop_and_save("/path/to/#{scenario.name.split.join("_")}.mov")
    # Now, you could for instant add the file to an FTP upload buffer ...
  else
    headless.video.stop_and_discard
  end
end

Also, you can take screenshots inside a scenario step definition file, like this:

headless.take_screenshot "/path/to/screenshot.jpg"
This will take a screen capture of the virtual framebuffer.

One minor detail, i couldn't get this to run on OS X (lion). You can easily install Ubuntu, either locally or as a virtual machine to make this run. Instructions on how to do this, you'll find in this post.

Comments

Try to add X11 to your PATH

ENV['PATH'] += ":/usr/X11/bin" if RUBY_PLATFORM.downcase.include?("darwin")

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.