Skip to content

Commit

Permalink
chrisgladd#17 Added missmatch tolerance and added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vergissberlin committed Mar 11, 2017
1 parent 1cef924 commit f8d5444
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 74 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,37 @@ Type: `String|Array`
The test files to run.

#### options.screenshots
Type: `String`
Type: `String`
Default: `'./screenshots'`

The screenshots directory where test fixtures (comparison screenshots) are stored. Baseline screenshots will be stored here on the first run if they're not present.

#### options.results
Type: `String`
Type: `String`
Default: `'./results'`

The directory to store source, diff, and failure screenshots after tests.

#### options.viewportSize
Type: `Array`
Type: `Array`
Default: `[1280, 800]`

The viewport size to test the site in `[width, height]` format. Useful when testing responsive layouts.
The viewport size to test the site in `[width, height]` format. Useful when testing responsive layouts.

#### options.logLevel
Type: `String`
Type: `String`
Default: `error`

The CasperJS log level. See [CasperJS: Logging](http://casperjs.readthedocs.org/en/latest/logging.html) for details.


#### options.mismatchTolerance
Type: `Float`
Default: 0.05

Mismatch tolerance defaults to 0.05%. Increasing this value will decrease test coverage. See [PhantomCSS](https://github.com/Huddle/PhantomCSS) for details.


### Usage Examples

#### Basic visual tests
Expand Down
132 changes: 66 additions & 66 deletions phantomjs/runner.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
var fs = require('fs');
var system = require('system');

// Parse arguments passed in from the grunt task
var args = JSON.parse(system.args[1]);

var viewportSize = {
"width": args.viewportSize[0],
"height": args.viewportSize[1]
};

// Messages are sent to the parent by appending them to the tempfile
var sendMessage = function() {
fs.write(args.tempFile, JSON.stringify(Array.prototype.slice.call(arguments)) + '\n', 'a');
};

// Initialise CasperJs
phantom.casperPath = args.casperPath;
phantom.injectJs([args.casperPath, 'bin', 'bootstrap.js'].join(fs.separator));

var casper = require('casper').create({
"viewportSize": viewportSize,
"logLevel": args.logLevel,
"verbose": true
});

// Require and initialise PhantomCSS module
var phantomcss = require('phantomcss');

phantomcss.init({
"libraryRoot": args.phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails

"screenshotRoot": args.screenshots,
"failedComparisonsRoot": args.failures,

/**
* Mismatch tolerance defaults to 0.05%. Increasing this value
* will decrease test coverage
*/
"mismatchTolerance": 0.05,

"onFail": function(test) {
sendMessage('onFail', test);
},
"onPass": function(test) {
sendMessage('onPass', test);
},
"onTimeout": function(test) {
sendMessage('onTimeout', test);
},
"onComplete": function(allTests, noOfFails, noOfErrors) {
sendMessage('onComplete', allTests, noOfFails, noOfErrors);
}
});

// Run the test scenarios
args.test.forEach(function(testSuite) {
require(testSuite);
});

// End tests and compare screenshots
casper.then(function() {
phantomcss.compareAll();
}).run(function() {
phantom.exit(0);
});
var fs = require('fs');
var system = require('system');

// Parse arguments passed in from the grunt task
var args = JSON.parse(system.args[1]);

var viewportSize = {
"width": args.viewportSize[0],
"height": args.viewportSize[1]
};

// Messages are sent to the parent by appending them to the tempfile
var sendMessage = function() {
fs.write(args.tempFile, JSON.stringify(Array.prototype.slice.call(arguments)) + '\n', 'a');
};

// Initialise CasperJs
phantom.casperPath = args.casperPath;
phantom.injectJs([args.casperPath, 'bin', 'bootstrap.js'].join(fs.separator));

var casper = require('casper').create({
"viewportSize": viewportSize,
"logLevel": args.logLevel,
"logLevel": args.logLevel,
"verbose": true
});

// Require and initialise PhantomCSS module
var phantomcss = require('phantomcss');

phantomcss.init({
"libraryRoot": args.phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails
"screenshotRoot": args.screenshots,
"failedComparisonsRoot": args.failures,

/**
* Mismatch tolerance defaults to 0.05%. Increasing this value
* will decrease test coverage
*/
"mismatchTolerance": args.mismatchTolerance,

"onFail": function(test) {
sendMessage('onFail', test);
},
"onPass": function(test) {
sendMessage('onPass', test);
},
"onTimeout": function(test) {
sendMessage('onTimeout', test);
},
"onComplete": function(allTests, noOfFails, noOfErrors) {
sendMessage('onComplete', allTests, noOfFails, noOfErrors);
}
});

// Run the test scenarios
args.test.forEach(function(testSuite) {
require(testSuite);
});

// End tests and compare screenshots
casper.then(function() {
phantomcss.compareAll();
}).run(function() {
phantom.exit(0);
});
7 changes: 4 additions & 3 deletions tasks/phantomcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ module.exports = function(grunt) {
var done = this.async();

var options = this.options({
screenshots: 'screenshots',
logLevel: 'error',
mismatchTolerance: 0.05,
results: 'results',
viewportSize: [1280, 800],
logLevel: 'error'
screenshots: 'screenshots',
viewportSize: [1280, 800]
});

// Timeout ID for message checking loop
Expand Down

0 comments on commit f8d5444

Please sign in to comment.