Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Visual Regression Testing with PhantomCSS

Jon Bellah
February 24, 2016

Visual Regression Testing with PhantomCSS

Presented at JavaScript Summit 2016, see: https://jonbellah.com/talks/js-summit

Jon Bellah

February 24, 2016
Tweet

More Decks by Jon Bellah

Other Decks in Technology

Transcript

  1. @jonbellah - jonbellah.com/talks/js-summit selenium wraith succss siteeffect huxley dpxdt css

    critic shoov snap and compare cactus hardy applitools specter needle
  2. @jonbellah - jonbellah.com/talks/js-summit A perceptual phenomenon that occurs when changes

    in a visual stimulus is made without the observer noticing Source: Wikipedia
  3. @jonbellah - jonbellah.com/talks/js-summit PhantomJS or SlimerJS - A headless browser.

    CasperJS - Navigation scripting and testing utility. ResembleJS - A library for making image comparisons.
  4. @jonbellah - jonbellah.com/talks/js-summit grunt.loadNpmTasks('@micahgodbolt/grunt-phantomcss'); grunt.initConfig({ phantomcss: { desktop: { options:

    { screenshots: 'baselines/desktop', results: 'results/desktop', viewportSize: [1280, 800] }, src: [ 'test/visual/start.js', 'test/visual/*-test.js' ] } } });
  5. @jonbellah - jonbellah.com/talks/js-summit options: { screenshots: 'baselines/desktop', results: 'results/desktop', viewportSize:

    [1280, 800], mismatchTolerance: 0.05, rootUrl: 'http://localhost:3000/' // Optional }
  6. @jonbellah - jonbellah.com/talks/js-summit phantomcss: { desktop: { options: { screenshots:

    'baselines/desktop', results: 'results/desktop', viewportSize: [1024, 768] } }, mobile: { options: { screenshots: 'baselines/mobile', results: 'results/mobile', viewportSize: [320, 480] } } }
  7. @jonbellah - jonbellah.com/talks/js-summit Faker.prototype.home = function( posts ) { var

    $ = jQuery, post = posts[5]; var title = post.title, author = post.author.name, date = post.date, excerpt = post.excerpt; // Hero var $hero = $('#hero'); $hero.find('.-text .entry-title').html( title ); $hero.find('.-text .author > a').html( author ); $hero.find('.-text .entry-content p').html( excerpt ); }
  8. @jonbellah - jonbellah.com/talks/js-summit var core = require( './core.js' ), Faker

    = require( ‘./faker.js’), posts = core.getData(), faker = new Faker(); casper.thenOpen( core.getSiteURL() ) .thenEvaluate( faker.home, posts ) .then( function() { phantomcss.screenshot( '#hero .-text', 'hero- post' ); });
  9. @jonbellah - jonbellah.com/talks/js-summit /*--- title: Buttons section: Base CSS ---

    Button styles can be applied to any element. Typically you'll want to use either a `<button>` or an `<a>` element: ```example:html <button class="btn">Click</button> <a class="btn" href="/some-page">Some Page</a> ``` */ .btn { background-color: black; color: white; }
  10. @jonbellah - jonbellah.com/talks/js-summit var localURL = grunt.option( 'url' ); grunt.registerTask(

    'test', function() { if ( localURL ) { grunt.log.writeln( 'Local URL: ' + localURL ); grunt.file.write( 'test/visual/.local_url', localURL ); } grunt.task.run(['phantomcss']); });
  11. @jonbellah - jonbellah.com/talks/js-summit var fs = require('fs'), siteURL; try {

    siteURL = fs.read( 'test/visual/.local_url' ); } catch(err) { siteURL = (typeof siteURL === 'undefined') ? 'http://local.wordpress.dev' : siteURL; } casper.thenOpen(siteURL + '/path/to/template');