Create and Compare Webpage Screenshots with Wraith

By  on  
Wraith

Last week I wrote about using PhantomJS to create screenshots of webpages.  I still find it amazing that we can so quickly and easily create screenshots of a web page using a bit of server side JavaScript.  A reader brought to my attention a tool that takes webpage screenshot gathering to a new level:  Wraith.  Wraith, a tool created by BBC News developers, not only captures screenshots of desired pages but will capture screenshots from two domains and compare the two, creating a diff image that overlays the two screenshots so you can ensure integrity between them.

Why is Wraith useful?  If you have a development server and you want to ensure new changes wont negatively effect the design of the production server, you can run wraith to compare the output of each page on each server!  Let's have a look at how to use Wraith!

YAML Configuration

Assuming you've installed Wraith and its dependencies, you'll need to create a YAML file with configuration information for screenshot creation and comparison.  The following is my configuration:

#Headless browser option
browser: "phantomjs"

# Type the name of the directory that shots will be stored in
directory: "screenshots"

# Add only 2 domains, key will act as a label
domains:
  home: "https://davidwalsh.name"
  localhost: "http://localhost:8080"

#Type screen widths below, here are a couple of examples
screen_widths:
  - 320
  - 600
  - 768x1500 # you can also specify the height, as we've done here
  - 1024
  - 1280

#Type page URL paths below, here are a couple of examples
paths:
  home: /
  topics: /topics
  content_template: /content-template

#Amount of fuzz ImageMagick will use
fuzz: "20%"

#Choose how results are displayed, by default alphanumeric. Different screen widths are always grouped.
#alphanumeric - all paths (with, and without, a difference) are shown, sorted by path
#diffs_first - all paths (with, and without, a difference) are shown, sorted by difference size (largest first)
#diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
mode: diffs_first

threshold: 15

Within my configuration above I've directed Wraith to:

  • Compare my production domain and my local development server.
  • Take and compare screenshots at multiple screen sizes
  • Take and compare screenshots of three critical paths

The screenshots are placed in a "screenshots" directory with a matching _diff.png file for each relevant page.  The following is a diff page for which I purposefully mismatched content:

Wraith Diff

The errors in layout are obvious (on purpose), so you would be able to tell with an image like this that a change you made locally may break the desired layout of given pages on production.

Running Wraith

Wraith is installed as a command line utility so you provide the desired action and path to the YAML file:

wraith capture davidwalshblog.yaml

There are many commands other than capture but capture is the most powerful (creates screenshots, diffs, and a gallery).  Explore the commands to see if Wraith can meet your needs.

Wraith is an awesome tool for going beyond automating screenshot creation to compare screenshots and create diffs for analyzation.  Large organizations like BBC News need tools like this to ensure their incredibly popular sites maintain design integrity; now you have access to the same tools for your website!

Recent Features

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

Incredible Demos

  • By
    Element Position Swapping Using MooTools 1.2

    We all know that MooTools 1.2 can do some pretty awesome animations. What if we want to quickly make two element swap positions without a lot of fuss? Now you can by implementing a MooTools swap() method. MooTools 1.2 Implementation MooTools 1.2 Usage To call the swap...

  • By
    Create a Context Menu with Dojo and Dijit

    Context menus, used in the right type of web application, can be invaluable.  They provide shortcut methods to different functionality within the application and, with just a right click, they are readily available.  Dojo's Dijit frameworks provides an easy way to create stylish, flexible context...

Discussion

  1. Andrei

    Hey! Nice article. But how about when a user encounters a bug in your website and wants to report that bug. You want to capture a screenshot with the actual state of the page (e.g a modal is shown or something). Do you have a solution for that?

    Thanks

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!