Generate User Tutorials with RSpec and Capybara


Capybara is a great test framework for writing integration or acceptance tests. It drives Selenium or Webkit through your website, rendering CSS and Javascript. An ability to take screenshots was added to Capybara in 2012, and this made debugging much easier. Fast forward to 2016, and my website features are growing and improving, with a need to document them for users. Why not recycle my own work, and take a screenshot for a feature tutorial?

Luckily, I have written numerous amounts of Capybara tests, covering most user features – meaning, I could just take screenshots. This will automagically generate me a step-by-step guide for the feature.

A script that does this will take a screenshot on every Capybara action:

This wraps Capybara methods such as click_on or visit and places a save_screenshot after performing given action. Your files will appear timestampted under steps directory or your project.

Usage

Save this monkeypatch under spec/support/capybara_steps.rb.

Currently it only tracks a limited number of capybara actions (e.g. visit, click_on, fill_in).